Rahul Bhooteshwar
Rahul Bhooteshwar

Reputation: 1955

Connect multiple log4js appender with express in node

I want to log all activities on my express server on console as well as in log file.

var log = log4js.getLogger(); log.info(), log.error()....etc works fine

Also if I connect it with express like app.use(log4js.connectLogger(log, { level: 'auto' })); works as well..

I am having another log appender i.e. of type file in config file & I know how to load appenders from config file.

But I am unable to use both file & console appenders simultaneously with express.

Upvotes: 3

Views: 2484

Answers (1)

Arunas Stonis
Arunas Stonis

Reputation: 179

You just need to configure two appenders like this:

log4js.configure({
  appenders: {
    consoleAppender: { type: 'console' },
    fileAppender: { type: 'file', filename: 'logs.log' },
  },
  categories: {
    default: { appenders: ['consoleAppender', 'fileAppender'], level: 'debug' },
  },
});

You can find details description of all configuration options at official site: Log4js - Appenders

Upvotes: 3

Related Questions