3
votes

We have very old application deployed in Linux server. We are using the RollingFileAppender which is deleting the old logs due to disk space problems.

Whenever we get a problem in the application most of the logs won't available in the disk. If we compress the log files, we can keep 100 log files in place of one uncompressed log file.

Is there a way to compress the file once the log file is filled up and delete them after certain point of time [lets say a week.]

I tried with DailyRollingFileAppender, but it is not working the way we are expecting.

Maximum logs limit is 500. But the application creates 200 logs per hour. The actual logs which contains the error messages may not be available for us. So we are planning to zip all the log files and delete them after one week of time.

3
have the shell script zip the logs every night , and then move them to a secondary storage device - Satya
"it is not working the way we are expecting"... so tell us what you were expecting, and how DailyRollingFileAppender differs from that. - skaffman

3 Answers

2
votes

yes, kindly check this link. It has support for that. Add this to RollingFileAppender configuration.

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

I dont know if log4j supports this, but if you move to logback you have this possibility.

http://logback.qos.ch/

Hajo

0
votes

yes, a shell script or a cron http://unixhelp.ed.ac.uk/CGI/man-cgi?crontab+5 would fix your problem quite easily