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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…