added fromreadme.js example, updated README

This commit is contained in:
Gareth Jones 2012-06-29 09:37:41 +10:00
parent 68b47dd51c
commit 1aed671137
2 changed files with 19 additions and 3 deletions

View File

@ -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
View 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.');