9

I use TimeBasedRollingPolicy and SizeAndTimeBasedFNATP triggering policy for my logback configuration. The rollover of log files is set to happen every day and it will also be triggered if log file size goes beyond a limit.

If I do setMaxHistory(10) on TimeBasedRollingPolicy with a daily roll over, then it will archive all log files in last 10 days. But what I want is to set maxHIstory on SizeAndTimeBasedFNATP each day.

Is this possible with logback?

lospejos
  • 1,976
  • 3
  • 19
  • 35
Prasanna
  • 3,703
  • 9
  • 46
  • 74

1 Answers1

11

With SizeAndTimeBasedFNATP and MaxHistory set to 10, the logs older than 10 days will be removed (assuming daily rollover schedule). Size is not factored in the into removal logic.

Ceki
  • 26,753
  • 7
  • 62
  • 71
  • Hey, I know you are the starter of lo4j/slf4j/logback projects and I guess there is no one better to answer these questions. Can I restrict number of history files created per day using TimeBasedRollingPolicy if size is not factored into removal logic? – Prasanna Nov 01 '11 at 15:47
  • I am using logback.xml for configuration (unline groovy that Prasanna seems to be using). I have set to 2 but I have more than 2 files, older ones are not being removed. mylog-minute%d{mm}.%i.log.zip 2 1kB – Ustaman Sangat Mar 06 '12 at 03:18
  • I notice that files do get deleted but sometimes some **much older** files are not deleted - I ended up with for instance the following log files - mylog-2012Mar05-minute30.4.log.zip, mylog-2012Mar05-minute39.0.log.zip, mylog-2012Mar05-minute39.1.log.zip and mylog-2012Mar05.log. As you can see minute30 is still there though minute31, minute32 etc. were deleted. – Ustaman Sangat Mar 06 '12 at 03:45
  • 2
    Any plans or JIRA to add a maxIndex option to SizeAndTimeBasedFNATP? – DarVar Aug 12 '14 at 21:16
  • @Ceki Hi,if I have this scene,in order to keep 7 days log, how do i define the `maxHistory` attribute. `${REQUEST_LOG_DIR}/request_archives/%d{yyyy-MM-dd,aux}/ip_${server.ip}/port_${server.port}/request_%d{yyyy-MM-dd_HH-mm}.log` details infer to [http://stackoverflow.com/questions/40098598/maxhistory-of-multiple-d-specifiers-in-logback-timebasedrollingpolicy](http://stackoverflow.com/questions/40098598/maxhistory-of-multiple-d-specifiers-in-logback-timebasedrollingpolicy). Thank you very much! – Edward Oct 18 '16 at 08:49
  • maxHistory tag is applicable for log4j2 in addition to slf4j ? – Aditya Sep 24 '21 at 04:28