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

cann't delete the history log base on periodtype hour after system start

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • 1.2.3
    • logback-core
    • suse linux

    Description

      1. log setting:<appender name="DebugAppender"
             class="ch.qos.logback.core.rolling.RollingFileAppender">

        <file>${loggerHome}/logs/${moduleName}/debug/${moduleName}_debug.log</file>
        <append>true</append>

        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
         
         <fileNamePattern>${loggerHome}/logs/${moduleName}/debug/${moduleName}debug%d{yyyyMMddHH{color}}_%i.log</fileNamePattern>
         <maxHistory>2</maxHistory>
         <CleanHistoryOnStart>true</CleanHistoryOnStart>

         <maxFileSize>100MB</maxFileSize>
        </rollingPolicy>

        <encoder charset="UTF-8">
         <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS}|%-5level|[%thread]|%m%n%</pattern>
        </encoder>

       </appender>

      1. after set the CleanhistoryOnStart to true,  the history log cann't be deleted base on the rule.
      2. debugging the code,find the issue :ch.qos.logback.core.rolling.helper.RollingCalendar 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.");
              }
          }

      the red color code will return the number below 0. because covert long to int . the value will be < 0.

      It's the reason why we cann't delete the history logs after system start

       

      Attachments

        Activity

          People

            logback-dev Logback dev list
            yanwuhua yanwuhua
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: