Browse Source

REPORT-42043 fanruan.log无法分割-代码质量

release/10.0
bokai 4 years ago
parent
commit
f267eabbae
  1. 22
      fine-log4j/src/main/java/com/fr/third/apache/log4j/DailyRollingFileAppender.java

22
fine-log4j/src/main/java/com/fr/third/apache/log4j/DailyRollingFileAppender.java

@ -303,7 +303,7 @@ public class DailyRollingFileAppender extends FileAppender {
}
/**
Rollover the current file to a new file.
* Rollover the current file to a new file.
*/
void rollOver() throws IOException {
@ -320,10 +320,6 @@ public class DailyRollingFileAppender extends FileAppender {
if (scheduledFilename.equals(datedFilename)) {
return;
}
synchronized (this) {
if (scheduledFilename.equals(datedFilename)) {
return;
}
// close current file, and compress it to datedFilename
this.closeFile();
@ -351,11 +347,9 @@ public class DailyRollingFileAppender extends FileAppender {
LogLog.error(e.getMessage(), e);
}
boolean isDeleteSuccess = true;
if (result) {
if (!file.delete()) {
LogLog.debug("file delete failed, empty it.");
emptyFile(file);
}
isDeleteSuccess = file.delete();
LogLog.debug(fileName + " -> " + scheduledFilename);
} else {
LogLog.error("Failed to rename [" + fileName + "] to [" + scheduledFilename + "].");
@ -368,6 +362,16 @@ public class DailyRollingFileAppender extends FileAppender {
} catch (IOException e) {
errorHandler.error("setFile(" + fileName + ", true) call failed.");
}
if(!isDeleteSuccess){
synchronized (this) {
if (scheduledFilename.equals(datedFilename)) {
return;
}
LogLog.debug("file delete failed, empty it.");
emptyFile(file);
scheduledFilename = datedFilename;
}
}else {
scheduledFilename = datedFilename;
}
}

Loading…
Cancel
Save