Logback:SizeAndTimeBasedRollingPolicy在达到totalSizeCap时删除所有已归档的文件

时间:2018-05-24 10:29:41

标签: logback logback-classic

我在logback中使用SizeAndTimeBasedRollingPolicy。对于较小的maxFileSize和totalSizeCap值,只有达到totalSizeCap限制时,logback才会删除旧的归档文件。但是,对于totalSizeCap(~5GB)的较大值,它会删除所有已归档的文件。

当我达到totalSizeCap限制时,我只想删除旧的归档文件。我使用的是logback版本1.2.3

这是我正在使用的logback配置。

<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 个答案:

答案 0 :(得分:1)

看起来这是logback版本的已知问题&lt; 1.3.0。

Logback: SizeAndTimeBasedRollingPolicy applies totalSizeCap to each day in maxHistory

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

因此,我们可能需要更新到该版本。

在logback 1.3.0中修复的另一个有趣的错误是: https://jira.qos.ch/browse/LOGBACK-1162