1

I am struggling to understand the purpose and meaning of DailyRollingFileAppender MaxBackupIndex property in the Log4cplus configuration file. As explained in the API documentation:

"This property limits how many backup files are kept per single logging period; e.g. how many log.2009-11-07.1, log.2009-11-07.2 etc. files are kept."

So, if I have the following configuration, where DailyRollingFileAppender scheduled as DAILY:

    log4cplus.rootLogger = INFO, logfile
    log4cplus.appender.logfile = log4cplus::DailyRollingFileAppender
    log4cplus.appender.logfile.File = /myLogFile.log
    log4cplus.appender.logfile.Schedule = DAILY
    log4cplus.appender.logfile.MaxBackupIndex = 10
    log4cplus.appender.logfile.Append = true
    log4cplus.appender.logfile.ImmediateFlush = true

I expect that on every new day, a new log file is created with the new date. for example:

log.2018-03-07, log.2018-03-08, log.2018-03-09,

What I can't seem to understand is WHEN do these backup files are created, and what do they contain?

N.avraham
  • 333
  • 2
  • 15

1 Answers1

0

The file can roll over if you close the appender. This is historical behaviour. You can also try TimeBasedRollingFileAppender which has a behaviour more in line with what most people expect.

wilx
  • 17,697
  • 6
  • 59
  • 114
  • I tried using TimeBasedRollingFileAppender with schedule property of "MINUTELY", but there was no creation of new log files every minute, as the DailyRollingFileAppender does. why is that? – N.avraham Mar 11 '18 at 09:26
  • I got it. TimeBasedRollingAppender schedules through it's filenamepattern property. – N.avraham Mar 12 '18 at 16:47