Log4j log file for each run

I have a Java project using a log4j application that works like a package.

I would like it to roll a file for every execution.

Log4j offers to collapse the file either in time ( DailyRollingFileAppender ) or in file length ( RollingFileAppender ), which is good for constantly running applications, for example, in Java EE, but not very good for a package.

Is there a way to manually run the file?

+4
source share
1 answer

Finally, it was easy, I just needed to do the following:

 for (Enumeration<Appender> e = Logger.getRootLogger().getAllAppenders(); e.hasMoreElements();) { Appender a = e.nextElement(); if (a instanceof RollingFileAppender) { ((RollingFileAppender) a).rollOver(); } } 

at the beginning of the party ...

+3
source

All Articles