diff --git a/example.js b/example.js index 9662fe0..ffc73d2 100644 --- a/example.js +++ b/example.js @@ -13,13 +13,27 @@ log4js.configure({ ], replaceConsole: true }); -//log4js.addAppender(log4js.fileAppender('cheese.log'), 'cheese', 'console'); + +//to add an appender programmatically, and without clearing other appenders +//loadAppender is only necessary if you haven't already configured an appender of this type +log4js.loadAppender('file'); +log4js.addAppender(log4js.appenders.file('pants.log'), 'pants'); +//a custom logger outside of the log4js/lib/appenders directory can be accessed like so +//log4js.loadAppender('what/you/would/put/in/require'); +//log4js.addAppender(log4js.appenders['what/you/would/put/in/require'](args)); +//or through configure as: +//log4js.configure({ +// appenders: [ { type: 'what/you/would/put/in/require', otherArgs: 'blah' } ] +//}); var logger = log4js.getLogger('cheese'); //only errors and above get logged. +//you can also set this log level in the config object +//via the levels field. logger.setLevel('ERROR'); -//console logging methds have been replaced with log4js ones. +//console logging methods have been replaced with log4js ones. +//so this will get coloured output on console, and appear in cheese.log console.error("AAArgh! Something went wrong", { some: "otherObject", useful_for: "debug purposes" }); //these will not appear (logging level beneath error) @@ -35,5 +49,10 @@ logger.fatal('Cheese was breeding ground for listeria.'); var anotherLogger = log4js.getLogger('another'); anotherLogger.debug("Just checking"); +//one for pants.log +//will also go to console, since that's configured for all categories +var pantsLog = log4js.getLogger('pants'); +pantsLog.debug("Something for pants"); +