Compression Log Rotation

We have a very old application deployed on a Linux server. We use RollingFileAppenderone that removes old logs due to disk space problems.

Whenever we get a problem in the application, most of the logs will not be available on disk. If we compress the log files, we can save 100 log files instead of one uncompressed log file.

Is there a way to compress the file after filling out the log file and delete it after a certain period of time [say, after a week.]

I tried with DailyRollingFileAppender, but it does not work as we expect.

The maximum log limit is 500. But the application creates 200 logs per hour. Actual logs containing error messages may not be available to us. Therefore, we plan to fix all the log files and delete them in a week.

+3
source share
3 answers

yes, kindly check this link. He supports it. Add this to your RollingFileAppender configuration.

<appender...>
    <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
      <param name="FileNamePattern" value="/wombat/foo.%d{yyyy-MM}**.gz**"/>
    </rollingPolicy>
</appender>
+1
source

I don’t know if log4j supports this, but if you go to logback you have such an opportunity.

http://logback.qos.ch/

Hayo

+1
source

All Articles