Browse Source

REPORT-42043 fanruan.log无法分割

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

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

@ -24,6 +24,7 @@ import com.fr.third.apache.log4j.spi.LoggingEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.text.SimpleDateFormat;
@ -358,7 +359,10 @@ public class DailyRollingFileAppender extends FileAppender {
}
if(result) {
file.delete();
if (!file.delete()) {
LogLog.debug("file delete failed, empty it.");
emptyFile(file);
}
LogLog.debug(fileName +" -> "+ scheduledFilename);
} else {
LogLog.error("Failed to rename ["+fileName+"] to ["+scheduledFilename+"].");
@ -375,6 +379,24 @@ public class DailyRollingFileAppender extends FileAppender {
scheduledFilename = datedFilename;
}
/**
* @param file empty file
*/
private static void emptyFile(File file) {
try {
if (!file.exists()) {
file.createNewFile();
}
FileWriter fileWriter = new FileWriter(file);
fileWriter.write("");
fileWriter.flush();
fileWriter.close();
} catch (IOException e) {
LogLog.debug("empty file failed:" + e.getMessage() + e);
}
}
/**
* This method differentiates DailyRollingFileAppender from its
* super class.

Loading…
Cancel
Save