log4j.RollingFileAppender not compressing files

六月ゝ 毕业季﹏ 提交于 2019-12-08 01:01:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!