Details
- 
    
Bug
 - 
    Resolution: Cannot Reproduce
 - 
    
Major
 - 
    1.2.3
 - 
    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
Issue Links
- relates to (out)
 - 
                    
LOGBACK-1458 TimeBasedRollingPolicy with MaxHistory would not delete log file created by startup with 0 size
-         
 - Resolved
 
 -