log4js-node/docs/faq.md
2017-04-18 08:07:02 +10:00

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');