Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to find logback log files programmatically?

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?

like image 200
Alexey Romanov Avatar asked Aug 15 '11 11:08

Alexey Romanov


People also ask

Where can I find Logback XML?

xml or logback. xml can be located directly under any folder declared in the class path. For example, if the class path reads "c:/java/jdk15/lib/rt.

What is Appender in Logback?

The Logback architecture is comprised of three classes: Logger, Appender, and Layout. A Logger is a context for log messages. This is the class that applications interact with to create log messages. Appenders place log messages in their final destinations. A Logger can have more than one Appender.

What is SiftingAppender?

19, 13 · Java Zone · Interview. One novel feature of Logback is SiftingAppender (JavaDoc). In short it's a proxy appender that creates one child appender per each unique value of a given runtime property. Typically this property is taken from MDC.


1 Answers

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.

like image 140
tafoo85 Avatar answered Oct 14 '22 09:10

tafoo85