Log4j: archive file deletion policy

I use TimeBasedRollingPolicy and RollingFileAppender so that my logs are redirected and archived as myLogFileName..log.gz:

<appender class="org.apache.log4j.rolling.RollingFileAppender" name="myLogFile"> <param value="/var/log/my/myLogFileName.log" name="File"/> <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy"> <param name="FileNamePattern" value="/var/log/my/myLogFileName.%d.log.gz" /> </rollingPolicy> <layout class="org.apache.log4j.PatternLayout"> <param value="%d [%t] %-5p - %m%n" name="ConversionPattern"/> </layout> </appender> 

What I don’t understand - where is it determined when and how will really old archive files be completely deleted from the file system?

And, if I want to always always store only files no older than one month old - where can I configure it (using log4j (optional))?

+6
source share
1 answer

Your question will be answered. How can I get log4j to delete old rotation log files?

RollingFileAppender does this. You just need to set maxBackupIndex to the maximum value for the backup file.

Or you can use a script How to configure log4j to only store log files for the last seven days?

+1
source

Source: https://habr.com/ru/post/955901/


All Articles