Skip to content

`logFormat`s are now customizable for every log level

Compare
Choose a tag to compare
@SirR4T SirR4T released this 20 May 04:11
· 55 commits to master since this release

You can now call log.setLogFormat() on specific levels.

For example,

/* Set the same format for all levels, when level is not specified */
log.setLogFormat('<%= ts %> [<%= uptime %>] ');
log.log('hello');
// prints -->
// info 2016-05-20 09:39:48 [0] hello

/* Set a different format, for a specific level */
log.setLogFormat('error', 'in <%= __FUNC__ %> at <%= __FILE__ %>:<%= __LINE__ %> ');
log.error(new Error('world'));
// prints -->
// ERR! in (anon) at /Users/sarat/Work/Paytm/lgr/test.js:23 Error: world

/* BEWARE: Calling setLogFormat without a level again overwrites the format for all levels again */
log.setLogFormat('<%= ts %> [<%= uptime %>] ');
log.log('hello world!');
log.error('hello world!');
// prints -->
// info 2016-05-20 09:39:48 [0] hello world!
// ERR! 2016-05-20 09:39:48 [0] hello world!