Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4j: Rolling logs into .gz file with DailyRollingFileAppender using TimeBasedRollingPolicy

Tags:

log4j

The current system is working as expected and the log files are rolled once an hr according to the logic below:

log4j.appender.oozie=org.apache.log4j.DailyRollingFileAppender
log4j.appender.oozie.DatePattern='.'yyyy-MM-dd-HH
log4j.appender.oozie.File=${oozie.log.dir}/oozie.log
log4j.appender.oozie.Append=true
log4j.appender.oozie.layout=org.apache.log4j.PatternLayout
log4j.appender.oozie.layout.ConversionPattern=%d{ISO8601} %5p %c{1}:%L - %m%n

I can understand that rolling of log file directly into a compressed file(.gz or .zip) is possible with RollingFileAppender(rolling based on file size) using TimeBasedRollingPolicy. I'm using DailyRollingFileAppender(time based rolling) and would like to achieve compression with that. I modified my properties as follows. But that doesnt work.

log4j.appender.oozie=org.apache.log4j.DailyRollingFileAppender
log4j.appender.oozie.DatePattern='.'yyyy-MM-dd-HH
log4j.appender.oozie.File=${oozie.log.dir}/oozie.log
log4j.appender.oozie.Append=true
log4j.appender.oozie.RollingPolicy=org.apache.log4j.rolling.TimeBasedRollingPolicy
log4j.appender.oozie.RollingPolicy.FileNamePattern=foo.%d{yyyy-MM-dd-HH}.gz
log4j.appender.oozie.layout=org.apache.log4j.PatternLayout
log4j.appender.oozie.layout.ConversionPattern=%d{ISO8601} %5p %c{1}:%L - %m%n

Any pointers would be highly appreciated. Here are some relevant links.

Configuring RollingFileAppender in log4j

http://logging.apache.org/log4j/companions/extras/apidocs/org/apache/log4j/rolling/TimeBasedRollingPolicy.html

like image 244
userkn87 Avatar asked Nov 25 '11 04:11

userkn87


1 Answers

Pardon my surprise, but at the exact link you gave above it says in the accepted answer:

Note that TimeBasedRollingPolicy can only be configured with xml, not log4j.properties

Have you tried rewriting your configuration to XML format?

like image 194
MaDa Avatar answered Sep 30 '22 09:09

MaDa