Uploaded image for project: 'logback'
  1. logback
  2. LOGBACK-1562

The old log files didn't get removed when fileNamePattern is configured by "yyyyMMddHH"

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: Major Major
    • 1.3.0-alpha7
    • 1.2.3
    • logback-core
    • None

    Description

      This is my logback configuration:

      <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
      <fileNamePattern>
      ${RECORD_BASE_DIR}/send/${logName}${HOST_IP}%d{yyyyMMddHH}_%i.txt
      </fileNamePattern>
      <maxFileSize>${RECORD_FILESIZE}</maxFileSize>
      <totalSizeCap>2GB</totalSizeCap>
      <maxHistory>168</maxHistory>
      </rollingPolicy>

       

      but it can not delete old files  althouth it is over the 168 files .

       

      So I track the  logback source and found that  when the fileNamePattern is configured by "TOP_OF_HOUR" ,  the code ' (int) diff / MILLIS_IN_ONE_HOUR' alaways return '-425'; it is incorrect.

      It should be written by return (int) (diff / MILLIS_IN_ONE_HOUR;

       

       

      The logback source code is:

      public long periodBarriersCrossed(long start, long end) {
      if (start > end)
      throw new IllegalArgumentException("Start cannot come before end");

      long startFloored = getStartOfCurrentPeriodWithGMTOffsetCorrection(start, getTimeZone());
      long endFloored = getStartOfCurrentPeriodWithGMTOffsetCorrection(end, getTimeZone());

      long diff = endFloored - startFloored;

      switch (periodicityType) {

      case TOP_OF_MILLISECOND:
      return diff;
      case TOP_OF_SECOND:
      return diff / MILLIS_IN_ONE_SECOND;
      case TOP_OF_MINUTE:
      return diff / MILLIS_IN_ONE_MINUTE;
      case TOP_OF_HOUR:

      return (int) diff / MILLIS_IN_ONE_HOUR;
      case TOP_OF_DAY:
      return diff / MILLIS_IN_ONE_DAY;
      case TOP_OF_WEEK:
      return diff / MILLIS_IN_ONE_WEEK;
      case TOP_OF_MONTH:
      return diffInMonths(start, end);
      default:
      throw new IllegalStateException("Unknown periodicity type.");
      }
      }

      Attachments

        Activity

          People

            ceki Ceki Gülcü
            likongze likongze
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: