Logback: SizeAndTimeBasedRollingPolicy does not comply with totalSizeCap

I try to manage my logging so that my old archived log files are deleted after they either have reached the general cumulative size limit, or have reached the maximum limit in history. When using SizeAndTimeBasedRollingPolicy in Logback 1.1.7, the sliding file application will continue to create new archives despite exceeding the set of totalSizeCap .

Here is my logback.xml file for reference:

 <?xml version="1.0" encoding="UTF-8"?> <configuration> <appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${USERPROFILE}/testlogs/test.log</file> <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> <fileNamePattern> ${USERPROFILE}/testlogs/%d{yyyy-MM-dd_HH}/test%i.log.zip </fileNamePattern> <maxHistory>7</maxHistory> <maxFileSize>50KB</maxFileSize> <totalSizeCap>200KB</totalSizeCap> </rollingPolicy> <encoder> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %5p - %m%n</pattern> </encoder> </appender> <root level="INFO"> <appender-ref ref="file" /> </root> </configuration> 

Is this a bug in logback, or am I not setting up a sliding file app correctly?

+8
java logging logback
source share
2 answers

This is a bug in Logback 1.1.7. See: http://jira.qos.ch/browse/LOGBACK-1166

I checked totalSizeCap works in Logback 1.1.8-SNAPSHOT.

+10
source share

Well, they even answered the question, I wanted to publish the work that we created until the error is fixed in 1.1.8.

error 1166 just does not apply totalSizeCap to the first two units of time , it depends on the smallest unit on the NamePattern file that you use, which means that for your scenario it will not consider the logs of the first two hours for caption totalSize.

My configuration was somehow taken from logback - examples;

 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <!-- daily rollover --> <fileNamePattern>logFile.%d{yyyy-MM-dd}.log</fileNamePattern> <!-- keep 30 days' worth of history capped at 3GB total size --> <maxHistory>30</maxHistory> <totalSizeCap>3GB</totalSizeCap> </rollingPolicy> 

So, we just switched from {yyyy-MM-dd} to {yyyy-MM-dd_HH} and, of course, maximized maxHistory to 30 * 24 . Thus, we made the last two hours not closed, and not the last two days , and for our case it was skipped. Of course, the log files will begin to tip over every hour, but, as I said, this is normal for our unique case.

+2
source share

All Articles