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 2012/10/11 02:16:45 UTC

svn commit: r1396872 - in /logging/log4j/log4j2/trunk: api/src/main/java/org/apache/logging/log4j/ api/src/main/java/org/apache/logging/log4j/spi/ core/src/main/java/org/apache/logging/log4j/core/

Author: ggregory
Date: Thu Oct 11 00:16:45 2012
New Revision: 1396872

URL: http://svn.apache.org/viewvc?rev=1396872&view=rev
Log:
Add Logger.getName().

Modified:
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/Logger.java
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/AbstractLoggerWrapper.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/Logger.java

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/Logger.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/Logger.java?rev=1396872&r1=1396871&r2=1396872&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/Logger.java (original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/Logger.java Thu Oct 11 00:16:45 2012
@@ -24,7 +24,7 @@ import org.apache.logging.log4j.message.
  * @doubt See LOG4J2-16.
  */
 public interface Logger {
-
+    
   /**
    * Logs an exception or error that has been caught.
    * @param level The logging Level.
@@ -145,7 +145,7 @@ public interface Logger {
    */
   void debug(String message, Object... params);
 
-   /**
+  /**
    * Logs a message at the {@link Level#DEBUG DEBUG} level including the
    * stack trace of the {@link Throwable} <code>t</code> passed as parameter.
    *
@@ -154,7 +154,7 @@ public interface Logger {
    */
   void debug(String message, Throwable t);
 
-  /**
+   /**
    * Logs entry to a method.
    */
   void entry();
@@ -438,6 +438,13 @@ public interface Logger {
   void fatal(String message, Throwable t);
 
   /**
+   * Gets the logger name.
+   * 
+   * @return the logger name.
+   */
+    String getName();
+
+  /**
    * Logs a message with the specific Marker at the INFO level.
    *
    * @param marker the marker data specific to this log statement

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java?rev=1396872&r1=1396871&r2=1396872&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java (original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java Thu Oct 11 00:16:45 2012
@@ -58,6 +58,24 @@ public abstract class AbstractLogger imp
 
     private static final String FQCN = AbstractLogger.class.getName();
 
+    private final String name;
+    
+    /**
+     * Creates a new logger named after the class (or subclass).
+     */
+    public AbstractLogger() {
+        this.name = getClass().getName();
+    }
+
+    /**
+     * Creates a new named logger.
+     * 
+     * @param name the logger name
+     */
+    public AbstractLogger(String name) {
+        this.name = name;
+    }
+    
     /**
      * Logs entry to a method.
      */
@@ -1441,4 +1459,20 @@ public abstract class AbstractLogger imp
         }
         return new SimpleMessage(" exit with (" + result + ")");
     }
+
+    /* (non-Javadoc)
+     * @see org.apache.logging.log4j.Logger#getName()
+     */
+    public String getName() {
+        return name;
+    }
+    
+    /**
+     * Returns a String representation of this instance in the form {@code "name"}.
+     * @return A String describing this Logger instance.
+     */
+    @Override
+    public String toString() {
+        return name;
+    }
 }

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/AbstractLoggerWrapper.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/AbstractLoggerWrapper.java?rev=1396872&r1=1396871&r2=1396872&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/AbstractLoggerWrapper.java (original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/spi/AbstractLoggerWrapper.java Thu Oct 11 00:16:45 2012
@@ -29,10 +29,6 @@ public class AbstractLoggerWrapper exten
      * The wrapped Logger.
      */
     protected final AbstractLogger logger;
-    /**
-     * The name of the Logger.
-     */
-    protected final String name;
 
     /**
      * Constructor that wraps and existing Logger.
@@ -40,8 +36,8 @@ public class AbstractLoggerWrapper exten
      * @param name The name of the Logger.
      */
     public AbstractLoggerWrapper(AbstractLogger logger, String name) {
+        super(name);
         this.logger = logger;
-        this.name = name;
     }
 
     /**

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=1396872&r1=1396871&r2=1396872&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 Thu Oct 11 00:16:45 2012
@@ -43,8 +43,6 @@ public class Logger extends AbstractLogg
      */
     protected volatile PrivateConfig config;
 
-    private final String name;
-
     private final LoggerContext context;
 
     /**
@@ -53,20 +51,12 @@ public class Logger extends AbstractLogg
      * @param name The name of the Logger.
      */
     protected Logger(LoggerContext context, String name) {
+        super(name);
         this.context = context;
-        this.name = name;
         config = new PrivateConfig(context.getConfiguration(), this);
     }
 
     /**
-     * Returns the name of the Logger.
-     * @return the name of the Logger.
-     */
-    public String getName() {
-        return name;
-    }
-
-    /**
      * Returns the parent of this Logger. If it doesn't already exist return a temporary Logger.
      * @return The parent Logger.
      */
@@ -76,9 +66,9 @@ public class Logger extends AbstractLogg
             return null;
         }
         if (context.hasLogger(lc.getName())) {
-            return context.getLogger(name);
+            return context.getLogger(getName());
         }
-        return new Logger(context, name);
+        return new Logger(context, getName());
     }
 
     /**
@@ -113,7 +103,7 @@ public class Logger extends AbstractLogg
             data = new SimpleMessage("");
         }
         config.config.getConfigurationMonitor().checkConfiguration();
-        config.loggerConfig.log(name, marker, fqcn, level, data, t);
+        config.loggerConfig.log(getName(), marker, fqcn, level, data, t);
     }
 
     @Override
@@ -250,7 +240,7 @@ public class Logger extends AbstractLogg
 
         public PrivateConfig(Configuration config, Logger logger) {
             this.config = config;
-            this.loggerConfig = config.getLoggerConfig(name);
+            this.loggerConfig = config.getLoggerConfig(getName());
             this.level = this.loggerConfig.getLevel();
             this.intLevel = this.level.intLevel();
             this.logger = logger;
@@ -349,7 +339,7 @@ public class Logger extends AbstractLogg
      */
     @Override
     public String toString() {
-        final String nameLevel = "" + name + ":" + getLevel();
+        final String nameLevel = "" + getName() + ":" + getLevel();
         if (context == null) {
             return nameLevel;
         }