|
|
|
@ -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. |
|
|
|
|