It would be useful to automatically attach log files to support emails. I could set the path programmatically (as in Setting Logback Appender path programmatically), but I'd prefer to let users configure logging in the familiar way via logback.xml
. So, can I find the files logback uses for logging?
You can get the list of all appenders in a certain context. To do this:
LoggerContext context = (LoggerContext)LoggerFactory.getILoggerFactory();
for (Logger logger : context.getLoggerList()) {
for (Iterator<Appender<ILoggingEvent>> index = logger.iteratorForAppenders(); index.hasNext();) {
Appender<ILoggingEvent> appender = index.next();
}
}
This iterates over the list of all appenders in all loggers for the current context.