added fromreadme.js example, updated README
This commit is contained in:
parent
68b47dd51c
commit
1aed671137
@ -35,12 +35,13 @@ By default, log4js outputs to stdout with the coloured layout (thanks to [masylu
|
|||||||
|
|
||||||
[2010-01-17 11:43:37.987] [DEBUG] [default] - Some debug messages
|
[2010-01-17 11:43:37.987] [DEBUG] [default] - Some debug messages
|
||||||
|
|
||||||
See example.js:
|
See example.js for a full example, but here's a snippet (also in fromreadme.js):
|
||||||
|
|
||||||
var log4js = require('log4js');
|
var log4js = require('log4js');
|
||||||
log4js.loadAppender('console');
|
//console log is loaded by default, so you won't normally need to do this
|
||||||
|
//log4js.loadAppender('console');
|
||||||
log4js.loadAppender('file');
|
log4js.loadAppender('file');
|
||||||
log4js.addAppender(log4js.appenders.console());
|
//log4js.addAppender(log4js.appenders.console());
|
||||||
log4js.addAppender(log4js.appenders.file('logs/cheese.log'), 'cheese');
|
log4js.addAppender(log4js.appenders.file('logs/cheese.log'), 'cheese');
|
||||||
|
|
||||||
var logger = log4js.getLogger('cheese');
|
var logger = log4js.getLogger('cheese');
|
||||||
|
15
fromreadme.js
Normal file
15
fromreadme.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
var log4js = require('./lib/log4js');
|
||||||
|
//log4js.loadAppender('console');
|
||||||
|
log4js.loadAppender('file');
|
||||||
|
//log4js.addAppender(log4js.appenders.console());
|
||||||
|
log4js.addAppender(log4js.appenders.file('cheese.log'), 'cheese');
|
||||||
|
|
||||||
|
var logger = log4js.getLogger('cheese');
|
||||||
|
logger.setLevel('ERROR');
|
||||||
|
|
||||||
|
logger.trace('Entering cheese testing');
|
||||||
|
logger.debug('Got cheese.');
|
||||||
|
logger.info('Cheese is Gouda.');
|
||||||
|
logger.warn('Cheese is quite smelly.');
|
||||||
|
logger.error('Cheese is too ripe!');
|
||||||
|
logger.fatal('Cheese was breeding ground for listeria.');
|
Loading…
Reference in New Issue
Block a user