A minimal logging utility to support verbose and debug modes
Switch branches/tags
Nothing to show
Pull request Compare This branch is 2 commits ahead, 4 commits behind tristanls:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



logly is a small logging framework in the nodejs ecosystem that also allows one to set debug or verbose logging modes. It is useful to replace comments that describe what the code is doing, especially in debug mode.


var logly = require( 'logly' );
logly.name( 'myapp' );
logly.mode( 'debug' );

logly.debug( 'debug log' );
// stdout: myapp[debug]: debug log

logly.verbose( 'verbose log' );
// stdout: myapp[verbose]: verbose log

logly.log( 'standard log' );
// stdout: myapp: standard log

logly.warn( 'warning log' );
// stderr: myapp[warn]: warning log

logly.error( 'error log' );
// stderr: myapp[error]: error log

logly.stdout( 'stdout log' );
// stdout: stdout log
// *above does not include 'myapp'

logly.stderr( 'stderr log' );
// stderr: stderr log
// *above does not include 'myapp'

functions as input

logly also accepts functions as input; this is primarily to conditionally produce a debug output of complex something if in debug mode, for example:

var options = { debug: true, output: "some.file" }
// dump options in debug mode
logly.debug( function() {
  for ( var i = 0; i < options.length; i++ ) {
    logly.debug( '[OPTION] ' + option + ": " + options[ option ] );
// stdout: myapp[debug]: [OPTION] debug: true
// stdout: myapp[debug]: [OPTION] output: some.file



If you want color then you can enable it (by default color is disabled):

logly.options( { color : true } );

You can also use color or colour functions (maintained for backward compatibility):



You can include a date prefix as well:

logly.options( { date : true } );
logly.log( 'with date' );
// stdout: Wed Aug 22 2012 21:22:52 GMT-0500 (CDT) myapp: with date

ISO8601 format is also available:

logly.options( { date : 'iso' } ); // or 'ISO8601', 'iso8601', 'ISO'
logly.log( 'with iso date' );
// stdout: 2012-08-23T02:26:14.841Z myapp: with iso date

options object

You can pass in the above options all together:

logly.options( { colour : true, date : 'iso' } );