Details
-
Bug
-
Resolution: Fixed
-
Major
-
None
-
None
-
None
Description
Here's the failure case:
Configuration:
<appender name="appender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>c:/var/tmp/base.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>
c:/var/tmp/%d
.%i.log
</FileNamePattern>
<TimeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<MaxFileSize>1KB</MaxFileSize>
</TimeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%d
[%thread] %-5level %logger
{36} - %msg%n
</Pattern>
</layout>
</appender>
Steps to reproduce:
1. Start the application
2. base.log was created.
3. yyyy-MM-dd_HH.0.log was created on rollover
4. rebounce the application
5. log to base.log
6. yyyy-MM-dd_HH.0.log was created on rollover, overwrite the previous yyyy-MM-dd_HH.0.log. Logging messages are lost.
It looks like the root cause is that SizeAndtimeBasedFNATP does not update the currentPeriodsCounter when parentsRawFileProperty is set.
if (tbrp.getParentsRawFileProperty() == null)
SizeAndTimeBasedFNATP should update currentPeriodsCounter regardless whether parentsRawFileProperty is set or not.
Here's a fix works for me.
SizeAndTimeBasedFNATP.java
@Override
public void start() {
// we depend on certain fields having been initialized
// in super.start()
super.start();
archiveRemover = new SizeAndTimeBasedArchiveRemover(tbrp.fileNamePattern, rc);
archiveRemover.setContext(context);
// we need to get the correct value of currentPeriodsCounter.
// usually the value is 0, unless the appender or the application
// is stopped and restarted within the same period
//if (tbrp.getParentsRawFileProperty() == null)
started = true;
}
void computeCurrentPeriodsHighestCounterValue(final String stemRegex) {
File file = new File(getCurrentPeriodsFileNameWithoutCompressionSuffix());
File parentDir = file.getParentFile();
File[] matchingFileArray = FileFilterUtil
.filesInFolderMatchingStemRegex(parentDir, stemRegex);
if (matchingFileArray == null || matchingFileArray.length == 0)
{ return; } FileFilterUtil.reverseSortFileArrayByName(matchingFileArray);
currentPeriodsCounter = FileFilterUtil.extractCounter(matchingFileArray[0], stemRegex);
//If parentsRawFileProperty is set, we should increment currentPeriodsCounter by one in order to avoid overwrite the last archive file.
if(tbrp.getParentsRawFileProperty() != null)
}
Thanks,
Tom