Uploaded image for project: 'logback'
  1. logback
  2. LOGBACK-1166 totalSizeCap not work as expected
  3. LOGBACK-1231

Size capping does not work for files of ~2G or more

    XMLWordPrintable

    Details

    • Type: Sub-task
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.1.8
    • Fix Version/s: 1.2.0
    • Component/s: logback-core
    • Labels:
      None
    • Environment:

      Ubuntu

      Description

      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 case:
      1. If we are using release 1.1.7 and it already got lots of logs (size is more than 2^31 -1 ~= 2G), It doesn't work if I hope that this fix can help to clean the old logs through upgrading.
      2. If we configure totalSizeCap more than 2^31 -1 ~= 2G, it seems it will get overflow when we go through the file length. (I didn't test this one, it seems it is an issue with my understanding).

      After checked 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");
          }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              ceki Ceki Gülcü
              Reporter:
              Simon_Teng Simon Teng
              Votes:
              5 Vote for this issue
              Watchers:
              7 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: