Log4cplus DailyRollingFileAppender MaxBackupIndex clarification

时间:2018-03-09 19:16:18

标签: logging configuration log4cplus

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?

1 个答案:

答案 0 :(得分:0)

如果关闭appender,文件可能会翻转。这是历史行为。您还可以尝试TimeBasedRollingFileAppender,其行为更符合大多数人的期望。