mirror of
https://github.com/log4js-node/log4js-node.git
synced 2025-12-08 19:26:01 +00:00
799 B
799 B
Frequently Asked Questions
I want errors to go to a special file, but still want everything written to another file - how do I do that?
You'll need to use the logLevelFilter. Here's an example configuration:
log4js.configure({
appenders: {
everything: { type: 'file', filename: 'all-the-logs.log' },
emergencies: { type: 'file', filename: 'oh-no-not-again.log' },
'just-errors': { type: 'logLevelFilter', appender: 'emergencies', minLevel: 'error' }
},
categories: {
default: { appenders: ['just-errors', 'everything'], level: 'debug' }
}
});
const logger = log4js.getLogger();
logger.debug('This goes to all-the-logs.log');
logger.info('As does this.');
logger.error('This goes to all-the-logs.log and oh-no-not-again.log');