logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1496682 - /logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/LogManager.java
Date Wed, 26 Jun 2013 00:16:05 GMT
Author: ggregory
Date: Wed Jun 26 00:16:05 2013
New Revision: 1496682

URL: http://svn.apache.org/r1496682
Log:
Use ternary expression consistently in the various getLogger APIs to end up calling an underlying
API with the same type. This seems clearer IMO than the 'if (value == null) { return an expr
} else { return another expr}'.

Modified:
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/LogManager.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=1496682&r1=1496681&r2=1496682&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 Jun 26 00:16:05 2013
@@ -247,10 +247,7 @@ public class LogManager {
      * @see StringFormatterMessageFactory
      */
     public static Logger getFormatterLogger(final Class<?> clazz) {
-        if (clazz != null) {
-            return getLogger(clazz, StringFormatterMessageFactory.INSTANCE);
-        }
-        return getLogger(getClassName(2), StringFormatterMessageFactory.INSTANCE);
+        return getLogger(clazz != null ? clazz.getName() : getClassName(2), StringFormatterMessageFactory.INSTANCE);
     }
 
     /**
@@ -280,10 +277,8 @@ public class LogManager {
      * @see StringFormatterMessageFactory
      */
     public static Logger getFormatterLogger(final Object value) {
-        if (value != null) {
-            return getLogger(value, StringFormatterMessageFactory.INSTANCE);
-        }
-        return getLogger(getClassName(2), StringFormatterMessageFactory.INSTANCE);
+        return getLogger(value != null ? value.getClass().getName() : getClassName(2),
+                StringFormatterMessageFactory.INSTANCE);
     }
 
     /**
@@ -312,10 +307,7 @@ public class LogManager {
      * @see StringFormatterMessageFactory
      */
     public static Logger getFormatterLogger(final String name) {
-        if (name != null) {
-            return getLogger(name, StringFormatterMessageFactory.INSTANCE);
-        }
-        return getLogger(getClassName(2), StringFormatterMessageFactory.INSTANCE);
+        return getLogger(name != null ? name : getClassName(2), StringFormatterMessageFactory.INSTANCE);
     }
 
     /**
@@ -347,10 +339,7 @@ public class LogManager {
      * @return The Logger.
      */
     public static Logger getLogger(final Object value) {
-        if (value != null) {
-            return getLogger(value.getClass().getName());
-        }
-        return getLogger(getClassName(2));
+        return getLogger(value != null ? value.getClass().getName() : getClassName(2));
     }
 
     /**
@@ -362,10 +351,7 @@ public class LogManager {
      * @return The Logger.
      */
     public static Logger getLogger(final Object value, final MessageFactory messageFactory)
{
-        if (value != null) {
-            return getLogger(value.getClass().getName(), messageFactory);
-        }
-        return getLogger(getClassName(2), messageFactory);
+        return getLogger(value != null ? value.getClass().getName() : getClassName(2), messageFactory);
     }
 
     /**
@@ -375,10 +361,8 @@ public class LogManager {
      * @return The Logger.
      */
     public static Logger getLogger(final String name) {
-        if (name != null) {
-            return factory.getContext(LogManager.class.getName(), null, false).getLogger(name);
-        }
-        return getLogger(getClassName(2));
+        String actualName = name != null ? name : getClassName(2);
+        return factory.getContext(LogManager.class.getName(), null, false).getLogger(actualName);
     }
 
     /**
@@ -390,10 +374,8 @@ public class LogManager {
      * @return The Logger.
      */
     public static Logger getLogger(final String name, final MessageFactory messageFactory)
{
-        if (name != null) {
-            return factory.getContext(LogManager.class.getName(), null, false).getLogger(name,
messageFactory);
-        }
-        return getLogger(getClassName(2), messageFactory);
+        String actualName = name != null ? name : getClassName(2);
+        return factory.getContext(LogManager.class.getName(), null, false).getLogger(actualName,
messageFactory);
     }
 
     /**
@@ -425,6 +407,12 @@ public class LogManager {
         return factory.getContext(fqcn, null, false).getLogger(name);
     }
 
+    /**
+     * Gets the class name of the caller in the current stack at the given {@code depth}.
+     * 
+     * @param depth a 0-based index in the current stack.
+     * @return a class name  
+     */
     private static String getClassName(int depth) {
         return new Throwable().getStackTrace()[depth].getClassName();
     }



Mime
View raw message