Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,51 @@ Instead of the log level constants, you may also supply a string:

log.error('oh no, failed to send mail to %s.', user.email);

Turn colors on:

log.colorful();

Turn colors off:

log.colorful(false);

Setting up our own colors :

log.colorful({
'EMERGENCY' : "\033[0;31m",
'ALERT' : "\033[0;33m",
'CRITICAL' : "\033[0;31m",
'ERROR' : "\033[1;31m",
'WARNING' : "\033[0;33m",
'NOTICE' : "\033[0;36m",
'INFO' : "\033[0;35m",
'DEBUG' : "\033[0m"
});

You don't have to specify all levels, when defining colors, if you only want to specify certain levels, you just write those:

log.colorful({
'INFO' : "\033[0;35m",
'DEBUG' : "\033[0m"
})

Setting up your own log levels:

log.customLevels([ 'COMMAND', 'DATA' ] );

Which will simple add methods `command` and `data` to the `Log` object, and you can use them as the way that default log methods be used, like `log.command( "a command message")`.

Also, you can setting up your own log levels and their colors at the same time:

log.customLevels({
COMMAND: '\033[0;31m',
DATA: '\033[0;31m'
});





## Reader

To stream a log, simply pass a readable stream instead of a writable:
Expand Down
66 changes: 66 additions & 0 deletions examples/stdout-color.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

/**
* Module dependencies.
*/

var Log = require('../lib/log')
, log = new Log('trace').colorful();

/**
* Default log.
*/
log.trace( 'Below is default logs.');
log.debug('a debug message');
log.info('a info message');
log.notice('a notice message');
log.warning('a warning message');
log.error('a error message');
log.critical('a critical message');
log.alert('a alert message');
log.emergency('a emergency %s', 'message');

/**
* Setup our own colors
*/
log.colorful({
ERROR : "\033[0;37m",
CRITICAL : "\033[1;36m"
});

log.trace( 'Below is color-customed logs.');
log.debug('a debug message');
log.info('a info message');
log.notice('a notice message');
log.warning('a warning message');
log.error('a error message');
log.critical('a critical message');
log.alert('a alert message');
log.emergency('a emergency %s', 'message');

/**
* Turn off color.
*/
log.colorful( false );
log.trace( 'Below is color-offed logs.');
log.debug('a debug message');
log.info('a info message');
log.notice('a notice message');
log.warning('a warning message');
log.error('a error message');
log.critical('a critical message');
log.alert('a alert message');
log.emergency('a emergency %s', 'message');

/**
* Customize levels and colors
*/
log.customLevels({
COMMAND: "\x1b[0;35m",
DATA: "\x1b[0;33m",
RESULT: "\x1b[0;36m"
}).colorful( true).setLevel( 'result' );

log.command( 'a command message' );
log.data( 'a data message' );
log.result( 'a result message' );

Loading