logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1396675 - in /logging/log4j/log4j2/trunk/api/src: main/java/org/apache/logging/log4j/LogManager.java test/java/org/apache/logging/log4j/LoggerTest.java
Date Wed, 10 Oct 2012 16:29:56 GMT
Author: ggregory
Date: Wed Oct 10 16:29:55 2012
New Revision: 1396675

URL: http://svn.apache.org/viewvc?rev=1396675&view=rev
Log:
Add new API: org.apache.logging.log4j.LogManager.getLogger(Object).

Modified:
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/LogManager.java
    logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/LoggerTest.java

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/LogManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/LogManager.java?rev=1396675&r1=1396674&r2=1396675&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/LogManager.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/LogManager.java
Wed Oct 10 16:29:55 2012
@@ -53,7 +53,6 @@ public class LogManager {
     protected LogManager() {
     }
 
-
     /**
      * Scans the classpath to find all logging implementation. Currently, only one will
      * be used but this could be extended to allow multiple implementations to be used.
@@ -125,7 +124,6 @@ public class LogManager {
      * @return The Logger.
      */
     public static Logger getLogger(String name) {
-
         return factory.getContext(LogManager.class.getName(), null, false).getLogger(name);
     }
 
@@ -135,7 +133,16 @@ public class LogManager {
      * @return The Logger.
      */
     public static Logger getLogger(Class<?> clazz) {
-        return factory.getContext(LogManager.class.getName(), null, false).getLogger(clazz.getName());
+        return getLogger(clazz != null ? clazz.getName() : null);
+    }
+
+    /**
+     * Returns a Logger using the fully qualified class name of the value as the Logger name.
+     * @param value The value whose class name should be used as the Logger name.
+     * @return The Logger.
+     */
+    public static Logger getLogger(Object value) {
+        return getLogger(value != null ? value.getClass() : null);
     }
 
     /**
@@ -146,7 +153,6 @@ public class LogManager {
      * @return The Logger.
      */
     protected static Logger getLogger(String fqcn, String name) {
-
         return factory.getContext(fqcn, null, false).getLogger(name);
     }
 

Modified: logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/LoggerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/LoggerTest.java?rev=1396675&r1=1396674&r2=1396675&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/LoggerTest.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/test/java/org/apache/logging/log4j/LoggerTest.java
Wed Oct 10 16:29:55 2012
@@ -17,6 +17,7 @@
 package org.apache.logging.log4j;
 
 import org.apache.logging.log4j.message.StructuredDataMessage;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -135,4 +136,27 @@ public class LoggerTest {
         Logger classLogger = LogManager.getLogger(LoggerTest.class);
         assertNotNull(classLogger);
     }
+
+    public void getLoggerByNullClass() {
+        // Returns a SimpleLogger
+        Assert.assertNotNull(LogManager.getLogger((Class<?>) null));
+    }
+
+    public void getLoggerByNullObject() {
+        // Returns a SimpleLogger
+        Assert.assertNotNull(LogManager.getLogger((Object) null));
+    }
+
+    @Test
+    public void getLoggerByNullString() {
+        // Returns a SimpleLogger
+        Assert.assertNotNull(LogManager.getLogger((String) null));
+    }
+
+    @Test
+    public void getLoggerByObject() {
+        Logger classLogger = LogManager.getLogger(this);
+        assertNotNull(classLogger);
+        assertEquals(classLogger, LogManager.getLogger(LoggerTest.class));
+    }
 }



Mime
View raw message