[Logback] What to do if unnecessary files do not disappear during rotation

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.

version

Why didn't the unnecessary files disappear! ??

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.

What should i do?

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.

Summary

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

[Logback] What to do if unnecessary files do not disappear during rotation
What to do if the breakpoint is shaded and does not stop during debugging
What to do if FacesMessage is set but not displayed
[Ubuntu 20.04] What to do if the external monitor is not recognized
[Rails] What to do if data is not registered in DB
What to do if you install Ubuntu
What to do if changes are not reflected after automatic deployment to EC2
What to do if you get an error during rails db: reset
What to do if the background image is not applied after deployment
What to do if the prefix c is not bound in JSP
What to do if deployment fails on Heroku (Ruby app not detected)
What to do if you push incorrect information
What to do if mvn archetype: generate fails
What to do if you get Could not locate Gemfile or .bundle / directory
What to do if the changes are not reflected in the jar manifest file
[Swift] What to do if the app icon is set but not reflected
What to do if the update does not take effect after deploying Rails AWS
What to do if the Rails server can't start
What to do if ClassNotFoundException occurs when starting Tomcat
What to do if rails server can't be stopped
What to do if TextToSpeech doesn't work on Android 11
What to do if you accidentally create a model
What to do if an ActionController :: UnknownFormat error occurs
What to do if the JSONHint annotation does not work with lombok and JSONIC
What to do if password authentication fails in Docker/Postgres
What to do if you installed Ruby with rbenv but the version does not change
[Swift5] What to do if you want to commit files to github but there are too many
What to do if you get an error in Basic authentication during Rails test code
What to do if you get a java.io.IOException in GlassFish
What to do when Method not found in f: ajax
# What to do if you accidentally do rails db: migrate: drop
What to do if the adb command cannot be executed
What to do if mysql2 gets a bundle install error
What to do if you can't use the rails command
[Note] What to do if bundle install in Chapter 3 of the rails tutorial is not possible
What to do if an SSH key authentication error occurs during automatic deployment to EC2 with Capistrano
What to do if the app is not created with the latest Rails version installed when rails new
What to do if you get "Changes not staged for commit:" when you git status after git add.
What to do if you get a gcc error in Docker
What to do if validation doesn't work with the update action
What to do when the changes in the Servlet are not reflected
What to do if the Rails page doesn't appear in Rails tutorial 1.3.2
What to do if Cloud9 is full in the Rails tutorial
What to do if the Eclipse Maven dependency Jar is wrong
[Rails] What to do when rails s does not respond or does not stop
What to do if you get a DISPLAY error in gym.render ()
What to do when you become a Problem During Content Assist
What to do if you forget the root password in CentOS7
What to do if you cannot roll back the migration (UnknownMigrationVersionError)
[Rails] What to do if you can't get parameters with form_with
What to do if Operation not permitted is displayed when you execute a command in the terminal
What to do after Vagrant install
What to do when javax.batch.operations.JobStartException occurs
What to do if JavaMail cannot be used with OpenJDK 11 or later
What to do if you get a groovy warning in Thymeleaf Layout
Add gem'rails-i18n','~> 6.0.0' and what to do if bundle install gives an error
[Composer] [Laravel] What to do if you cannot install due to insufficient memory
What to do if you get an uninitialized constant Likes Controller error
What to do if you can't install the plugin from the Eclipse marketplace
no space left on device What to do if an error occurs
What to do if you don't like the code generated by swagger-codegen-cli