A memo when I checked when the unnecessary file (= archive file that was out of save) did not disappear and became "Why ~" while verifying the validity of the rotation setting of Logback.
NOTE:
At the time of verification, I created a main method that outputs only one debug log and executed it with the system date shifted.
I have not investigated the detailed conditions, but in the case of a stand-alone application with a short execution time (= application that the process ends immediately after log output), unnecessary files that should be done after rotation of the log file (= out of save) Archive file) It seems that the JVM before the deletion process may be terminated.
By enabling the option to call the process to delete unnecessary files (= archive files that have been saved) when the application is started, unnecessary files can be deleted at the next execution timing.
Setting example when executing the process of deleting unnecessary files at startup
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>/var/log/app-%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>7</maxHistory>
<cleanHistoryOnStart>true</cleanHistoryOnStart> <!--★★★ Add here ★★★-->
</rollingPolicy>
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
<charset>UTF-8</charset>
</encoder>
</appender>
NOTE:
In the case of a resident application such as a Web application, unnecessary files are also deleted at the rotation timing unless there is a special case (= because it is very unlikely that the process will end at the time of switching). Even if you are unlucky and it is not deleted, it will be deleted at the next rotation opportunity, so it seems that there will be no problem even if you do not have the above settings.
Probably ... For apps that run on commercial services, it's almost okay to not specify cleanHistoryOnStart
. A batch app that ends in an instant kill! ?? If you have (although there seems to be a story that you don't have to batch if it ends in an instant kill ...), you may want to specify this option just in case.
Also ... If you don't include this option when checking the rotation operation like I do, you may end up wasting time asking "Why?".
Recommended Posts