问题
How to zip backup file in log4j RollingFileAppender
I have following log4j.properties file , while exceeding size limit it is creating backup file but not zipping it.
log4j.appender.request=org.apache.log4j.RollingFileAppender
log4j.appender.request.File=${catalina.home}/webapps/Sample/WEB-INF/logs/FAW_l4j.log
log4j.appender.request.MaxFileSize=10KB
log4j.appender.request.MaxBackupIndex=3
log4j.appender.request.RollingPolicy.ActiveFileName =${catalina.home}/webapps/Sample/WEB-INF/logs/FAW_l4j.log-%d.log.
log4j.appender.request.RollingPolicy.FileNamePattern=${catalina.home}/webapps/Sample/WEB-INF/logs/FAW_l4j.log-%d.log.zip
log4j.appender.request.layout = org.apache.log4j.PatternLayout
log4j.appender.request.layout.ConversionPattern=%d %p [%c{3}] - [%t] - %X{ip}: %m%n
回答1:
I have done this using logj extras . just configur your RollingFileAppender configuration with the following and having the filename end in .gz will compress your logfiles:
<appender...>
<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="FileNamePattern" value="/wombat/foo.%d{yyyy-MM}**.gz**"/>
</rollingPolicy>
</appender>
来源:https://stackoverflow.com/questions/14275701/log4j-rollingfileappender-not-compressing-files