Search code examples
logbacklog4j2

FileAppender with maxHistory


I am writing a batch application. It is desirable for me to create a new log file at each new application launch. I am tempted to use logback's Uniquely named file. So if I run the batch application 100 times, it will create 100 log files. I also desire a maximum number of 30 archive files to keep and asynchronously deleting older files. Here is another stackoverflow question asking the same. But I do not want to write code, is there a way to easily achieve that using logback?


Solution

  • I ended up using log4j2's RollingFileAppender. It has a "OnStartup Triggering Policy" which is perfect for batch applications.