Logback, set max history files per day
Asked Answered
C

1

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?

Chute answered 28/10, 2011 at 20:56 Comment(1)
Did you find the solution for this ? @ChuteClo
S
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.

See answered 1/11, 2011 at 8:3 Comment(6)
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?Chute
I am using logback.xml for configuration (unline groovy that Prasanna seems to be using). I have <maxHistory> set to 2 but I have more than 2 files, older ones are not being removed. <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>mylog-minute%d{mm}.%i.log.zip</fileNamePattern> <maxHistory>2</maxHistory> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <maxFileSize>1kB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy>Godewyn
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.Godewyn
Any plans or JIRA to add a maxIndex option to SizeAndTimeBasedFNATP?Feat
@See Hi,if I have this scene,in order to keep 7 days log, how do i define the maxHistory attribute. <fileNamePattern>${REQUEST_LOG_DIR}/request_archives/%d{yyyy-MM-dd,aux}/ip_${server.ip}/port_${server.port}/request_%d{yyyy-MM-dd_HH-mm}.log</fileNamePattern> details infer to https://mcmap.net/q/1315957/-maxhistory-of-multiple-d-specifiers-in-logback-timebasedrollingpolicy. Thank you very much!Impatience
maxHistory tag is applicable for log4j2 in addition to slf4j ?Winkler

© 2022 - 2024 — McMap. All rights reserved.