1.2.2 • Published 7 years ago

kth-console-log v1.2.2

Weekly downloads
3
License
MIT
Repository
-
Last release
7 years ago

NPM

kth-console-log

Simple console logger used for default logging in our npm packages

This module can be use as a default, node-bunyan compatible logger in projects where basic logging that should be overridable should be available.

Requirements of overriding logger

If you use kth-console-log in your module and want to replace it with a custom logger, just make sure that the logger you are providing adheres to the following pseudo interface:

function trace(...args)
function debug(...args)
function info(...args)
function warn(...args)
function error(...args)
function fatal(...args)

Example of usage

In the module that should have an overridable logger add:

const defaultLogger = require('kth-console-log')
var log = defaultLogger

Then export a getter/setter for the logger along with everything else that should be exported from the module:

  return {
    funcToExport: function() { ... },
    get logger() {
      return log
    },
    set logger(logger) {
      log = logger
    }
  }

Then log as usual in the module itself:

log.info('This is some info-level logging')

And in the main application that depends on the module just override the exported logger with your own logging object:

var myModule = require('my-module-with-overridable-logging')
var myLogger = require('my-initialized-logger')
myModule.logger = myLogger
1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago