You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2016/03/31 05:36:10 UTC

logging-log4j2 git commit: [LOG4J2-1336] LoggerFactory in 1.2 API module is not compatible with 1.2.

Repository: logging-log4j2
Updated Branches:
  refs/heads/master c78333ef0 -> 9e4b9f4e6


[LOG4J2-1336] LoggerFactory in 1.2 API module is not compatible with
1.2.

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

Branch: refs/heads/master
Commit: 9e4b9f4e686c26f76e0a6a6b3e6361e26120e8ce
Parents: c78333e
Author: ggregory <gg...@apache.org>
Authored: Wed Mar 30 20:36:06 2016 -0700
Committer: ggregory <gg...@apache.org>
Committed: Wed Mar 30 20:36:06 2016 -0700

----------------------------------------------------------------------
 .../main/java/org/apache/log4j/Category.java    | 18 ++++++++--
 .../org/apache/log4j/spi/LoggerFactory.java     |  9 ++---
 .../apache/log4j/spi/LoggerFactoryBridge.java   | 36 ++++++++++++++++++++
 src/changes/changes.xml                         |  3 ++
 4 files changed, 59 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9e4b9f4e/log4j-1.2-api/src/main/java/org/apache/log4j/Category.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/Category.java b/log4j-1.2-api/src/main/java/org/apache/log4j/Category.java
index aae8850..e3e68a0 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/Category.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/Category.java
@@ -25,6 +25,7 @@ import java.util.concurrent.ConcurrentMap;
 
 import org.apache.log4j.helpers.NullEnumeration;
 import org.apache.log4j.spi.LoggerFactory;
+import org.apache.log4j.spi.LoggerFactoryBridge;
 import org.apache.log4j.spi.LoggingEvent;
 import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.util.NameUtil;
@@ -39,7 +40,7 @@ import org.apache.logging.log4j.util.Strings;
  */
 public class Category {
 
-    private static LoggerFactory loggerFactory = new PrivateFactory();
+    private static LoggerFactoryBridge loggerFactory = new PrivateFactory();
 
     private static final Map<LoggerContext, ConcurrentMap<String, Logger>> CONTEXT_MAP =
         new WeakHashMap<>();
@@ -88,6 +89,17 @@ public class Category {
         if (logger != null) {
             return logger;
         }
+        logger = factory.makeNewLoggerInstance(name);
+        final Logger prev = loggers.putIfAbsent(name, logger);
+        return prev == null ? logger : prev;
+    }
+
+    static Logger getInstance(final LoggerContext context, final String name, final LoggerFactoryBridge factory) {
+        final ConcurrentMap<String, Logger> loggers = getLoggersMap(context);
+        Logger logger = loggers.get(name);
+        if (logger != null) {
+            return logger;
+        }
         logger = factory.makeNewLoggerInstance(context, name);
         final Logger prev = loggers.putIfAbsent(name, logger);
         return prev == null ? logger : prev;
@@ -444,10 +456,10 @@ public class Category {
     /**
      * Private logger factory.
      */
-    private static class PrivateFactory implements LoggerFactory {
+    private static class PrivateFactory implements LoggerFactoryBridge {
 
         @Override
-        public Logger makeNewLoggerInstance(final LoggerContext context, final String name) {
+        public Logger makeNewLoggerInstance(org.apache.logging.log4j.core.LoggerContext context, final String name) {
             return new Logger(context, name);
         }
     }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9e4b9f4e/log4j-1.2-api/src/main/java/org/apache/log4j/spi/LoggerFactory.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/spi/LoggerFactory.java b/log4j-1.2-api/src/main/java/org/apache/log4j/spi/LoggerFactory.java
index d79aea2..e2f3708 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/spi/LoggerFactory.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/spi/LoggerFactory.java
@@ -20,13 +20,14 @@ import org.apache.log4j.Logger;
 
 /**
  *
- * Implement this interface to create new instances of Logger or
- * a sub-class of Logger.
+ * Implement this interface to create new instances of Logger or a sub-class of Logger.
  *
- * <p>See <code>examples/subclass/MyLogger.java</code> for an example.
+ * <p>
+ * See <code>examples/subclass/MyLogger.java</code> for an example.
+ * </p>
  */
 public interface LoggerFactory {
 
-  Logger makeNewLoggerInstance(org.apache.logging.log4j.core.LoggerContext context, String name);
+    Logger makeNewLoggerInstance(String name);
 
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9e4b9f4e/log4j-1.2-api/src/main/java/org/apache/log4j/spi/LoggerFactoryBridge.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/spi/LoggerFactoryBridge.java b/log4j-1.2-api/src/main/java/org/apache/log4j/spi/LoggerFactoryBridge.java
new file mode 100644
index 0000000..bd14ab3
--- /dev/null
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/spi/LoggerFactoryBridge.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.log4j.spi;
+
+import org.apache.log4j.Logger;
+
+/**
+ *
+ * Implement this interface to create new instances of Logger or a sub-class of Logger when instantiating with specific
+ * context.
+ *
+ * <p>
+ * See <code>examples/subclass/MyLogger.java</code> for an example.
+ * </p>
+ * 
+ * @since 2.6
+ */
+public interface LoggerFactoryBridge {
+
+    Logger makeNewLoggerInstance(org.apache.logging.log4j.core.LoggerContext context, String name);
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/9e4b9f4e/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index eb204e4..94ed516 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -24,6 +24,9 @@
   </properties>
   <body>
     <release version="2.6" date="2016-MM-DD" description="GA Release 2.6">
+      <action issue="LOG4J2-1336" dev="ggregory" type="fix" due-to="Zbynek Vyskovsky">
+        LoggerFactory in 1.2 API module is not compatible with 1.2.
+      </action>
       <action issue="LOG4J2-1339" dev="rpopma" type="fix">
         AsyncLogger performance optimization: avoid calling instanceof TimestampMessage in hot path.
       </action>