Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
CoffeeScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
examples
lib
src
test
Cakefile
LICENSE.txt
README.md
package.json

README.md

dLogger

dLogger is a node.js module for simple logging with color and categories option.

Requirements

Install

$ npm install dlogger

Usage

    var info = require('dlogger').use('info', 'green');
    info('hello world');

    var error = require('dlogger').use('error', 'red');
    error('error occured');

    var dbLogger = require('dlogger').use('database', 'yellow');
    dbLogger('saving to [green]database[/green]');

API

require('dlogger').setStream(stream)

Setting the stream to some function ( by default it is console.log ).

  • stream must be a function
    var log = [];
    var stream = function() {
      log.push(Array.prototype.slice.call(arguments));
    }

    var info = require('dlogger').setStream(stream).use('info', 'green');
    info('this will log in the array');

You can set only one stream for your app.

var loggerInstance = require('dlogger').use(name, style)

This creates new logger instance with the specified name and style.

  • name is a string for this instance of the logger ( e.g. fatal, app, database, etc. )
  • style is a string with color and/or text style

  • supported colors are : 'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'

  • supported styles are : 'normal', 'bold', 'underline', 'blink'

Returns an instance

loggerInstance(text, [arguments...])

This logs any argument to console.log ( or any other function specified as stream ).

  • text is string which has support for specifying colors and styles in brackets like the example below.
  • arguments are objects to be logged and sent to the stream.
    var info = require('dlogger').use('info', 'green');

    var object = { a: 1, b: 2, c: 3 }

    info('This [green]is[/green] [yellow]info[/yellow] text with attached object to be logged', object);

loggerInstance(text, [arguments...]).and(callback)

  • callback must be a function

Executes the callback immediately after logging. Useful for saving code.

    var fatal = require('dlogger').use('fatal', 'red');

    if ( error ) fatal('Fatal error occured. Exiting ...').and( function() { process.exit(1) } );

Better with CoffeeScript

    fatal = require('dlogger').use 'fatal', 'red'

    if error then fatal('Fatal error occured. Exiting ...').and -> process.exit 1

Copyright

Copyright (c) 2013 Ivan Drinchev drinchev@gmail.com . See LICENSE.txt for details.

Something went wrong with that request. Please try again.