Speed up log4j-slf4j-impl LoggerContext lookup.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/1ad7be8a
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/1ad7be8a
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/1ad7be8a

Branch: refs/heads/master
Commit: 1ad7be8ad5c6abec45d91657dba5a6166c0fe141
Parents: c91070a
Author: Matt Sicker <[email protected]>
Authored: Sat Oct 4 10:48:10 2014 -0500
Committer: Matt Sicker <[email protected]>
Committed: Sat Oct 4 10:48:10 2014 -0500

----------------------------------------------------------------------
 .../logging/slf4j/Log4jLoggerFactory.java       | 22 ++------------------
 1 file changed, 2 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1ad7be8a/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jLoggerFactory.java
----------------------------------------------------------------------
diff --git 
a/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jLoggerFactory.java
 
b/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jLoggerFactory.java
index 3c82b87..a5ff7af 100644
--- 
a/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jLoggerFactory.java
+++ 
b/log4j-slf4j-impl/src/main/java/org/apache/logging/slf4j/Log4jLoggerFactory.java
@@ -20,6 +20,7 @@ import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.spi.AbstractLoggerAdapter;
 import org.apache.logging.log4j.spi.ExtendedLogger;
 import org.apache.logging.log4j.spi.LoggerContext;
+import org.apache.logging.log4j.util.ReflectionUtil;
 import org.slf4j.ILoggerFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -40,26 +41,7 @@ public class Log4jLoggerFactory extends 
AbstractLoggerAdapter<Logger> implements
 
     @Override
     protected LoggerContext getContext() {
-        final Throwable t = new Throwable();
-        boolean next = false;
-        boolean pkg = false;
-        String fqcn = LoggerFactory.class.getName();
-        // TODO: update with LOG4J2-809
-        for (final StackTraceElement element : t.getStackTrace()) {
-            if (FQCN.equals(element.getClassName())) {
-                next = true;
-                continue;
-            }
-            if (next && element.getClassName().startsWith(PACKAGE)) {
-                fqcn = element.getClassName();
-                pkg = true;
-                continue;
-            }
-            if (pkg) {
-                break;
-            }
-        }
-        return PrivateManager.getContext(fqcn);
+        return PrivateManager.getContext(ReflectionUtil.getCallerClass(FQCN, 
PACKAGE).getName());
     }
 
     /**

Reply via email to