Missing log4j log files with DailyRollingFileAppender when they should roll over?
Posted by Vivek Agarwal on February 9, 2008
Yes, I am back with a blog entry after quite a gap here! I have been knocked out sick for 5 weeks now and I am sick of being sick! Better now and hoping to be back at a 100% soon. Enough excuses – onto the subject of this blog entry. We use Log4j’s DailyRollingFileAppender in a WebSphere Portal environment to generate daily log files for various custom portlets that we have deployed. This worked just fine on some WPE v6 test servers with multiple portlets logging to the same log file, and the daily rollover occurring every midnight. However, on some other WPE v6 test servers running the exact same applications, while logging did work the daily rollover did not. Instead of us having multiple log files with date timestamps in their names, we would only have today’s log file – the previous log files would simply disappear! This issue results from the fact that the DailyRollingFileAppender (DRFA) tries to rename the log file during rollover. However, when the rename fails, it ends up overwriting the log file, hence losing information. On checking the application server’s SystemErr.log, we found an error each midnight similar to -
log4j:ERROR Failed to rename [logfilename] to logfilename.2008.01.11].
This appears to be a fairly common issue with log4j 1.2.x in Java application servers running on Windows. While there is no good resolution for this issue there is a workaround that works pretty well.
We ended up getting the DatedFileAppender which is a log4j extension that is publicly available at http://minaret.biz/tips/datedFileAppender.html. DatedFileAppender avoids the need for renaming the log file by simply creating the log file initially with the date in the file name – this is a simple workaround for the problem that we were experiencing. Switching from the DailyRollingFileAppender to DatedFileAppender was fairly seamless. In addition to installing the jar in WebSphere Portal, we had to switch a few lines of our log4j configuration. We changed the following lines -
log4j.appender.sametimeSyncAppender.Period=month # this line is only needed if the period is not a day
18 Responses to “Missing log4j log files with DailyRollingFileAppender when they should roll over?”
Sorry, the comment form is closed at this time.