1

I am using SizeAndTimeBasedRollingPolicy in logback. For small values of maxFileSize and totalSizeCap, logback deletes older archived files only, when totalSizeCap limit is reached. But, for large values of totalSizeCap (~ 5GB) , it deletes all archived files.

I would like to delete only the older archived files, when totalSizeCap limit is reached.I am using logback version 1.2.3

Here, is the logback configuration i am using.

<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
   
     <file>${tivo.logpath}/${tivo.logfilename}.log</file>

  <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
   <!-- Rollover everyday. If file exceeds 1GB within a day, then file is archived with index starting from 0 -->
   <fileNamePattern>${tivo.logpath}/${tivo.logfilename}-%d{yyyyMMdd}-%i.log.gz</fileNamePattern>
   <!-- Each file should be at most 1GB -->
   <maxFileSize>1GB</maxFileSize>
   <!-- Keep maximum 30 days worth of archive files, deleting older ones -->
   <maxHistory>30</maxHistory>
   <!-- Total size of all archived files is at most 5GB -->
   <totalSizeCap>5GB</totalSizeCap>
     </rollingPolicy>
 
     <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
   <layout class="com.tivo.logging.logback.layout.JsonLayout">
    <env>${envId}</env>
    <datacenter>${dcId}</datacenter>
    <serverId>${serverId}</serverId>
    <build>${info.properties.buildChange}</build>
    <service>${tivo.appname}</service>
   </layout>
     </encoder>

   </appender> 

1 Answers1

1

Looks like this is a known issue with the logback version < 1.3.0.

Logback: SizeAndTimeBasedRollingPolicy applies totalSizeCap to each day in maxHistory

https://jira.qos.ch/browse/LOGBACK-1361

So, we might have to update to that version.

One other interesting bug fixed in the logback 1.3.0 will be: https://jira.qos.ch/browse/LOGBACK-1162

Vijay
  • 11
  • 2