summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Ritchie <ritchiem@apache.org>2009-12-16 17:18:49 +0000
committerMartin Ritchie <ritchiem@apache.org>2009-12-16 17:18:49 +0000
commit22f4920bf4f88629ab031749a3487e3fe6363fad (patch)
tree330fd2605a04b1420e51788f1918599f4c2164cf
parentf4c04b84ecbbe9c09be7f33e955b743301679968 (diff)
downloadqpid-python-22f4920bf4f88629ab031749a3487e3fe6363fad.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/qpid@891329 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--java/broker/src/main/java/org/apache/log4j/QpidCompositeRollingAppender.java51
1 files changed, 46 insertions, 5 deletions
diff --git a/java/broker/src/main/java/org/apache/log4j/QpidCompositeRollingAppender.java b/java/broker/src/main/java/org/apache/log4j/QpidCompositeRollingAppender.java
index 5aae336918..634fffdbc3 100644
--- a/java/broker/src/main/java/org/apache/log4j/QpidCompositeRollingAppender.java
+++ b/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;
}