3

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.

Rahul Bhooteshwar
  • 1,675
  • 17
  • 31

1 Answers1

3

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

Thomas.Donnelly
  • 481
  • 4
  • 12
Arunas Stonis
  • 169
  • 1
  • 6