Git Product home page Git Product logo

nlogger's Introduction

nlogger

nlogger is a Node.js logging library that can

  • print messages with module name and current line number so you know from where it was called
  • print messages in color
  • print parameters in message
  • be configured from file

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.

Changes

1.0.0 - Compatibility with latest node.js 0.12.x

0.4.0 - Logging methods parameters changed

0.3.1 - Fixed util dependencies

0.3.0 - Added parameters support to logging methods

0.2.0 - Added configuration file support

0.1.0 - First npm release

License

Commercial license available at http://iostock.com/nlogger

nlogger's People

Contributors

celalo avatar guileen avatar igo avatar rydn avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.