I have an application which uses JDK Logging with a logging.properties file which configures a number of older log-file via java.util.logging.FileHandler.count.
At certain points in the application I would like to trigger a manual rollover of the logfile to have a new logfile started, e.g. before a scheduled activity starts.
Is this possible with JDK Logging?
In Log4j I am using the following, however in this case I would like to use JDK Logging!
Logger logger = Logger.getRootLogger();
Enumeration<Object> appenders = logger.getAllAppenders();
while(appenders.hasMoreElements()) {
Object obj = appenders.nextElement();
if(obj instanceof RollingFileAppender) {
((RollingFileAppender)obj).rollOver();
}
}
You would have to write your own handler in order to get a rotation to work. Something like JBoss Log Manager works with JDK logging and just replaces the logmanger parts. It already has a few different rotating handlers.
}
You can trigger a rotation by creating a throw away FileHandler with a zero limit and no append.
new FileHandler(pattern, 0, count, false).close();
Otherwise you can resort to using reflection: