[logback-dev] [JIRA] (LOGBACK-1416) cann't delete the history log base on periodtype hour after system start

QOS.CH (JIRA) noreply-jira at qos.ch
Sat Aug 25 03:25:00 CEST 2018


yanwuhua created LOGBACK-1416:
---------------------------------

             Summary: cann't delete the history log base on periodtype hour after system start
                 Key: LOGBACK-1416
                 URL: https://jira.qos.ch/browse/LOGBACK-1416
             Project: logback
          Issue Type: Bug
          Components: logback-core
    Affects Versions: 1.2.3
         Environment: suse linux
            Reporter: yanwuhua
            Assignee: Logback dev list


# 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\{{color:#d04437}yyyyMMddHH{color}}_%i.log</fileNamePattern>
   <maxHistory>2</maxHistory>
  {color:#d04437} <CleanHistoryOnStart>true</CleanHistoryOnStart>{color}

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

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

 </appender>

 # after set the CleanhistoryOnStart to true,  the history log cann't be deleted base on the rule.
 # 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;
        {color:#d04437}case TOP_OF_HOUR:{color}

{color:#d04437}            return (int) diff / MILLIS_IN_ONE_HOUR;{color}
        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

 



--
This message was sent by Atlassian JIRA
(v7.3.1#73012)


More information about the logback-dev mailing list