I'm having problem with my Logback in Java/Spring Boot application.
My Logback is keep creating large tmp files and it's taking over lots of disk usage.
This is how my RollingFileAppender in logback-config.xml looks like
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${appName}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${appName}.%d{yyyy-MM-dd}.log.gz</fileNamePattern>
<maxHistory>5</maxHistory>
<totalSizeCap>3GB</totalSizeCap>
</rollingPolicy>
</appender>
I'm aware that TimeBasedRollingPolicy rolls file every 00:00 in my option.
I've seend that %i option is needed for rolling index, and I tried it but %i option is not available in TimeBasedRollingPolicy and it's only used is SizeAndTimeBasedRollingPolicy.
Why is my logback keep creating large tmp files?
Let me know if you need anymore information.
Thank you.
ps. I know I can solve this issue by using SizeAndTimeBasedRollingPolicy and %i option, but I'm curious why this options is keep creating big tmp files.
Let see why the problem is :
timeBasedFileNamingAndTriggeringPolicy
inside rollingPolicy
How we can fix it :
We can set a triggering police for every 5 mb size file can be archive to another folder
consider below sample rollingPolicy
to avoid large log file
<property name="LOGS" value="${logging.file.path}" />
rollingPolicy
<appender name="RollingFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOGS}/info/app_info.log</file>
<encoder
class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<Pattern>%d %p %C{1.} [%t] %m%n</Pattern>
</encoder>
<rollingPolicy
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- rollover daily and when the file reaches 5 MegaBytes -->
<fileNamePattern>${LOGS}/info/archived/app_info-%d{yyyy-MM-dd}.%i.log
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>5MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
</appender>