https://issues.apache.org/bugzilla/show_bug.cgi?id=44932
Summary: improve DailyRollingFileAppender handling of rotation
errors
Product: Log4j
Version: 1.2
Platform: PC
OS/Version: Windows XP
Status: NEW
Severity: enhancement
Priority: P2
Component: Appender
AssignedTo: [email protected]
ReportedBy: [EMAIL PROTECTED]
Request to improve DailyRollingFileAppender handling of errors during log
rotation. If an error occur,
P1. Old logs [to archive] can be lost. Can occur if
scheduled-file=name [to archive to] cannot be deleted during rotation
P2. It can end up infinite looping if ErrorHandler itself uses
DailyRollingFileAppender
To address above issues, I'm currently use customized version of
DailyRollingFileAppender with the following changes:
C1. If cannot delete scheduled-file-name, then continue appending
to existing file (i.e., don't rotate)
C2. Defer invocating ErrorHandler until very end of rollOver()
method.
i.e., Change Log4j v1.2.15 from
void rollOver() throws IOException {
...
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+"].");
}
try {
// This will also close the file. This is OK since
multiple
// close operations are safe.
this.setFile(fileName, false, this.bufferedIO,
this.bufferSize);
}
catch(IOException e) {
errorHandler.error("setFile("+fileName+", false) call
failed.");
}
...
}
to
void rollOver() throws IOException {
...
List<String> errMsgs = new LinkedList<String>();
boolean result = true;
if (target.exists()) {
result = target.delete();
}
if (! result) {
errMsgs.add("Failed to delete [" + scheduledFilename +
"]. Log file will not be rolled over!");
} else {
File file = new File(fileName);
result = file.renameTo(target);
if(result) {
LogLog.debug(fileName +" -> "+
scheduledFilename);
} else {
errMsgs.add("Failed to rename ["+fileName+"] to
["+scheduledFilename+"]. Log file will not be rolled over!");
}
}
try {
this.setFile(
fileName,
// Append if rollover [to schedule
file] failed, else overwrite
! result,
this.bufferedIO,
this.bufferSize);
// Finally write out error messages now that Log4j is
closer to being stable
for (String msg : errMsgs) {
errorHandler.error(msg);
}
}
catch(IOException e) {
errorHandler.error("setFile("+fileName+", false) call
failed.");
}
...
}
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]