Sandeep
Sandeep

Reputation: 21

log4j.RollingFileAppender not compressing files

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

Upvotes: 2

Views: 3764

Answers (1)

Sam
Sam

Reputation: 1328

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>

Upvotes: 1

Related Questions