You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Plugin for JS logger loglevel which allows enable/disable debug output dynamically and draws inspiration from TJ Hollowaychuk's debug.
Features
Ability to change logging levels of specific modules.
Ability to turn on/off debug output for specific modules in development.
Production logging would be all modules with warn, info, error levels,
Installation
npm install loglevel-debug
bower install loglevel-debug
Usage
This plugin is deigned to be used standalone.
varlog=require('loglevel-debug')('http'),http=require('http'),name='My App';// fake applog('booting %s',name);http.createServer(function(req,res){log(req.method+' '+req.url);res.end('hello\n');}).listen(3000,function(){log.info('listening');});// fake worker of some kindrequire('./worker');
Example worker.js:
varlog=require('loglevel-debug')('worker');setInterval(function(){log('doing some work');},1000);
Use DEBUG environment variable to control debug output.
$ DEBUG=http,worker:* node example/app
[DEBUG] http booting %s
[DEBUG] worker:a doing lots of uninteresting work
[DEBUG] worker:b doing some work
[INFO] http listening
[DEBUG] worker:a doing lots of uninteresting work
[DEBUG] worker:a doing lots of uninteresting work
[DEBUG] worker:b doing some work
[DEBUG] worker:a doing lots of uninteresting work
[DEBUG] worker:a doing lots of uninteresting work
# createsaloggerforModule1.varlog=require('loglevel-debug')('Module1');log('this is a debug message');log.debug('this is a debug message');log.info('this is a info message');log.warn('this is a warring message');log.error('this is a errror message');log.trace('this is a trace message');
you can dynamic change specific logger's logging level.
log.setLevel(log.levels.INFO)
Browser support
This plugin works on browser as well. To enable debug output, you can use its enable public api,