Matthew Firth created LOG4J2-3646:
-------------------------------------

             Summary: Log4jBridgeHandler does not work OTB on Tomcat 10.1
                 Key: LOG4J2-3646
                 URL: https://issues.apache.org/jira/browse/LOG4J2-3646
             Project: Log4j 2
          Issue Type: Bug
          Components: JUL adapter
    Affects Versions: 2.19.0
            Reporter: Matthew Firth


 

Related to the issue I filed in the Tomcat BZ: 
[https://bz.apache.org/bugzilla/show_bug.cgi?id=66406] 

The Log4jBridgeHandler's logic to clear existing handlers on the root logger 
doesn't work in TC 10 and possibly other situations.   The result is that I get 
all log messages published twice - once to the console by JUL and then once 
again by log4j.

Log4jBridgeHandler.getJulRootLogger() assumes that the "root logger" is the one 
returned by getLogger("").   

When running TC10 with JULI (the default), that Logger actually has two parents 
- and the grand-parent Logger has the Console Handler attached to it.
Even if the Tomcat Project don't change JULI, I suggest log4j could be 
defensive and simply block parent loggers if any exist.


 
For example - ammending Log4jBridgeHandler.install() like this:
{noformat}
if (removeHandlersForRootLogger) {
   for (java.util.logging.Handler hdl : rootLogger.getHandlers()) {
     rootLogger.removeHandler(hdl);
    }
   
   if (rootLogger.getParent() != null)
     rootLogger.setUseParentHandlers(false);
   rootLogger.addHandler(new Log4jBridgeHandler(false, suffixToAppend, 
propagateLevels));
}
 
{noformat}
 
 

) 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to