Search code examples
javafilenameslogback

Logback filenamepattern with time period


I currently have the requirement to create log files which contain the period for the containing entries in the filename.

So for example when I want to roll the file on a daily basis and the first log comes at 1:00 am and the last one at 22:00 pm, the filename should look something like this:

"logfile_2018_07_09_01_00 - 2018_07_09_22_00".

Is it possible to achieve this via xml-configuration?

Thanks in advance. Andreas


Solution

  • It seems not possible. You could create the logfiles with just the starting timestamp and then write an extended version of TimeBasedRollingPolicy that appends the second timestamp when rotating the file. But maybe it's easier to just write to info.log and have a shell script do the rotation and naming.