[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
Hello,
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 =
(LoggerContext)LoggerFactory.getILoggerFactory();
for (Logger l : ctx.getLoggerList()) {
ch.qos.logback.classic.Logger log
=(ch.qos.logback.classic.Logger) l;
Iterator<Appender<ILoggingEvent>> it =
log.iteratorForAppenders();
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
it.
Thanks in advance!
Regards,
Noah
More information about the Logback-user
mailing list