[logback-dev] [JIRA] Updates for LOGBACK-1562: The old log files didn't get removed when fileNamePattern is configured by "yyyyMMddHH"

QOS.CH (JIRA) noreply-jira at qos.ch
Tue Jun 29 10:13:00 CEST 2021


logback / LOGBACK-1562 [Open]
The old log files didn't get removed when  fileNamePattern is configured by "yyyyMMddHH"

==============================

Here's what changed in this issue in the last few minutes.
This issue has been created
This issue is now assigned to you.

View or comment on issue using this link
https://jira.qos.ch/browse/LOGBACK-1562

==============================
 Issue created
------------------------------

likongze created this issue on 29/Jun/21 9:57 AM
Summary:              The old log files didn't get removed when  fileNamePattern is configured by "yyyyMMddHH"
Issue Type:           Bug
Affects Versions:     1.2.3
Assignee:             Logback dev list
Components:           logback-core
Created:              29/Jun/21 9:57 AM
Priority:             Major
Reporter:             likongze
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**)**;***
  
  
  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:#FF0000}*case TOP_OF_HOUR:*{color}
  
  {color:#FF0000} *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.");
   }
  }


==============================
 This message was sent by Atlassian Jira (v8.8.0#808000-sha1:e2c7e59)



More information about the logback-dev mailing list