Why do I receive 2 log files in log4js?

173 Views Asked by At

I have the following configuration of my logger in a Node.js script:

const log4js = require('log4js');
 log4js.configure({
      appenders: {
        out: {
          type: "dateFile",
          filename: conf.logsFolder+"etl-processing.log",
          pattern: "yyyy-MM-dd-hh-mm-ss",
          alwaysIncludePattern:true,
          keepFileExt:true
        }
      },
      categories: {
         default: { appenders: ['out'], level: 'debug' }
      }
    });
    const logger = log4js.getLogger();
    logger.info ("yada yada yada...")
    logger.error ("yada yada yada...")

Why does log4js produce two log files: one empty and one with all logs? Am I missing something?
The result is always sth like this (2 files separated in time with 1 sec):

  1. etl-processing.2022-10-04-13-40-29.log
  2. etl-processing.2022-10-04-13-40-30.log
1

There are 1 best solutions below

1
Mureinik On BEST ANSWER

The pattern argument refers to the date pattern added to the file name. With the configuration you provided, it will roll over every second. You could change the pattern to something a bit more lax, or even omit it entirely and let it default to yyyy-MM-dd.