I am using the org.apache.log4j.rolling.RollingFileAppender
in the apache-log4j-extras
package to compress the log once they are no longer the active log. Here is an example appender:
<appender name="TRACELOG" class="org.apache.log4j.rolling.RollingFileAppender">
<param name="file" value="logFileName.log" />
<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="FileNamePattern" value="logFileName.%d.log.gz" />
</rollingPolicy>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%t] %C{2} (%F:%L) - %m%n" />
</layout>
<filter class="org.apache.log4j.varia.LevelMatchFilter">
<param name="LevelToMatch" value="trace" />
<param name="AcceptOnMatch" value="true" />
</filter>
<filter class="org.apache.log4j.varia.DenyAllFilter" />
</appender>
What I would like to do is add something like <param name="MaxBackupIndex" value="14" />
so that it will essentially only keep 14 days worth of compressed logs, but when I try and use it, I get the following warning:
log4j:WARN No such property [maxBackupIndex] in org.apache.log4j.rolling.RollingFileAppender.
in extra rolling file appender (not the standard) there is no way to specify the rolling policy directly in the appender, cause it's specified in the rolling policy field.
The problem is that you're using a TimeBasedRollingPolicy that doesn't support maxBackupIndex, maxBackupIndex is only supported in FixedWindowRollingPolicy
You can write your custom file appender, which extends RollingFileAppender. Here is an example: http://www.javaworld.com/community/node/6148
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With