2

Hello I have following log4js configuration:

const defaultPath = './logs/notif.log'
const defaultFormat = '"%d{yyyyMMddhhmmssSSS}","%p","%x{user}","%m"'

module.exports = (level = 'debug', path = defaultPath, format = defaultFormat, compress = true) => {
  const log4js = require('log4js')
  const user = require('os').userInfo().username

  const layout = {
    type: 'pattern',
    pattern: format,
    tokens: {
      user: user,
    },
  }

  log4js.configure({
    appenders: {
      stdout: {
        type: 'stdout',
        layout: layout,
      },
      file: {
        type: 'dateFile',
        filename: path,
        pattern: '.yyyyMMdd',
        compress: compress,
        layout: layout,
      },
      logFilter: {
        type: 'logLevelFilter',
        appender: 'file',
        level: 'info',
      },
    },
    categories: {
      default: {
        appenders: ['stdout', 'logFilter'],
        level: level,
      },
    },
  })
  return log4js.getLogger()
}

My problem is that when I restart the program it will delete the content from the DateFile and start "freshly" over.

Is it possible with the current setup, when the app restarts, to append to the DateFile until its rolled over?

It's really hard to google because 90% matches are for log4j and not for log4js. Kudo's to the name giver!

The Fool
  • 16,715
  • 5
  • 52
  • 86

0 Answers0