diff options
author | Martin Ritchie <ritchiem@apache.org> | 2009-12-16 17:18:49 +0000 |
---|---|---|
committer | Martin Ritchie <ritchiem@apache.org> | 2009-12-16 17:18:49 +0000 |
commit | 54e144a946893b420b25ba4d16921c6241a60d0a (patch) | |
tree | 17fff527eb19bbce6ce6d7d6549f3aae30935ed6 | |
parent | f034a9a0449e4fdf68d5cc6f591c114216a0449e (diff) | |
download | qpid-python-54e144a946893b420b25ba4d16921c6241a60d0a.tar.gz |
QPID-2275 : Update to address CountDirection 0 increments when MaxFileSize kicks in before DatePattern.
Now it is possible to specify a DatePattern with small units (seconds/minutes) and not lose log file date when the MaxFileSize causes the file to roll over
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@891329 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | qpid/java/broker/src/main/java/org/apache/log4j/QpidCompositeRollingAppender.java | 51 |
1 files changed, 46 insertions, 5 deletions
diff --git a/qpid/java/broker/src/main/java/org/apache/log4j/QpidCompositeRollingAppender.java b/qpid/java/broker/src/main/java/org/apache/log4j/QpidCompositeRollingAppender.java index 5aae336918..634fffdbc3 100644 --- a/qpid/java/broker/src/main/java/org/apache/log4j/QpidCompositeRollingAppender.java +++ b/qpid/java/broker/src/main/java/org/apache/log4j/QpidCompositeRollingAppender.java @@ -890,10 +890,51 @@ public class QpidCompositeRollingAppender extends FileAppender else if (countDirection == 0) { // rollFile based on date pattern - curSizeRollBackups++; now.setTime(System.currentTimeMillis()); - scheduledFilename = fileName + sdf.format(now); - rollFile(fileName, scheduledFilename, compress); + String newFile = fileName + sdf.format(now); + + // If we haven't rolled yet then validate we have the right value + // for curSizeRollBackups + if (curSizeRollBackups == 0) + { + //Validate curSizeRollBackups + curSizeRollBackups = countFileIndex(newFile); + // to balance the increment just coming up. as the count returns + // the next free number not the last used. + curSizeRollBackups--; + } + + // If we are not keeping an infinite set of backups the delete oldest + if (maxSizeRollBackups > 0) + { + // Don't prune older files if they exist just go for the last + // one based on our maxSizeRollBackups. This means we may have + // more files left on disk that maxSizeRollBackups if this value + // is adjusted between runs but that is an acceptable state. + // Otherwise we would have to check on startup that we didn't + // have more than maxSizeRollBackups and prune then. + + if (((curSizeRollBackups - maxSizeRollBackups) >= maxSizeRollBackups)) + { + // delete the first and keep counting up. + int oldestFileIndex = curSizeRollBackups - maxSizeRollBackups + 1; + deleteFile(newFile + '.' + oldestFileIndex); + } + } + + + String finalName = newFile; + + curSizeRollBackups++; + + // Add rollSize if it is > 0 + if (curSizeRollBackups > 0 ) + { + finalName = newFile + '.' + curSizeRollBackups; + + } + + rollFile(fileName, finalName, compress); } else { // countDirection > 0 @@ -954,7 +995,7 @@ public class QpidCompositeRollingAppender extends FileAppender // It is possible for index 1..n to be missing leaving n+1..n+1+m logs // in this scenario we should still return n+1+m+1 int index=1; - + testFileName = fileName + "." + index; // Check that we do not have the 1..n missing scenario @@ -1008,7 +1049,7 @@ public class QpidCompositeRollingAppender extends FileAppender index++; testFileName = fileName + "." + index; } - + return index; } |