[ https://issues.apache.org/jira/browse/LOG4J2-2025?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16591836#comment-16591836 ]
ASF GitHub Bot commented on LOG4J2-2025: ---------------------------------------- Github user rgoers commented on a diff in the pull request: https://github.com/apache/logging-log4j2/pull/213#discussion_r212672416 --- Diff: log4j-jul/src/site/markdown/index.md --- @@ -74,3 +74,29 @@ Java Level | Log4j Level [`FINER`](http://docs.oracle.com/javase/6/docs/api/java/util/logging/Level.html#FINER) | `TRACE` [`FINEST`](http://docs.oracle.com/javase/6/docs/api/java/util/logging/Level.html#FINEST) | [`FINEST`](apidocs/org/apache/logging/log4j/jul/LevelTranslator.html#FINEST) [`ALL`](http://docs.oracle.com/javase/6/docs/api/java/util/logging/Level.html#ALL) | `ALL` + + +# Log4j JDK Logging Bridge + +The LogManager is not always useable because you have to set a JVM wide effective system +property - e.g. in web servers this is not possible if you are not the administrator. + +The [`Log4jBridgeHandler`](apidocs/org/apache/logging/log4j/jul/Log4jBridgeHandler.html) is an +alternative that can be declaratively used via `logging.properties`. +It is less performant than the LogManager but still okay to use. --- End diff -- This should also note that logging methods are subject to filtering by BOTH java.util.logging and log4j 2. > Support Tomcat JULI's per-webapp JUL logging by implementing > java.util.logging.Handler > -------------------------------------------------------------------------------------- > > Key: LOG4J2-2025 > URL: https://issues.apache.org/jira/browse/LOG4J2-2025 > Project: Log4j 2 > Issue Type: Improvement > Components: JUL adapter > Affects Versions: 2.8.2 > Environment: Tomcat 8.5.20, Oracle Java 1.8.0_144 > Reporter: Ibrahim M. Ghazal > Assignee: Ralph Goers > Priority: Minor > Fix For: 2.11.2 > > > On most servlet containers, the only way to redirect JUL calls to Log4j is by > setting the > {{java.util.logging.manager=org.apache.logging.log4j.jul.LogManager}} system > property *globally*. This often breaks the native logging of the container, > and could also break other apps on the same container do not use Log4j 2. > This also requires changing the container's settings and cannot be expressed > in the app itself. > Another approach (used by slf4j) is to implement > {{java.util.logging.Handler}} and then install this handler at the root > logger, either programmatically by calling > {{LogManager.getLogManager().getLogger("").addHandler(...)}} or by changing > logging.properties at the JRE level. This also breaks the container's native > logging and other apps, but in different ways than LogManager. I do not > advocate this approach, but it's useful to know about it as a background for > this feature request. > (tl;dr: It's impossible to reliably redirect JUL from a webapp without > creating a mess). > Thankfully, Tomcat has a solution for this: Tomcat > [JULI|https://tomcat.apache.org/tomcat-8.5-doc/logging.html] allows > per-webapp configuration by adding a {{WEB-INF/classes/logging.properties}} > file with {{handlers=some.custom.Handler}} inside it. This will redirect JUL > calls from this webapp (and this webapp only) to that handler, and that > handler then can redirect to Log4j. > In short: Add a {{java.util.logging.Handler}} implementation that redirects > to Log4j so that webapps can use Tomcat's per-webapp configuration and avoid > the JUL mess. -- This message was sent by Atlassian JIRA (v7.6.3#76005)