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

    • Icon: Sub-task Sub-task
    • Resolution: Fixed
    • Icon: Major Major
    • 1.2.0
    • 1.1.8
    • logback-core
    • None
    • 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

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: