views:

334

answers:

3

Is it possible to compress log files (I doing it via RollingFileAppender )?

+3  A: 

logj extras has support for that:

just add the following to your RollingFileAppender configuration and having the filename end in .gz will automagically compress your logfiles:

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

check here:

http://logging.apache.org/log4j/companions/extras/index.html

and here for some details in the javadoc:

http://logging.apache.org/log4j/companions/extras/apidocs/org/apache/log4j/rolling/TimeBasedRollingPolicy.html

hope that helped

smeg4brains
A: 

I know this does not exactly answer your question, but it does propose an alternate solution.

The way we handle that is by having a batch process run at the end of the day that compresses any prior log files to today's date, get's rid of any prior to a week old and then copies them off to another file server. This way the application does not need to consume any CPU cycles doing this and on the server we have logs that are no older than a week and on another file server we have older log files.

Romain Hippeau
A: 

@smeg4brains

how can i add it to the property file?

log4j.appender.DefaultLog=org.apache.log4j.RollingFileAppender log4j.appender.DefaultLog.File=${mailbox.root}/logs/application.log log4j.appender.DefaultLog.MaxFileSize=50MB log4j.appender.DefaultLog.MaxBackupIndex=100 log4j.appender.DefaultLog.layout=org.apache.log4j.PatternLayout log4j.appender.DefaultLog.layout.ConversionPattern=%d %p [%c] - %m%n

MiKu