What is abstract-logging?
The abstract-logging npm package provides a minimalistic logging interface that is compatible with the log method signature of the pino logger. It is primarily used as a placeholder logger in modules that expect a logger to be passed to them, allowing developers to use a no-op (no operation) logger when they don't want to perform any logging. This can be useful for testing or for disabling logging in production for performance reasons.
What are abstract-logging's main functionalities?
No-op logger
The abstract-logging package provides a no-op logger with methods that can be called like a normal logger but do not perform any operations. This is useful for disabling logging or for providing a logger to modules that require one without actually logging any messages.
{"logger": {"info": function() {}, "error": function() {}, "debug": function() {}, "fatal": function() {}, "warn": function() {}, "trace": function() {}, "child": function() { return this; }}}
Other packages similar to abstract-logging
noop-logger
The noop-logger package provides a similar functionality to abstract-logging by offering a logger with no-op methods. It can be used to silently ignore all logging operations.
bunyan-blackhole
Bunyan-blackhole is another package that provides a no-op logger, specifically designed to work with the Bunyan logging library. It is similar to abstract-logging but tailored for Bunyan's API.
pino-noir
Pino-noir is not a no-op logger but offers a feature to redact certain log fields. It is related to abstract-logging in the sense that it can be used to control the output of logs, although it serves a different purpose by focusing on privacy and security rather than completely disabling logging.
abstract-logging
This module provides an interface for modules to include so that they can
support logging via an external logger that conforms to the standard Log4j
interface. One such logger is Pino. This module
is intended for modules that are meant to be used by other modules.
Example:
'use strict'
function AwesomeLibrary (options) {
this.log = (options.logger) ? options.logger : require('abstract-logging')
}
AwesomeLibrary.prototype.coolMethod = function () {
this.log.trace('AwesomeLibrary.coolMethod was invoked')
return {}
}
module.exports = AwesomeLibrary
Interface
Available methods:
fatal
error
warn
info
debug
trace
All methods are no operation functions.
Some loggers, like Pino, implement a child()
method. This method can be easily added to an abstract-logging
instance when stubbing out such loggers:
const logger = require('abstract-logging')
logger.child = () => logger
License
MIT License