[logback-user] How to get the pattern of an appender of logback.xml

Noah Rebmann nrebmann at bluewin.ch
Fri Jun 24 15:43:58 CEST 2011


It seems to be possible to read the pattern of an appender out of the 
logback.xml-file. But I don't know how exactly.
We use the followin Code to get the the filepath form the appender 
(found somwhere in this mailinglist):
         String path = "";

         LoggerContext ctx = 

         for (Logger l : ctx.getLoggerList()) {
             ch.qos.logback.classic.Logger log 
=(ch.qos.logback.classic.Logger) l;
             Iterator<Appender<ILoggingEvent>> it = 

             while (it.hasNext()) {
                 Appender<ILoggingEvent> ap = it.next();

                 if (ap instanceof FileAppender<?> || ap instanceof 
RollingFileAppender<?>) {
                     FileAppender<?> fileAppender = (FileAppender<?>)ap;
                     path = fileAppender.getFile();
         return path;

Is it possible to implement a method which also gets the pattern of the 
appender out of the file? I tried different ways but somehow I don't get 

Thanks in advance!



More information about the Logback-user mailing list