Price per single Simple License

14-days money back guarantee

nlogger

Logging lib that prints module name and line number

JavaScript · Node Compatible · Server-side

Usage

Use npm or download. Then add to your code:

var logger = require('nlogger').logger(module);

module is object defined automatically by Node.js. If you don’t want automatic module names, replace it with your desired string name.

logger.info(message);
logger.info(message, variable, message, variable...);

Examples

var logger = require('nlogger').logger(module);
logger.info('Info message');
logger.debug('Debug message');
logger.warn('Warning message');
logger.error('Error message');
logger.trace('Trace message');
logger.info('Array = ', [1, 2, 3, 4], ', Object = ', {one: 1, two: 2});

Output samples

2015-02-23 20:39:03.570 INFO  main:5 - Info message
2015-02-23 20:39:03.588 DEBUG main:6 - Debug message
2015-02-23 20:39:03.589 WARN  main:7 - Warning message
2015-02-23 20:39:03.590 ERROR main:8 - Error message
2015-02-23 20:39:03.590 TRACE main:9 - Trace message
2015-02-23 20:39:03.590 INFO  main:10 - Array = [ 1, 2, 3, 4 ], Object = { one: 1, two: 2 }

2015-02-23 20:59:12.496 INFO  my-modules/first:3 - Message from first module from line #3
2015-02-23 20:59:12.514 INFO  my-modules/second:10 - Message from second module from line #10
2015-02-23 20:59:12.515 INFO  fake-module-name:3 - Message from third module from line #3
2015-02-23 20:59:12.516 INFO  <unknown>:3 - Message from fourth module from line #3

Configuration

nlogger can load optional configuration file nlogger.json which looks like:

{
	"color": "auto",
	"level": {
		"*": "debug",
		"my-modules/first": "info"
	}
}
  • color - print message in color? [true, false, “auto”]
  • level.* - default debug level
  • level.yourModuleName - log level for specified module

Possible log levels are trace, debug, info, warn, error.