A simple loglevel and label wrapper around process.stdout
Install
$ npm install --save oniyi-logger
Usage
all log functions work similar to console.log() and can take multiple arguments in a printf()-like way.
Note that the debug method is a noop per default. To enable debug
logging, you must use a labled logger,
and list the label in the NODE_DEBUG
environment variable.
NODE_DEBUG
must be a comma,
or space
separated list
var fs = require('fs');
var logger = require('oniyi-logger')();
logger.info('my %s message', 'info');
logger.debug('my debug message');
logger.warn('my warn message');
logger.error('my error message');
process.env.NODE_DEBUG = 'my-label';
var labeledLogger = require('oniyi-logger')('my-label');
labeledLogger.info('my info message');
labeledLogger.debug('my debug message');
labeledLogger.warn('my warn message');
labeledLogger.error('my error message');
var labeledFileLog = require('oniyi-logger')('file', {sink: fs.createWriteStream('file.log, {flags: 'a'}')});
labeledFileLog.info('my info message');
labeledFileLog.debug('my debug message');
labeledFileLog.warn('my warn message');
labeledFileLog.error('my error message');
Use a logger's instance methods enableDebug()
and disableDebug
to enable or disable debugging
on that particular instance.
License
Apache 2.0 © Benjamin Kroeger