Affects Version/s: 2.7
Fix Version/s: 2.8
After having worked on
LOG4J2-1649 I found another serious issue in combination with the CronTriggeringPolicy.
The policy has some very weird behaviour when it comes to naming rolled over files and also creates a NPE on specific configurations.
The following is broken:
- when using "evaluateOnStartup" a NPE is the result of an immediate rollover
- when no rollover is happing at startup the first rollover produces a file that uses the time of the rollover (e.g. rollover is happening at midnight 2010-05-05 producing a rolled over file named log-2010-05-05)
- but it becomes worse: all files after the first rollover are named using a date of the "previous rollover date minus a second" - when using the previous example this results in:
- first rollover happening at midnight 2010-05-05, resulting in file log-2010-05-05
- next rollover happening at 2010-05-06, resulting in file log-2010-05-04
- next rollover happening at 2010-05-07, resulting in file log-2010-05-05 again so the previously saved file gets removed!
I would expect the file to be named after the content it contains. E.g. a file rolled over at 2010-05-05 should be named log-2010-05-04 as it contains all the data of the 2010-05-04.
So I decided to write a patch for those problems too (again the sources of Log4J2 2.7 were used). Unfortunately I needed a method to calculate the last cron date. The CronExpression class has such a method ("getTimeBefore") but nobody implemented this one since years.
The only quick solution I found: I used another 3rd party library to fix this called cronutils. The solution I wrote uses the latest version of this library which now only supports Java 8.
My guess is that you don't want Log4J2 to only support Java 8 - if this is the case you will have to use a different library/version or whatever to be able to calculate the last cron date.