Copyright ©2014 Jared Bell
basiclogger is a very basic node.js logger. Instead of writing console.log()
everywhere, you can use this. Has levels so you only see what you want even though you may be logging more. Future plans include being able to pipe to a log file while still outputing to stdout/stderr as configured.
-
debug
(stdout) -
info
(stdout) -
warning
(stderr) -
error
(stderr)
npm install basiclogger
var log = require('basiclogger');
//these are the allowed values for log.setLevel(level)
var levels = ['debug', 'info', 'warning', 'error'];
//run the test without setting the log level to show how the default level is debug
console.log('Log level not set, using default.');
doLogTests();
//cycle through each log level to see how setting the level affects which messages are displayed
levels.forEach(function (level) {
console.log('Log level set to: ' + level);
log.setLevel(level);
doLogTests()
});
//attempt to log each of the levels
function doLogTests() {
log.debug('This a debug log.');
log.info('This an info log.');
log.warning('This a warning log.');
log.error('This an error log.');
}