Compress Log4j files
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.
Try Log4j v2.x
I came upon this great answer, but then kept investigating a bit and log4j 2 is out!
Now you can have compression with the basic library and much, much more... it's just awesome!
RollingFileAppender - I was looking for something that had both timeBased and sizeBased rolling, and with compression... it has both! and I can drop my syslog4j library since this one has it also!
Please don't use log4j 1.2 + extras unless you really have to.
log4j extras has support for that.
Just add the following to your RollingFileAppender
configuration and have the filename end in .gz to automagically compress your log files:
<appender...>
<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="FileNamePattern" value="/wombat/foo.%d{yyyy-MM}.gz"/>
</rollingPolicy>
</appender>
For more details check the Javadoc