[slf4j-user] how to properly activate the jul-to-slf4j bridge

Shawn Heisey slf4j at elyograg.org
Sat Sep 16 22:45:37 CEST 2023


I am a committer on the Apache Solr project.

The primary dependency that Solr has is Lucene, and there are a LOT more 
dependencies.

The lucene-core jar has zero dependencies, and their intent is to keep 
it that way.  So when they needed to implement logging, they did so 
using java.util.logging.

Solr uses slf4j for logging.  The binary package includes Jetty, and 
logging jars are in jetty's lib/ext folder.  The ultimate logging 
destination in the binary package is log4j2.  Before the 7.4 version of 
Solr, it used log4j1 as the ultimate destination -- long after log4j1 
reached end of life.

For a very long time Solr has had slf4j bridges in place to handle 
anything logged by its many dependencies.  The current version of Solr 
uses the JCL bridge and the JUL bridge.  Bridging for log4j1 is handled 
by log4j2.

One of my fellow developers noticed that Lucene's logs were not getting 
logged with the Solr logs.  So they added log4j's JUL bridge and a 
system property to use it.  This created a problem when another feature 
was activated.  See this issue:

https://issues.apache.org/jira/browse/SOLR-16976

I have learned that although Solr does include the jul-to-slf4j jar, 
this bridge does not get activated just by having the jar in the 
classpath.  It must be activated either in the code or in the JUL config.

So I tried to add these lines to Solr's entry point, a class called 
SolrDispatchFilter:

SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();

Solr has an admin UI with a page that shows all the loggers that exist 
for log4j2 and allows the levels for each logger to be changed on the 
fly.  With the log4j bridge for JUL, this page has entries for Lucene 
classes, but I have not been able to get those to show up with the slf4j 
bridge.

I also tried configuring a logging.properties file with the following 
line in it, and setting the system property for that config to be used:

handlers = org.slf4j.bridge.SLF4JBridgeHandler

What do I need to do to properly activate the jul-to-slf4j bridge in 
Solr?  How can I tell when/if it is successful?

Thanks,
Shawn



More information about the slf4j-user mailing list