Reputation: 659
I have an application that only runs when triggered by hardware. An legacy c++ application that we recently added log4cxx too, to generate logs to help debug rare production issues. We of course wanted daily logfiles.
It turns out that we never got rolling files.
To debug the problem we set it roll over on the minute rather than the day. We found that if the program was called within a few seconds from the top of the minute, the file would roll over. If it was called more than 5 seconds after the top of the minute, roll over did not occur.
In testing the program takes roughly 5 seconds to run.
Is there anyway to have log4 rollover the file when the program starts, if needed?
i.e. If we logged at minute 6 and then don't run again until minute 50, we'll roll over the log file before we starting logging for minute 50, rather than just appending to minute 6.
Upvotes: 2
Views: 1965
Reputation: 2585
DailyRollingFileAppender
didn't work in my case too (at log4cxx 0.10.0), so I ended up using RollingFileAppender
plus TimeBasedRollingPolicy
:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="roll" class="org.apache.log4j.rolling.RollingFileAppender">
<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="FileNamePattern" value="roll.%d{yyyy-MM-dd}.log"/>
</rollingPolicy>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%p %t %c - %m%n"/>
</layout>
<param name="Append" value="true"/>
</appender>
<root>
<priority value="ALL"/>
<appender-ref ref="roll"/>
</root>
</log4j:configuration>
Point is not to specify <param name="file">
or it won't roll over (also it doesn't recognize StaticLogFileName
param as in the original log4j).
Upvotes: 2
Reputation: 1366
Try {
log4j.rootLogger=debug, R
# Pattern to output the caller's file name and line number.
log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.DatePattern=test-%Y-%m-%d.log
}
Upvotes: 1