Hello,<br>I just tried the example given for variable substitution in the FAQ with logback 1.0.0: <br><a href="http://logback.qos.ch/faq.html#sharedConfiguration">http://logback.qos.ch/faq.html#sharedConfiguration</a><br>And it seems the "context.reset();" line is not in the right place.<br>
<br>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()):<br>--BEGIN CODE--<br> LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); <br>
// context.reset(); // This works!<br> // property of the LoggerContext <br> context.putProperty("application-name", "killerapp"); <br> JoranConfigurator jc = new JoranConfigurator(); <br>
jc.setContext(context);<br> context.reset(); // override default configuration. This does not work (no variable substitution)!<br> try {<br> jc.doConfigure(Test.class.getResourceAsStream("/logback.xml"));<br>
} catch (JoranException e1) {<br> throw new RuntimeException(e1);<br> }<br> <br> Appender<ILoggingEvent> appender = context.getLogger("mylogger").getAppender("FILE");<br>
String filename = ((RollingFileAppender<ILoggingEvent>) appender).getFile();<br> System.out.println("filename = " + filename);<br>--END CODE--<br><br>--OUTPUT--<br>
filename = d:/users/logs/application-name_IS_UNDEFINED_error.log<br>
--END OUTPUT--<br><br>Now, if I uncomment line 2: "// context.reset(); // This works!" <br>and comment out " context.reset(); // override default configuration...", I get what I want:<br>--OUTPUT--<br>
filename = d:/users/logs/killerapp_error.log<br>--END OUTPUT--<br><br>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.<br>
<br>Am I correct? In which case, the FAQ should be fixed accordingly<br><br>Thanks.<br>