[
https://issues.apache.org/jira/browse/LOG4J2-3646?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17654398#comment-17654398
]
Matthew Firth commented on LOG4J2-3646:
---------------------------------------
[~pkarwasz] - creating a custom LogManager that mimics JULI's hierarchy was the
hard bit. I'll keep at it :) I'm also thinking of creating a separate PR
and tests for a feature that lets one set a "removeHandlersForRootLogger"
property in logging.properties, much like one can set "propagateLevels" that
way.
> 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
> Priority: Minor
>
> Related to the issue I filed in the Tomcat Bugzilla:
> [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 doesn'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)