DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUGĀ· RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://issues.apache.org/bugzilla/show_bug.cgi?id=43374>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED ANDĀ· INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=43374 Summary: DailyRollingFileAppender may delete files during rollover Product: Log4j Version: 1.2 Platform: PC OS/Version: Windows XP Status: NEW Severity: critical Priority: P2 Component: Appender AssignedTo: [email protected] ReportedBy: [EMAIL PROTECTED] CC: [EMAIL PROTECTED] The DailyRollingFileAppender (DRFA) tries to rename the log file during roll over. However, when the rename fails, it ends up overwriting the log file, hence loosing information. In particular, on Windows, the file rename can fail if another thread has the file open. This problem was found in 1.2.8 and still exists in 1.2.15. The problem was already described in bug 29726, but at that time the solution was left to 1.3. Then it was again addressed in bug 41735, but only for RollingFileAppender (RFA). I also talked about it on log4j-user ML (http://mail-archives.apache.org/mod_mbox/logging-log4j-user/200709.mbox/[EMAIL PROTECTED]). I created a unit test that reproduces the problem (and also tests RFA), and made a patch to solve this problem. The problem was reproduced with both log4j 1.2.9 & 1.2.15 in the following configurations (all combinations): - Win XP SP1, Win XP SP2, Win 2K3 - JDK 1.4.2_03-b02, 1.5.0_10-b03, 1.6.0_02-b06 - JUnit 3.8.1 The following patch applies on 1.2.15 and addresses the issue: (I tested it in all the above configurations.) Index: DailyRollingFileAppender.java =================================================================== --- DailyRollingFileAppender.java (revision 572567) +++ DailyRollingFileAppender.java (working copy) @@ -319,16 +319,19 @@ File file = new File(fileName); boolean result = file.renameTo(target); + boolean continueToAppend = false; if(result) { LogLog.debug(fileName +" -> "+ scheduledFilename); } else { - LogLog.error("Failed to rename ["+fileName+"] to ["+scheduledFilename+"]."); + // if file rename failed, reopen file with append = true + LogLog.warn("Failed to rename ["+fileName+"] to ["+scheduledFilename+"]."); + continueToAppend = true; } try { // This will also close the file. This is OK since multiple // close operations are safe. - this.setFile(fileName, false, this.bufferedIO, this.bufferSize); + this.setFile(fileName, continueToAppend, this.bufferedIO, this.bufferSize); } catch(IOException e) { errorHandler.error("setFile("+fileName+", false) call failed."); -- Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the assignee for the bug, or are watching the assignee. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
