<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Take this with a pinch of salt, but my understanding is that <span style="font-family: 'courier new', monospace; ">SLF4JBridgeHandler.install() </span>simply adds a new handler to the root logger which sends events to SLF4J. Unless the root JUL logger (and any others with configured levels) is set to a low enough level they won't reach the handler.<div><br></div><div>This is why the jul-to-slf4j bridge is quite inefficient - all JUL logging events have to be constructed and sent to the handler and only then are they filtered by SLF4J. See [1] for details.</div><div><br></div><div>Logback has a LevelChangePropagator[2] which reacts to changes in the enabled Logback level and changes the appropriate JUL Logger's level to keep it in synch, which might you a pattern to copy in Log4J2 if Log4J2 exposes the necessary extension points to listen for logger level changes.</div><div><br></div><div>Rob</div><div><br></div><div>[1]<a href="http://www.slf4j.org/legacy.html#jul-to-slf4j">http://www.slf4j.org/legacy.html#jul-to-slf4j</a></div><div>[2]<a href="http://logback.qos.ch/manual/configuration.html#LevelChangePropagator">http://logback.qos.ch/manual/configuration.html#LevelChangePropagator</a></div><div><br></div><div><br></div><div><br><div><div>On 10 Sep 2013, at 16:55, Guus der Kinderen <<a href="mailto:guus.der.kinderen@gmail.com">guus.der.kinderen@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr"><div class="gmail_quote"><div dir="ltr"><div><div><div><div><div><div><div><div><div><div>Hello,<br><br></div>Today, I've ran into a snag using the jul-to-slf4j SLF4JBridgeHandler (distribution version 1.7.5). Although I worked around the issue, I wonder if I'm doing something wrong, or if I hit a bug in the implementation.<br>
<br></div>The problem popped up during a refactoring of a project. In this project, I switched from using version 1.x of the Jersey framework to version 2.x. Both versions use JUL, which is why the SLF4JBridge was already in place (and doing its magic without incident), using the following two lines in a ContextListener<br>
<br><span style="font-family:courier new,monospace">SLF4JBridgeHandler.removeHandlersForRootLogger();<br>SLF4JBridgeHandler.install();<br></span><br></div>After the move was complete, I noticed that a lot less information was logged. When looking into the source code of the newly added framework, I noticed the following:<br>
<br></div>A log statement that was generated using the snippet below got logged just fine:<br><span style="font-family:courier new,monospace"><br>LOGGER.info(LocalizationMessages.INIT_MSG(Version.getBuildId()));</span><br>
<br></div>However, in the same method, a different log statement was generated conditionally based on the 'isLoggable' method response:<br><span style="font-family:courier new,monospace"><br>if (LOGGER.isLoggable(Level.CONFIG)) {<br>
final StringBuilder sb;<br> /* lots of string generation */<br> LOGGER.log(Level.CONFIG, sb.toString());<br>}</span><br><br></div>The condition in the if statement evaluated to false, no matter what.<br><br></div>I remedied the problem by adding this last line to my jul-to-slf4j bridge invocation:<br>
<br><span style="font-family:courier new,monospace">SLF4JBridgeHandler.removeHandlersForRootLogger();<br>SLF4JBridgeHandler.install();<br>java.util.logging.LogManager.getLogManager().getLogger( "" ).setLevel( Level.ALL );</span><br>
<br></div>Immediately, all of the missing log statements popped up in my log files again. Changing the desired log level in my log configuration (which happens to be log4j2) also has the desired effect (as in: lower level JUL statements do not get logged).<br>
<br></div>I'm not familiar enough with all of the implementations involved to evaluate a) why my fix was needed, and b) if this fix is a proper work-around, rather than something that's likely to fail in upcoming releases of either product. I would love to get some feedback.<br>
<br>Kind regards,<br><br></div> Guus<br></div>
</div><br></div>
_______________________________________________<br>slf4j-user mailing list<br><a href="mailto:slf4j-user@qos.ch">slf4j-user@qos.ch</a><br>http://mailman.qos.ch/mailman/listinfo/slf4j-user</blockquote></div><br></div></body></html>