问题
I've the below mentioned logback file. I want to delete any logs older than 2 days or if the size of the logs exceed 500KB.
Logs older than 2days are getting deleted as expected. However Logs which exceed 500KB are not getting deleted. I tried to use ch.qos.logback.core.rolling.TimeBasedRollingPolicy
as well but the behavior is the same.
<property name="DEV_HOME" value="/home/kishore/test/logs" />
<appender name="INFO_LOG"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- <file>/home/kishore/test/logs/info.log</file> -->
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>
${DEV_HOME}/info-%d{yyyy-MM-dd}.log
</fileNamePattern>
<totalSizeCap>500KB</totalSizeCap>
<maxHistory>2</maxHistory>
</rollingPolicy>
<encoder>
<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
</Pattern>
</encoder>
</appender>
I also tried to specify <maxFileSize>100KB</maxFileSize>
and <fileNamePattern>${DEV_HOME}/info-%d{yyyy-MM-dd}.%i.log
, So the logs will be split into multiple files of 100KB each.
It splits as expected, but neither do these parts .0, .1, etc. get deleted after the overall size of all logs reach more than 500 KB.
Version of logback : 1.1.3
Am I missing any configuration?
回答1:
<totalSizeCap>
was added in v1.1.7. You'll need to upgrade.
来源:https://stackoverflow.com/questions/40905179/totalsizecap-in-logback-doesnt-seem-to-be-working-as-expected