mirror of
https://github.com/log4js-node/log4js-node.git
synced 2025-12-08 19:26:01 +00:00
40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
var log4js = require('./lib/log4js');
|
|
//log the cheese logger messages to a file, and the console ones as well.
|
|
log4js.configure({
|
|
appenders: [
|
|
{
|
|
type: "file",
|
|
filename: "cheese.log",
|
|
category: [ 'cheese','console' ]
|
|
},
|
|
{
|
|
type: "console"
|
|
}
|
|
],
|
|
replaceConsole: true
|
|
});
|
|
//log4js.addAppender(log4js.fileAppender('cheese.log'), 'cheese', 'console');
|
|
|
|
var logger = log4js.getLogger('cheese');
|
|
//only errors and above get logged.
|
|
logger.setLevel('ERROR');
|
|
|
|
//console logging methds have been replaced with log4js ones.
|
|
console.error("AAArgh! Something went wrong", { some: "otherObject", useful_for: "debug purposes" });
|
|
|
|
//these will not appear (logging level beneath error)
|
|
logger.trace('Entering cheese testing');
|
|
logger.debug('Got cheese.');
|
|
logger.info('Cheese is Gouda.');
|
|
logger.warn('Cheese is quite smelly.');
|
|
//these end up on the console and in cheese.log
|
|
logger.error('Cheese %s is too ripe!', "gouda");
|
|
logger.fatal('Cheese was breeding ground for listeria.');
|
|
|
|
//these don't end up in cheese.log, but will appear on the console
|
|
var anotherLogger = log4js.getLogger('another');
|
|
anotherLogger.debug("Just checking");
|
|
|
|
|
|
|