You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2014/09/08 00:38:41 UTC

[02/32] git commit: Update slf4j binding to use ELCR.

Update slf4j binding to use ELCR.


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

Branch: refs/heads/master
Commit: c2c67cc08777dfc942e7d67d308ab07358312372
Parents: 24b0598
Author: Matt Sicker <ma...@apache.org>
Authored: Mon Sep 1 13:38:34 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Mon Sep 1 13:38:34 2014 -0500

----------------------------------------------------------------------
 .../logging/slf4j/Log4jLoggerFactory.java       | 37 ++++----------------
 1 file changed, 7 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c2c67cc0/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 47edeb4..2878618 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
@@ -16,14 +16,10 @@
  */
 package org.apache.logging.slf4j;
 
-import java.util.Map;
-import java.util.WeakHashMap;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
 import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.spi.LoggerContext;
+import org.apache.logging.log4j.spi.AbstractExternalLoggerContextRegistry;
 import org.apache.logging.log4j.spi.ExtendedLogger;
+import org.apache.logging.log4j.spi.LoggerContext;
 import org.slf4j.ILoggerFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -31,38 +27,19 @@ import org.slf4j.LoggerFactory;
 /**
  *
  */
-public class Log4jLoggerFactory implements ILoggerFactory {
+public class Log4jLoggerFactory extends AbstractExternalLoggerContextRegistry<Logger> implements ILoggerFactory {
 
     private static final String FQCN = Log4jLoggerFactory.class.getName();
     private static final String PACKAGE = "org.slf4j";
 
-    private final Map<LoggerContext, ConcurrentMap<String, Logger>> contextMap =
-        new WeakHashMap<LoggerContext, ConcurrentMap<String, Logger>>();
-
     @Override
-    public Logger getLogger(final String name) {
-        final LoggerContext context = getContext();
-        final ConcurrentMap<String, Logger> loggers = getLoggersMap(context);
-
-        if (loggers.containsKey(name)) {
-            return loggers.get(name);
-        }
+    public Logger newLogger(final String name, final LoggerContext context) {
         final String key = Logger.ROOT_LOGGER_NAME.equals(name) ? LogManager.ROOT_LOGGER_NAME : name;
-        loggers.putIfAbsent(name, new Log4jLogger(context.getLogger(key), name));
-        return loggers.get(name);
+        return new Log4jLogger(context.getLogger(key), name);
     }
 
-    private ConcurrentMap<String, Logger> getLoggersMap(final LoggerContext context) {
-        synchronized (contextMap) {
-            ConcurrentMap<String, Logger> map = contextMap.get(context);
-            if (map == null) {
-                map = new ConcurrentHashMap<String, Logger>();
-                contextMap.put(context, map);
-            }
-            return map;
-        }
-    }
-    private LoggerContext getContext() {
+    @Override
+    public LoggerContext getContext() {
         final Throwable t = new Throwable();
         boolean next = false;
         boolean pkg = false;