|
|
@ -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 { |
|
|
|
void rollOver() throws IOException { |
|
|
|
|
|
|
|
|
|
|
@ -313,17 +313,13 @@ public class DailyRollingFileAppender extends FileAppender { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String datedFilename = fileName+sdf.format(now)+COMPRESS_SUFFIX; |
|
|
|
String datedFilename = fileName + sdf.format(now) + COMPRESS_SUFFIX; |
|
|
|
// It is too early to roll over because we are still within the
|
|
|
|
// It is too early to roll over because we are still within the
|
|
|
|
// bounds of the current interval. Rollover will occur once the
|
|
|
|
// bounds of the current interval. Rollover will occur once the
|
|
|
|
// next interval is reached.
|
|
|
|
// next interval is reached.
|
|
|
|
if (scheduledFilename.equals(datedFilename)) { |
|
|
|
if (scheduledFilename.equals(datedFilename)) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
synchronized (this) { |
|
|
|
|
|
|
|
if (scheduledFilename.equals(datedFilename)) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// close current file, and compress it to datedFilename
|
|
|
|
// close current file, and compress it to datedFilename
|
|
|
|
this.closeFile(); |
|
|
|
this.closeFile(); |
|
|
@ -336,9 +332,9 @@ public class DailyRollingFileAppender extends FileAppender { |
|
|
|
File file = new File(fileName); |
|
|
|
File file = new File(fileName); |
|
|
|
boolean result = false; |
|
|
|
boolean result = false; |
|
|
|
|
|
|
|
|
|
|
|
try (FileInputStream fis =new FileInputStream(file) ; |
|
|
|
try (FileInputStream fis = new FileInputStream(file); |
|
|
|
FileOutputStream fos = new FileOutputStream(target); |
|
|
|
FileOutputStream fos = new FileOutputStream(target); |
|
|
|
GZIPOutputStream gzos = new GZIPOutputStream(fos);){ |
|
|
|
GZIPOutputStream gzos = new GZIPOutputStream(fos);) { |
|
|
|
byte[] inbuf = new byte[8102]; |
|
|
|
byte[] inbuf = new byte[8102]; |
|
|
|
int n; |
|
|
|
int n; |
|
|
|
|
|
|
|
|
|
|
@ -351,11 +347,9 @@ public class DailyRollingFileAppender extends FileAppender { |
|
|
|
LogLog.error(e.getMessage(), e); |
|
|
|
LogLog.error(e.getMessage(), e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean isDeleteSuccess = true; |
|
|
|
if (result) { |
|
|
|
if (result) { |
|
|
|
if (!file.delete()) { |
|
|
|
isDeleteSuccess = file.delete(); |
|
|
|
LogLog.debug("file delete failed, empty it."); |
|
|
|
|
|
|
|
emptyFile(file); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
LogLog.debug(fileName + " -> " + scheduledFilename); |
|
|
|
LogLog.debug(fileName + " -> " + scheduledFilename); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
LogLog.error("Failed to rename [" + fileName + "] to [" + scheduledFilename + "]."); |
|
|
|
LogLog.error("Failed to rename [" + fileName + "] to [" + scheduledFilename + "]."); |
|
|
@ -368,6 +362,16 @@ public class DailyRollingFileAppender extends FileAppender { |
|
|
|
} catch (IOException e) { |
|
|
|
} catch (IOException e) { |
|
|
|
errorHandler.error("setFile(" + fileName + ", true) call failed."); |
|
|
|
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; |
|
|
|
scheduledFilename = datedFilename; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|