I'd like to output logging for a specific amount of time and for a selection of classes to a second file. Right now I use this code:
FileAppender appender = new FileAppender(new PatternLayout(PATTERN), filePath);
Logger.getRootLogger().addAppender(appender);
log.info("test");
appender.close();
This does work for logging for a limited time, but instead of specific classes, all my logging is output to the second logfile. An alternative is using class specific logging:
FileAppender appender = new FileAppender(new PatternLayout(PATTERN), filePath);
Logger.getLogger(A.class).addAppender(appender);
Logger.getLogger(B.class).addAppender(appender);
Logger.getLogger(C.class).addAppender(appender);
log.info("test");
appender.close();
Which is closer to what I want, but it's hard to make an exhaustive list of the classes in use.
Is it possible to programmatically add an appender based on thread or based on package name?