I'm using log4j
and log4j.extras
to create a RollingFileAppender that rolls on two conditions:
- The working filesize exceeds a
MaxFileSize
threshold. - The system's date changes.
Following this guide, the appender needs both a TimeBasedRollingPolicy
and a SizeBasedTriggeringpolicy
, for example:
<appender name="file_logger" class="org.apache.log4j.rolling.RollingFileAppender">
<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="ActiveFileName" value="/fxh/logs/D3FIXFeeds.log" />
<param name="FileNamePattern" value="/fxh/logs/D3FIXFeeds.%d{HH-mm}.%i.log" />
</rollingPolicy>
<triggeringPolicy
class="org.apache.log4j.rolling.SizeBasedTriggeringPolicy">
<param name="MaxFileSize" value="50000" /> <!-- in bytes -->
</triggeringPolicy>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p - %m%n" />
</layout>
</appender>
How can I set a maximum limit on the total disk space of the log output? For example, say our server admin allots 40gb for logs to this application, is there anyway to specify this given the dual rolling policies?
So far the closest I've found is the maxBackupIndex
parameter. I can't event get this to work... For example, neither of these truncates the logs at only five files:
<appender name="file_logger" class="org.apache.log4j.rolling.RollingFileAppender">
<param name="MaxBackupIndex" value="5"/>
<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="ActiveFileName" value="/fxh/logs/D3FIXFeeds.log" />
<param name="FileNamePattern" value="/fxh/logs/D3FIXFeeds.%d{HH-mm}.%i.log" />
...
nor
<appender name="file_logger" class="org.apache.log4j.rolling.RollingFileAppender">
<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="ActiveFileName" value="/fxh/logs/D3FIXFeeds.log" />
<param name="FileNamePattern" value="/fxh/logs/D3FIXFeeds.%d{HH-mm}.%i.log" />
<param name="MaxBackupIndex" value="5"/>
...