From 1aed671137e738b44052a5743474eaac671d3587 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Fri, 29 Jun 2012 09:37:41 +1000 Subject: [PATCH] added fromreadme.js example, updated README --- README.md | 7 ++++--- fromreadme.js | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 fromreadme.js diff --git a/README.md b/README.md index c3c98df..2acab54 100644 --- a/README.md +++ b/README.md @@ -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 -See example.js: +See example.js for a full example, but here's a snippet (also in fromreadme.js): 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.addAppender(log4js.appenders.console()); + //log4js.addAppender(log4js.appenders.console()); log4js.addAppender(log4js.appenders.file('logs/cheese.log'), 'cheese'); var logger = log4js.getLogger('cheese'); diff --git a/fromreadme.js b/fromreadme.js new file mode 100644 index 0000000..90ab1d6 --- /dev/null +++ b/fromreadme.js @@ -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.');