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=31458>. 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=31458 ------- Additional Comments From [EMAIL PROTECTED] 2005-12-08 15:36 ------- (In reply to comment #3) > We are experiencing this issue too. I've looked at the sources of > DailyRollingFileAppender.java and I think this can easily be fixed by changing > the rollOver method. Instead of the following code: > > File target = new File(scheduledFilename); > if (target.exists()) { > target.delete(); > } > > File file = new File(fileName); > boolean result = file.renameTo(target); > if(result) { > LogLog.debug(fileName +" -> "+ scheduledFilename); > } else { > LogLog.error("Failed to rename ["+fileName+"] to > ["+scheduledFilename+"]."); > } > > The following code: > > File target = new File(scheduledFilename); > if (!target.exists()) { > File file = new File(fileName); > boolean result = file.renameTo(target); > if(result) { > LogLog.debug(fileName +" -> "+ scheduledFilename); > } else { > LogLog.error("Failed to rename ["+fileName+"] to > ["+scheduledFilename+"]."); > } > } > > Maybe behind an option so that the user can choose for the (old) delete > behaviour and the new behaviour. > > Will this be incorporated in a future version of Log4J? But still there is a problem since when the new file descriptor is opened, the append varaible is set to "false". Image 3 JVMs writing in the same log file, only the last JVM opening the file will "win" the file and kick out any thing that the other 2 JVMs will write. The new file need to be opened with append = true! In the new version of RollingFileAppender in CVS (DailyRollingFileAppender is deprecated) the bollean append is set in the constructor by default to "true" and the method getAppend() is used to retrieve the value whenever needed. For the moment if you have still the problem as me, here is my class to fix it: package org.apache.log4j; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; import org.apache.log4j.helpers.LogLog; public class DailyRollingFileAppenderFix extends DailyRollingFileAppender { /** * Need this method since it computes the private variable scheduledFilename. * * @see DailyRollingFileAppender */ public void activateOptions() { super.activateOptions(); String datePattern = getDatePattern(); if (datePattern != null && fileName != null) { now.setTime(System.currentTimeMillis()); sdf = new SimpleDateFormat(datePattern); int type = computeCheckPeriod(); printPeriodicity(type); rc.setType(type); File file = new File(fileName); scheduledFilename = fileName + sdf.format(new Date(file.lastModified())); } else { LogLog.error("Either File or DatePattern options are not set for appender [" + name + "]."); } } void rollOver() throws IOException { String datePattern = getDatePattern(); if (datePattern == null) { errorHandler.error("Missing DatePattern option in rollOver()."); return; } String datedFilename = fileName + sdf.format(now); if (scheduledFilename.equals(datedFilename)) { return; } this.closeFile(); File target = new File(scheduledFilename); if (!target.exists()) { File file = new File(fileName); boolean result = file.renameTo(target); if (result) { LogLog.debug(fileName + " -> " + scheduledFilename); } else { LogLog.error("Failed to rename [" + fileName + "] to [" + scheduledFilename + "]."); } } try { // FIX - Set append to true due to multiple JVM opening multiple // file descriptor with the same file name. // Currently not in the version 1.2.13 (Rev. 353962 of DailyRollingFileAppender) setFile(fileName, true, this.bufferedIO, this.bufferSize); } catch (IOException _ex) { super.errorHandler.error("setFile(" + fileName + ", false) call failed."); } scheduledFilename = datedFilename; } private String scheduledFilename; } -- 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]
