This is an automated email from the ASF dual-hosted git repository.

ckozak pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


The following commit(s) were added to refs/heads/master by this push:
     new c40db0f  LOG4J2-2739: Fix erroneous log4j-jul recursive logger 
detection
c40db0f is described below

commit c40db0f8e04d8ff301f0f57d77a3e0a3bdc078f0
Author: Carter Kozak <[email protected]>
AuthorDate: Tue Dec 24 11:06:37 2019 -0500

    LOG4J2-2739: Fix erroneous log4j-jul recursive logger detection
    
    The new implementation takes the requested logger name into account.
    Invocations of jul LogManager.getLogger may become slightly less
    performant due to string hashing and allocaiton overhead, but in
    these scenarios it's best to reuse logger instances.
---
 .../org/apache/logging/log4j/jul/LogManager.java     | 20 ++++++++++++--------
 src/changes/changes.xml                              |  3 +++
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git 
a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LogManager.java 
b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LogManager.java
index ecfdee6..6225b4c 100644
--- a/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LogManager.java
+++ b/log4j-jul/src/main/java/org/apache/logging/log4j/jul/LogManager.java
@@ -18,6 +18,8 @@ package org.apache.logging.log4j.jul;
 
 import java.util.Collections;
 import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
 import java.util.logging.Logger;
 
 import org.apache.logging.log4j.LoggingException;
@@ -41,7 +43,8 @@ public class LogManager extends java.util.logging.LogManager {
 
     private static final org.apache.logging.log4j.Logger LOGGER = 
StatusLogger.getLogger();
     private final AbstractLoggerAdapter loggerAdapter;
-    private final ThreadLocal<Boolean> recursive = ThreadLocal.withInitial(() 
-> Boolean.FALSE);
+    // Contains the set of logger names that are actively being requested 
using getLogger.
+    private final ThreadLocal<Set<String>> recursive = 
ThreadLocal.withInitial(HashSet::new);
 
     public LogManager() {
         super();
@@ -87,16 +90,17 @@ public class LogManager extends 
java.util.logging.LogManager {
     @Override
     public Logger getLogger(final String name) {
         LOGGER.trace("Call to LogManager.getLogger({})", name);
-        if (recursive.get()) {
+        Set<String> activeRequests = recursive.get();
+        if (activeRequests.add(name)) {
+            try {
+                return loggerAdapter.getLogger(name);
+            } finally {
+                activeRequests.remove(name);
+            }
+        } else {
             LOGGER.warn("Recursive call to getLogger for {} ignored.", name);
             return new NoOpLogger(name);
         }
-        recursive.set(Boolean.TRUE);
-        try {
-            return loggerAdapter.getLogger(name);
-        } finally {
-            recursive.set(Boolean.FALSE);
-        }
     }
 
     @Override
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 10c2340..44b0f23 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -181,6 +181,9 @@
       <action issue="LOG4J2-2747" dev="ckozak" type="fix">
         Fix a memory leak using fully asynchronous logging when the queue is 
full using the 'discard' asynchronous queue full strategy.
       </action>
+      <action issue="LOG4J2-2739" dev="ckozak" type="fix">
+        Fix erroneous log4j-jul recursive logger detection resulting in some 
no-op JUL loggers and 'WARN Recursive call to getLogger' being reported by the 
status logger.
+      </action>
     </release>
     <release version="2.13.0" date="2019-12-11" description="GA Release 
2.13.0">
       <action issue="LOG4J2-2058" dev="rgoers" type="fix">

Reply via email to