[logback-user] Documentation/FAQ - Typo/error in variable substitution example?
Cyril DANGERVILLE
darthvader7777 at gmail.com
Wed Dec 7 19:36:59 CET 2011
Hello,
I just tried the example given for variable substitution in the FAQ with
logback 1.0.0:
http://logback.qos.ch/faq.html#sharedConfiguration
And it seems the "context.reset();" line is not in the right place.
If I use the same code as in the example, I got this (I added a few lines
of code at the end to print the filename that should be changed after
doConfigure()):
--BEGIN CODE--
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
// context.reset(); // This works!
// property of the LoggerContext
context.putProperty("application-name", "killerapp");
JoranConfigurator jc = new JoranConfigurator();
jc.setContext(context);
context.reset(); // override default configuration. This does not
work (no variable substitution)!
try {
jc.doConfigure(Test.class.getResourceAsStream("/logback.xml"));
} catch (JoranException e1) {
throw new RuntimeException(e1);
}
Appender<ILoggingEvent> appender =
context.getLogger("mylogger").getAppender("FILE");
String filename = ((RollingFileAppender<ILoggingEvent>)
appender).getFile();
System.out.println("filename = " + filename);
--END CODE--
--OUTPUT--
filename = d:/users/logs/application-name_IS_UNDEFINED_error.log
--END OUTPUT--
Now, if I uncomment line 2: "// context.reset(); // This works!"
and comment out " context.reset(); // override default configuration...", I
get what I want:
--OUTPUT--
filename = d:/users/logs/killerapp_error.log
--END OUTPUT--
In short, it makes a more sense and it works if context.reset() is done
before setting the property. Otherwise, I guess the property map is cleared
with the reset if done after.
Am I correct? In which case, the FAQ should be fixed accordingly
Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20111207/a8af73a4/attachment.html>
More information about the Logback-user
mailing list