Details
-
Improvement
-
Resolution: Unresolved
-
Minor
-
None
-
None
-
None
Description
It would be nice to have the option of having the SizeAndTimeBasedFNATP always create a new file on a restart (only applicable when <File> is not specified – only the <FileNamePattern>). Currently, if a process locks the latest file while the appender is stopped, then the FileAppender.openFile will fail if the file is still locked when the appender starts again.
I'm currently accomplishing this by overriding SizeAndTimeBasedFNATP.start and using reflection to increment the currentPeriodsCounter.
If a boolean option (e.g. "newFileOnStart") was added to SizeAndTimeBasedFNATP and computeCurrentPeriodsHighestCounterValue was modified to return whether or not a matching file was found, then the start method could be modified as shown below:
if (tbrp.getParentsRawFileProperty() == null) {
String regex = tbrp.fileNamePattern.toRegex(dateInCurrentPeriod);
String stemRegex = FileFilterUtil.afterLastSlash(regex);
// beginning of changes
boolean fileExists = computeCurrentPeriodsHighestCounterValue(stemRegex);
if (fileExists && newFileOnStart)
// end of changes
}