<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>