Browse Source

REPORT-42043 fanruan.log无法分割-多线程问题

bokai 4 years ago
parent
commit
af4fb4b14d
  1. 20
      fine-log4j/src/main/java/com/fr/third/apache/log4j/DailyRollingFileAppender.java

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

@ -320,6 +320,10 @@ 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();
@ -346,11 +350,11 @@ public class DailyRollingFileAppender extends FileAppender {
gzos.write(inbuf, 0, n);
}
result = true;
} catch (Exception e){
} catch (Exception e) {
LogLog.error("Compress " + fileName + " to " + scheduledFilename + " failed.");
LogLog.error(e.getMessage(), e);
} finally {
if(gzos!=null) {
if (gzos != null) {
gzos.close();
}
if (fis != null) {
@ -358,26 +362,26 @@ public class DailyRollingFileAppender extends FileAppender {
}
}
if(result) {
if (result) {
if (!file.delete()) {
LogLog.debug("file delete failed, empty it.");
emptyFile(file);
}
LogLog.debug(fileName +" -> "+ scheduledFilename);
LogLog.debug(fileName + " -> " + scheduledFilename);
} else {
LogLog.error("Failed to rename ["+fileName+"] to ["+scheduledFilename+"].");
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, true, this.bufferedIO, this.bufferSize);
}
catch(IOException e) {
errorHandler.error("setFile("+fileName+", true) call failed.");
} catch (IOException e) {
errorHandler.error("setFile(" + fileName + ", true) call failed.");
}
scheduledFilename = datedFilename;
}
}
/**

Loading…
Cancel
Save