I did some testing recently by porting fix of
LOGBACK-1166
to our project which needs this fix urgently.
It seems this fix still cannot fix totalSizeCap issue entirely. It cannot cover below two cases: 1. If we are using release 1.1.7 and it already got lots of logs (size is more than 3G), It doesn't work if I hope that this fix can help to clean the old through upgrading. 2. If I configure totalSizeCap's value greater than 3G, It doesn't work because of the overflow.
After check the code, it seems we need to change the local variable (totalSize and totalRemoved)'s type from int to long in function void capTotalSize(Date now) in file logback-core/src/main/java/ch/qos/logback/core/rolling/helper/TimeBasedArchiveRemover.java.
void capTotalSize(Date now) { int totalSize = 0; int totalRemoved = 0; for (int offset = 0; offset < maxHistory; offset++) { Date date = rc.getEndOfNextNthPeriod(now, -offset); File[] matchingFileArray = getFilesInPeriod(date); descendingSortByLastModified(matchingFileArray); for (File f : matchingFileArray) { long size = f.length(); if (totalSize + size > totalSizeCap) { addInfo("Deleting [" + f + "]" + " of size " + new FileSize(size)); totalRemoved += size; f.delete(); }
totalSize += size; } } addInfo("Removed " + new FileSize(totalRemoved) + " of files"); }
|