logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1479236 - in /logging/log4j/log4j2/trunk: core/src/main/java/org/apache/logging/log4j/core/Logger.java log4j12-api/src/test/java/org/apache/log4j/LoggingTest.java log4j12-api/src/test/resources/log4j2-config.xml src/changes/changes.xml
Date Sun, 05 May 2013 05:11:50 GMT
Author: rgoers
Date: Sun May  5 05:11:49 2013
New Revision: 1479236

URL: http://svn.apache.org/r1479236
Log:
LOG4J2-231 - Logger.getParent() was not returning the correct Logger.

Added:
    logging/log4j/log4j2/trunk/log4j12-api/src/test/java/org/apache/log4j/LoggingTest.java
    logging/log4j/log4j2/trunk/log4j12-api/src/test/resources/log4j2-config.xml
Modified:
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/Logger.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/Logger.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/Logger.java?rev=1479236&r1=1479235&r2=1479236&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/Logger.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/Logger.java
Sun May  5 05:11:49 2013
@@ -59,18 +59,20 @@ public class Logger extends AbstractLogg
     }
 
     /**
+     * This method is only used for 1.x compatibility.
      * Returns the parent of this Logger. If it doesn't already exist return a temporary
Logger.
      * @return The parent Logger.
      */
     public Logger getParent() {
-        final LoggerConfig lc = config.loggerConfig.getParent();
+        LoggerConfig lc = config.loggerConfig.getName().equals(getName()) ? config.loggerConfig.getParent()
:
+            config.loggerConfig;
         if (lc == null) {
             return null;
         }
         if (context.hasLogger(lc.getName())) {
-            return context.getLogger(getName(), getMessageFactory());
+            return context.getLogger(lc.getName(), getMessageFactory());
         }
-        return new Logger(context, getName(), this.getMessageFactory());
+        return new Logger(context, lc.getName(), this.getMessageFactory());
     }
 
     /**

Added: logging/log4j/log4j2/trunk/log4j12-api/src/test/java/org/apache/log4j/LoggingTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j12-api/src/test/java/org/apache/log4j/LoggingTest.java?rev=1479236&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j12-api/src/test/java/org/apache/log4j/LoggingTest.java
(added)
+++ logging/log4j/log4j2/trunk/log4j12-api/src/test/java/org/apache/log4j/LoggingTest.java
Sun May  5 05:11:49 2013
@@ -0,0 +1,67 @@
+/*
+ * 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;
+
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.test.appender.ListAppender;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ *
+ */
+public class LoggingTest {
+
+    private static final String CONFIG = "log4j2-config.xml";
+    private static Configuration config;
+    private static ListAppender<String> app;
+    private static LoggerContext ctx;
+
+    @BeforeClass
+    public static void setupClass() {
+        ctx = Configurator.initialize("Test1", null, CONFIG);
+    }
+
+    @AfterClass
+    public static void cleanupClass() {
+        ctx.stop();
+        StatusLogger.getLogger().reset();
+    }
+
+    @Before
+    @SuppressWarnings("unchecked")
+    public void before() {
+        config = ctx.getConfiguration();
+    }
+
+    @Test
+    public void testParent() {
+        final Logger a = Logger.getLogger("org.apache.test.logging.Test");
+        Category parent = a.getParent();
+        assertNotNull("No parent Logger", parent);
+        assertTrue("Incorrect parent logger", parent.getName().equals("org.apache.test.logging"));
+    }
+
+}

Added: logging/log4j/log4j2/trunk/log4j12-api/src/test/resources/log4j2-config.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j12-api/src/test/resources/log4j2-config.xml?rev=1479236&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j12-api/src/test/resources/log4j2-config.xml (added)
+++ logging/log4j/log4j2/trunk/log4j12-api/src/test/resources/log4j2-config.xml Sun May  5
05:11:49 2013
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+
+-->
+<configuration name="ConfigTest" status="error" packages="org.apache.logging.log4j.test"
+               monitorInterval="5">
+  <appenders>
+    <Console name="STDOUT">
+      <PatternLayout pattern="%m%n"/>
+    </Console>
+    <List name="List">
+    </List>
+  </appenders>
+  <loggers>
+    <logger name="org.apache.test.logging" level="debug" additivity="false">
+      <appender-ref ref="List"/>
+    </logger>
+    <logger name="org.apache.test" level="trace" additivity="false">
+      <appender-ref ref="List"/>
+    </logger>
+    <root level="error">
+      <appender-ref ref="STDOUT"/>
+    </root>
+  </loggers>
+</configuration>
\ No newline at end of file

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1479236&r1=1479235&r2=1479236&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Sun May  5 05:11:49 2013
@@ -23,6 +23,9 @@
 
   <body>
     <release version="2.0-beta6" date="@TBD@" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-231" dev="rgoers" type="fix">
+        Logger.getParent() was not returning the correct Logger.
+      </action>
       <action issue="LOG4J2-201" dev="rgoers" type="fix">
         Renamed Plugin annotation attribute from "type" to "category".
       </action>



Mime
View raw message