This commit is contained in:
地平线
2015-09-02 11:29:26 +08:00
parent ae1a363a8f
commit 1c2c89ece5

View File

@@ -113,15 +113,18 @@ public class LogFileHandler extends Handler {
while (true) {
try {
LogRecord record = records.take();
if ((limit > 0 && limit <= length.get()) || tomorrow <= record.getMillis()) {
final boolean bigger = (limit > 0 && limit <= length.get());
if (bigger || tomorrow <= record.getMillis()) {
updateTomorrow();
if (stream != null) {
stream.close();
for (int i = Math.min(count - 2, index.get() - 1); i > 0; i--) {
File greater = new File(logfile.getPath() + "." + i);
if (greater.exists()) Files.move(greater.toPath(), new File(logfile.getPath() + "." + (i + 1)).toPath(), REPLACE_EXISTING, ATOMIC_MOVE);
if (bigger) {
for (int i = Math.min(count - 2, index.get() - 1); i > 0; i--) {
File greater = new File(logfile.getPath() + "." + i);
if (greater.exists()) Files.move(greater.toPath(), new File(logfile.getPath() + "." + (i + 1)).toPath(), REPLACE_EXISTING, ATOMIC_MOVE);
}
Files.move(logfile.toPath(), new File(logfile.getPath() + ".1").toPath(), REPLACE_EXISTING, ATOMIC_MOVE);
}
Files.move(logfile.toPath(), new File(logfile.getPath() + ".1").toPath(), REPLACE_EXISTING, ATOMIC_MOVE);
stream = null;
}
}