[logback-dev] svn commit: r1553 - in logback/trunk/log4j-bridge: compatibility compatibility/lib compatibility/src/main/java/test src/main/java/org/apache/log4j src/test/java/org/apache/log4j

noreply.ceki at qos.ch noreply.ceki at qos.ch
Mon Jul 9 22:12:20 CEST 2007


Author: ceki
Date: Mon Jul  9 22:12:20 2007
New Revision: 1553

Removed:
   logback/trunk/log4j-bridge/compatibility/lib/slf4j-api-1.4.0.jar
Modified:
   logback/trunk/log4j-bridge/compatibility/build.xml
   logback/trunk/log4j-bridge/compatibility/src/main/java/test/Log4j12Calls.java
   logback/trunk/log4j-bridge/compatibility/src/main/java/test/Log4j13Calls.java
   logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/Category.java
   logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/MDC.java
   logback/trunk/log4j-bridge/src/test/java/org/apache/log4j/LoggerTest.java

Log:
- preparing to move log4j-bridge to SLF4J

Modified: logback/trunk/log4j-bridge/compatibility/build.xml
==============================================================================
--- logback/trunk/log4j-bridge/compatibility/build.xml	(original)
+++ logback/trunk/log4j-bridge/compatibility/build.xml	Mon Jul  9 22:12:20 2007
@@ -1,7 +1,7 @@
 <project name="testing-log4j-bridge" default="usage" basedir=".">
 
-	<property name="lbversion" value="0.9.1" />
-  <property name="slf4jversion" value="1.3.0" />
+	<property name="lbversion" value="0.9.8-SNAPSHOT" />
+  <property name="slf4jversion" value="1.4.1" />
 	<property name="source.home" value="./src/main/java/" />
 	<property name="javac.dest.12" value="./target/classes12/" />
 	<property name="javac.dest.13" value="./target/classes13/" />

Modified: logback/trunk/log4j-bridge/compatibility/src/main/java/test/Log4j12Calls.java
==============================================================================
--- logback/trunk/log4j-bridge/compatibility/src/main/java/test/Log4j12Calls.java	(original)
+++ logback/trunk/log4j-bridge/compatibility/src/main/java/test/Log4j12Calls.java	Mon Jul  9 22:12:20 2007
@@ -28,10 +28,10 @@
   public void testLog() {
     MDC.put("key", "value1");
     
+    logger.trace("Trace level can be noisy");
     logger.debug("Entering application");
     logger.info("Violets are blue");
     logger.warn("Here is a warning");
-    
     logger.error("Exiting application", new Exception("just testing"));
     
     MDC.remove("key");

Modified: logback/trunk/log4j-bridge/compatibility/src/main/java/test/Log4j13Calls.java
==============================================================================
--- logback/trunk/log4j-bridge/compatibility/src/main/java/test/Log4j13Calls.java	(original)
+++ logback/trunk/log4j-bridge/compatibility/src/main/java/test/Log4j13Calls.java	Mon Jul  9 22:12:20 2007
@@ -30,6 +30,7 @@
   public void testLog() {
     MDC.put("key", "value1");
     
+    logger.trace("Trace level can be noisy");
     logger.debug("Entering application");
     logger.info("Violets are blue");
     logger.warn("Here is a warning");

Modified: logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/Category.java
==============================================================================
--- logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/Category.java	(original)
+++ logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/Category.java	Mon Jul  9 22:12:20 2007
@@ -18,12 +18,15 @@
 import org.slf4j.LoggerFactory;
 import org.slf4j.Marker;
 import org.slf4j.MarkerFactory;
+import org.slf4j.spi.LocationAwareLogger;
+
+import ch.qos.logback.classic.Level;
 
 /**
  * <p>
  * This class is a minimal implementation of the origianl
  * org.apache.log4j.Logger class delegating all calls to a
- * {@link ch.qos.logback.classic.Logger} instance.
+ * {@link org.slf4j.Logger.Logger} instance.
  * </p>
  * 
  * <p>
@@ -42,14 +45,18 @@
 
   private String name;
 
-  private ch.qos.logback.classic.Logger lbLogger;
-
+  private org.slf4j.Logger lbLogger;
+  private org.slf4j.spi.LocationAwareLogger locationAwareLogger;
+  
   private static Marker TRACE_MARKER = MarkerFactory.getMarker("TRACE");
   private static Marker FATAL_MARKER = MarkerFactory.getMarker("FATAL");
 
   Category(String name) {
     this.name = name;
-    lbLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(name);
+    lbLogger = LoggerFactory.getLogger(name);
+    if(lbLogger instanceof LocationAwareLogger) {
+      locationAwareLogger = (LocationAwareLogger) lbLogger;
+    }
   }
 
   public static Logger getLogger(String name) {
@@ -79,11 +86,11 @@
   }
 
   /**
-   * Delegates to {@link ch.qos.logback.classic.Logger#isDebugEnabled} 
-   * method of logback, in addition, the call is marked with a marker named "TRACE".
+   * Delegates to {@link ch.qos.logback.classic.Logger#isTraceEnabled} 
+   * method of logback.
    */
   public boolean isTraceEnabled() {
-    return lbLogger.isDebugEnabled(TRACE_MARKER);
+    return lbLogger.isTraceEnabled();
   }
 
   /**
@@ -112,7 +119,9 @@
   }
 
   public boolean isEnabledFor(Level l) {
-    switch (l.level) {
+    switch (l.levelInt) {
+    case Level.TRACE_INT:
+      return lbLogger.isTraceEnabled();
     case Level.DEBUG_INT:
       return lbLogger.isDebugEnabled();
     case Level.INFO_INT:
@@ -121,7 +130,7 @@
       return lbLogger.isWarnEnabled();
     case Level.ERROR_INT:
       return lbLogger.isErrorEnabled();
-    case Level.FATAL_INT:
+    case Priority.FATAL_INT:
       return lbLogger.isErrorEnabled();
     }
     return false;
@@ -329,24 +338,33 @@
   } 
   
   public void log(String FQCN, Priority p, Object msg, Throwable t) {
-    ch.qos.logback.classic.Level level = priorityToLevel(p);
-    lbLogger.filterAndLog(FQCN, null, level, msg.toString(), null, t);
+    int levelInt = priorityToLevelInt(p);
+    if(locationAwareLogger != null) {
+      if(msg != null) {
+        locationAwareLogger.log(null, FQCN, levelInt, msg.toString(), t); 
+      } else {
+        locationAwareLogger.log(null, FQCN, levelInt, null, t); 
+      }
+    } else {
+      throw new UnsupportedOperationException("The logger ["+lbLogger+"] does not seem to be location aware.");
+    }
+   
   }
   
-  private ch.qos.logback.classic.Level priorityToLevel(Priority p) {
+  private int priorityToLevelInt(Priority p) {
     switch (p.level) {
     case Level.TRACE_INT:
-      return ch.qos.logback.classic.Level.TRACE;
+      return LocationAwareLogger.TRACE_INT;
     case Priority.DEBUG_INT:
-      return ch.qos.logback.classic.Level.DEBUG;
+      return LocationAwareLogger.DEBUG_INT;
     case Priority.INFO_INT:
-      return ch.qos.logback.classic.Level.INFO;
+      return LocationAwareLogger.INFO_INT;
     case Priority.WARN_INT:
-      return ch.qos.logback.classic.Level.WARN;
+      return LocationAwareLogger.WARN_INT;
     case Priority.ERROR_INT:
-      return ch.qos.logback.classic.Level.ERROR;
+      return LocationAwareLogger.ERROR_INT;
     case Priority.FATAL_INT:
-      return ch.qos.logback.classic.Level.ERROR;
+      return LocationAwareLogger.ERROR_INT;
     default:
       throw new IllegalStateException("Unknown Priority " + p);
     }

Modified: logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/MDC.java
==============================================================================
--- logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/MDC.java	(original)
+++ logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/MDC.java	Mon Jul  9 22:12:20 2007
@@ -3,7 +3,7 @@
 public class MDC {
 
   public static void put(String key, String value) {
-    ch.qos.logback.classic.MDC.put(key, value);
+    org.slf4j.MDC.put(key, value);
   }
   
   public static void put(String key, Object value) {
@@ -15,14 +15,14 @@
   }
   
   public static Object get(String key) {
-    return ch.qos.logback.classic.MDC.get(key);
+    return org.slf4j.MDC.get(key);
   }
   
   public static void remove(String key) {
-    ch.qos.logback.classic.MDC.remove(key);
+    org.slf4j.MDC.remove(key);
   }
   
   public static void clear() {
-    ch.qos.logback.classic.MDC.clear();
+    org.slf4j.MDC.clear();
   }
 }

Modified: logback/trunk/log4j-bridge/src/test/java/org/apache/log4j/LoggerTest.java
==============================================================================
--- logback/trunk/log4j-bridge/src/test/java/org/apache/log4j/LoggerTest.java	(original)
+++ logback/trunk/log4j-bridge/src/test/java/org/apache/log4j/LoggerTest.java	Mon Jul  9 22:12:20 2007
@@ -70,7 +70,7 @@
   }
 
   public void testIsEnabledAPI() {
-    assertTrue(log4jLogger.isTraceEnabled());
+    assertFalse(log4jLogger.isTraceEnabled());
     assertTrue(log4jLogger.isDebugEnabled());
     assertTrue(log4jLogger.isInfoEnabled());
     assertTrue(log4jLogger.isWarnEnabled());



More information about the logback-dev mailing list