A logger for node inspired by log4j and commons-logging.
MadEye Logger is a lightweight logger that combines some of the best properties of log4j and node. It's equally usable in Node, (most) browsers, and Meteor (client and server).
npm install pince.
In any file you wish to make a logger, require it via
Logger = require('pince');
To install, just
mrt add pince. The global
Logger symbol will be there
waiting for you.
Set the log level:
//Default is infoLoggersetLevel'trace';
Make a new logger:
log = 'router';log.info"Routing.";//2013-10-31 11:29:36.097 info: [router] Routing.logtrace"Setting up routes...";//2013-10-31 11:29:36.101 trace: [router] Setting up routes...
Set individual levels:
LoggersetLevel'info';LoggersetLevel'controller' 'trace';routerLog = 'router';controllerLog = 'controller';routerLogtrace"Can't hear me!";//NothingcontrollerLogtrace"Can hear me."://2013-10-31 11:31:21.906 trace: [controller] Can hear me.LoggersetLevelsrouter:'debug' controller:'warn';routerLog.info"Finally! Someone is listening to me.";//2013-10-31 11:32:48.374 info: [router] Finally! Someone is listening to me.controllerLog.info"Hello? Hello??";//Nothing
Hierarchically name and set levels:
routerLog = 'myPackage:router';controllerLog = 'myPackage:controller';LoggersetLevel'myPackage' 'info';LoggersetLevel'myPackage:controller' 'debug';routerLog.info'You can see this.';routerLogdebug'You cannot see this; myPackage level is set to info.';controllerLogdebug'You can see this, myPackage:controller level is set to debug.';