abstract-logging

2.0.1 • Public • Published

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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.0.1
    1,733,516
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 2.0.1
    1,733,516
  • 2.0.0
    8,036
  • 1.0.0
    9,688

Package Sidebar

Install

npm i abstract-logging

Weekly Downloads

1,751,240

Version

2.0.1

License

MIT

Unpacked Size

2.3 kB

Total Files

4

Last publish

Collaborators

  • jsumners