[slf4j-dev] svn commit: r707 - in slf4j/trunk: slf4j-api/src/main/java/org/slf4j slf4j-jdk14/src/main/java/org/slf4j/impl slf4j-log4j12/src/main/java/org/slf4j/impl slf4j-simple/src/main/java/org/slf4j/impl

ceki at slf4j.org ceki at slf4j.org
Sun Feb 4 02:08:32 CET 2007


Author: ceki
Date: Sun Feb  4 02:08:31 2007
New Revision: 707

Modified:
   slf4j/trunk/slf4j-api/src/main/java/org/slf4j/Logger.java
   slf4j/trunk/slf4j-jdk14/src/main/java/org/slf4j/impl/JDK14LoggerFactory.java
   slf4j/trunk/slf4j-log4j12/src/main/java/org/slf4j/impl/Log4jLoggerFactory.java
   slf4j/trunk/slf4j-simple/src/main/java/org/slf4j/impl/SimpleLoggerFactory.java

Log:

Added support for retrieving the root logger to the JUL and log4j
bindings as requested in bug report #35. NOP, Simple and JCL do not
have a notion of a root logger.

Bug reprot 35 can be found at: 

  http://bugzilla.slf4j.org/show_bug.cgi?id=35




Modified: slf4j/trunk/slf4j-api/src/main/java/org/slf4j/Logger.java
==============================================================================
--- slf4j/trunk/slf4j-api/src/main/java/org/slf4j/Logger.java	(original)
+++ slf4j/trunk/slf4j-api/src/main/java/org/slf4j/Logger.java	Sun Feb  4 02:08:31 2007
@@ -43,6 +43,12 @@
 
 
   /**
+   * Case insensitive string constant used to retrieve the name of the root logger.
+   * @since 1.3
+   */
+  final public String ROOT_LOGGER_NAME = "ROOT";
+  
+  /**
    * Return the name of this <code>Logger</code> instance.
    */
   public String getName();

Modified: slf4j/trunk/slf4j-jdk14/src/main/java/org/slf4j/impl/JDK14LoggerFactory.java
==============================================================================
--- slf4j/trunk/slf4j-jdk14/src/main/java/org/slf4j/impl/JDK14LoggerFactory.java	(original)
+++ slf4j/trunk/slf4j-jdk14/src/main/java/org/slf4j/impl/JDK14LoggerFactory.java	Sun Feb  4 02:08:31 2007
@@ -63,6 +63,10 @@
     Logger ulogger = null;
     // protect against concurrent access of loggerMap
     synchronized (this) {
+      // the root logger is called "" in JUL
+      if(name.equalsIgnoreCase(Logger.ROOT_LOGGER_NAME)) {
+        name = "";
+      }
       ulogger = (Logger) loggerMap.get(name);
       if (ulogger == null) {
         java.util.logging.Logger logger = java.util.logging.Logger

Modified: slf4j/trunk/slf4j-log4j12/src/main/java/org/slf4j/impl/Log4jLoggerFactory.java
==============================================================================
--- slf4j/trunk/slf4j-log4j12/src/main/java/org/slf4j/impl/Log4jLoggerFactory.java	(original)
+++ slf4j/trunk/slf4j-log4j12/src/main/java/org/slf4j/impl/Log4jLoggerFactory.java	Sun Feb  4 02:08:31 2007
@@ -64,10 +64,15 @@
     Logger slf4jLogger = null;
     // protect against concurrent access of loggerMap
     synchronized (this) {
-      slf4jLogger = (Logger) loggerMap.get(name);
+        slf4jLogger = (Logger) loggerMap.get(name);
       if (slf4jLogger == null) {
-        org.apache.log4j.Logger logger = LogManager.getLogger(name);
-        slf4jLogger = new Log4jLoggerAdapter(logger);
+        org.apache.log4j.Logger log4jLogger;
+        if(name.equalsIgnoreCase(Logger.ROOT_LOGGER_NAME)) {
+           log4jLogger = LogManager.getRootLogger();
+        } else {
+          log4jLogger = LogManager.getLogger(name);
+        }
+        slf4jLogger = new Log4jLoggerAdapter(log4jLogger);
         loggerMap.put(name, slf4jLogger);
       }
     }

Modified: slf4j/trunk/slf4j-simple/src/main/java/org/slf4j/impl/SimpleLoggerFactory.java
==============================================================================
--- slf4j/trunk/slf4j-simple/src/main/java/org/slf4j/impl/SimpleLoggerFactory.java	(original)
+++ slf4j/trunk/slf4j-simple/src/main/java/org/slf4j/impl/SimpleLoggerFactory.java	Sun Feb  4 02:08:31 2007
@@ -47,14 +47,7 @@
  */
 public class SimpleLoggerFactory implements ILoggerFactory {
 
-  /**
-   * A default instance of SimpleLoggerFactory. This default instance may be
-   * used to retrieve a simple logger as a last-resort fallback logger. This
-   * instance is designed to be used by a very specific group of users, namely
-   * for those developing fully-fledged logging systems (e.g. log4j or logback).
-   * It is not intended for end-users of the SLF4J API.
-   */
-  public final static SimpleLoggerFactory INSTANCE = new SimpleLoggerFactory();
+  final static SimpleLoggerFactory INSTANCE = new SimpleLoggerFactory();
 
   Map loggerMap;
 



More information about the slf4j-dev mailing list