
Andy, Thank you for your message. I think the following test reproduces the bug you have encountered. @Test public void levelResetTest() { LoggerContext loggerContext = new LoggerContext(); Logger root = loggerContext.getLogger(LoggerContext.ROOT_NAME); root.setLevel(Level.TRACE); assertTrue(root.isTraceEnabled()); loggerContext.reset(); assertFalse(root.isTraceEnabled()); <-- assertion fails assertTrue(root.isDebugEnabled()); } If so, could you please enter a jira issue at http://jira.qos.ch ? Many thanks in advance, Andy Ruch wrote:
Hello,
I'm using SLF4J 1.5.6 and Logback 0.9.15.
I'm wanting to reconfigure Logback in my code, but I think I've found a bug. I've copied the following code from the documentation for how to reconfigure Logback.
// assume SLF4J is bound to logback in the current environment LoggerContext lc = ( LoggerContext ) LoggerFactory.getILoggerFactory();
try { JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext( lc ); // the context was probably already configured by default configuration // rules lc.reset(); configurator.doConfigure( url ); } catch ( JoranException je ) { je.printStackTrace(); } StatusPrinter.printInCaseOfErrorsOrWarnings( lc );
This works fine, except for when my new root logger level is DEBUG. If that is the case, I receive trace messages also. I have tracked the issue down to ch.qos.logback.classic.Logger. When localLevelReset() is called, the effectiveLevelInt is set to DEBUG_INT = 10. If it is the root logger, the level is also set to DEBUG. When the logger is being reconfigured, setLevel() is called with newLevel = DEBUG. Because level == newLevel, nothing happens and the method returns. However, effectiveLevelInt is never being set to ch.qos.logback.classic.Level.DEBUG_INT = 10000. When a TRACE log message is then evaluated, it is sent through because the effectiveLevelInt is still 10, even though Level should be DEBUG.
-- Ceki Gülcü Logback: The reliable, generic, fast and flexible logging framework for Java. http://logback.qos.ch