1

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
Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • If I understand the documentation correctly, you will get a new logfile every second (as long as there's something to be logged) because you're including `-ss` in the pattern (the pattern is used to determine the _current_ filename it should log to, not just the filename of the first logfile). – robertklep Oct 04 '22 at 11:57

1 Answers1

1

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.

Mureinik
  • 297,002
  • 52
  • 306
  • 350