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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With