[logback-dev] svn commit: r1082 - logback/trunk/log4j-bridge/src/main/java/org/apache/log4j

noreply.seb at qos.ch noreply.seb at qos.ch
Wed Dec 13 21:40:54 CET 2006


Author: seb
Date: Wed Dec 13 21:40:54 2006
New Revision: 1082

Added:
   logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/MDC.java
Modified:
   logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/Category.java

Log:
Added a MDC wrapper and parametrized logging into Category.java

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	Wed Dec 13 21:40:54 2006
@@ -23,16 +23,15 @@
  * <p>
  * This class is a minimal implementation of the origianl
  * org.apache.log4j.Logger class delegating all calls to a
- * {@link org.slf4j.Logger} instance, which in turn will delegate to a final
- * logging system chosen by the user..
+ * {@link ch.qos.logback.classic.Logger} instance.
  * </p>
  * 
  * <p>
  * Log4j's <code>debug()</code>, <code>info()</code>, <code>warn()</code>,
- * <code>error()</code> printing methods are directly mapped to their SLF4J
+ * <code>error()</code> printing methods are directly mapped to their logback
  * equivalents. Log4j's <code>trace()</code> printing method is mapped to
- * SLF4J's <code>debug()</code> method with a TRACE marker. Log4j's
- * <code>fatal()</code> printing method is mapped to SLF4J's
+ * logback's <code>debug()</code> method with a TRACE marker. Log4j's
+ * <code>fatal()</code> printing method is mapped to logback's
  * <code>error()</code> method with a FATAL marker.
  * 
  * @author S&eacute;bastien Pennec
@@ -80,64 +79,96 @@
   }
 
   /**
-   * Delegates to {@link org.slf4j.Logger#isDebugEnabled} method of the SLF4J
-   * API, in addition, the call is marked with a marker named "TRACE".
+   * Delegates to {@link ch.qos.logback.classic.Logger#isDebugEnabled} 
+   * method of logback, in addition, the call is marked with a marker named "TRACE".
    */
   public boolean isTraceEnabled() {
     return lbLogger.isDebugEnabled(TRACE_MARKER);
   }
 
   /**
-   * Delegates to {@link org.slf4j.Logger#isDebugEnabled} method of the SLF4J
-   * API.
+   * Delegates to {@link ch.qos.logback.classic.Logger#isDebugEnabled} method of logback
    */
   public boolean isDebugEnabled() {
     return lbLogger.isDebugEnabled();
   }
 
   /**
-   * Delegates to {@link org.slf4j.Logger#isInfoEnabled} method of the SLF4J
-   * API.
+   * Delegates to {@link ch.qos.logback.classic.Logger#isInfoEnabled} method of logback
    */
   public boolean isInfoEnabled() {
     return lbLogger.isInfoEnabled();
   }
 
   /**
-   * Delegates to {@link org.slf4j.Logger#isWarnEnabled} method of the SLF4J
-   * API.
+   * Delegates to {@link ch.qos.logback.classic.Logger#isWarnEnabled} method of logback
    */
   public boolean isWarnEnabled() {
     return lbLogger.isWarnEnabled();
   }
+  
+  public boolean isEnabledFor(Priority p) {
+    return isEnabledFor(Level.toLevel(p.level));
+  }
+
+  public boolean isEnabledFor(Level l) {
+    switch (l.level) {
+    case Level.DEBUG_INT:
+      return lbLogger.isDebugEnabled();
+    case Level.INFO_INT:
+      return lbLogger.isInfoEnabled();
+    case Level.WARN_INT:
+      return lbLogger.isWarnEnabled();
+    case Level.ERROR_INT:
+      return lbLogger.isErrorEnabled();
+    case Level.FATAL_INT:
+      return lbLogger.isErrorEnabled();
+    }
+    return false;
+  }
 
   /**
-   * Delegates to {@link org.slf4j.Logger#isErrorEnabled} method of the SLF4J
-   * API.
+   * Delegates to {@link ch.qos.logback.classic.Logger#isErrorEnabled} method of logback
    */
   public boolean isErrorEnabled() {
     return lbLogger.isErrorEnabled();
   }
 
   /**
-   * Delegates to {@link org.slf4j.Logger#debug(String)} method of the SLF4J
-   * API, in addition, the call is marked with a marker named "TRACE".
+   * Delegates to {@link ch.qos.logback.classic.Logger#debug(String)} method of logback, 
+   * in addition, the call is marked with a marker named "TRACE".
    */
   public void trace(Object message) {
     lbLogger.debug(TRACE_MARKER, (String) message);
   }
 
   /**
-   * Delegates to {@link org.slf4j.Logger#debug(String,Throwable)} method of the
-   * SLF4J API, in addition, the call is marked with a marker named "TRACE".
+   * Delegates to {@link ch.qos.logback.classic.Logger#debug(String,Throwable)} 
+   * method of logback in addition, the call is marked with a marker named "TRACE".
    */
   public void trace(Object message, Throwable t) {
     lbLogger.debug(TRACE_MARKER, (String) message, t);
   }
+  
+  /**
+   * Delegates to {@link ch.qos.logback.classic.Logger#debug(String,Object)} 
+   * method of logback in addition, the call is marked with a marker named "TRACE".
+   */
+  public void trace(Object message, Object o) {
+    lbLogger.debug(TRACE_MARKER, (String)message, o);
+  }
 
   /**
-   * Delegates to {@link org.slf4j.Logger#debug(String)} method of the SLF4J
-   * API.
+   * Delegates to {@link ch.qos.logback.classic.Logger#debug(String,Object,Object)} 
+   * method of logback in addition, the call is marked with a marker named "TRACE".
+   */
+  public void trace(String message, Object arg1, Object arg2) {
+    lbLogger.debug(TRACE_MARKER, message, arg1, arg2);
+  }
+  
+  /**
+   * Delegates to {@link ch.qos.logback.classic.Logger#debug(String)} method of
+   * logback.
    */
   public void debug(Object message) {
     // casting to String as SLF4J only accepts String instances, not Object
@@ -146,97 +177,177 @@
   }
 
   /**
-   * Delegates to {@link org.slf4j.Logger#debug(String,Throwable)} method of the
-   * SLF4J API.
+   * Delegates to {@link ch.qos.logback.classic.Logger#debug(String,Throwable)} 
+   * method of logback.
    */
   public void debug(Object message, Throwable t) {
     lbLogger.debug((String) message, t);
   }
 
   /**
-   * Delegates to {@link org.slf4j.Logger#info(String)} method of the SLF4J API.
+   * Delegates to {@link ch.qos.logback.classic.Logger#debug(String,Object)} 
+   * method of logback.
+   */
+  public void debug(Object message, Object o) {
+    lbLogger.debug((String)message, o);
+  }
+  
+  /**
+   * Delegates to {@link ch.qos.logback.classic.Logger#debug(String,Object,Object)} 
+   * method of logback.
+   */
+  public void debug(String message, Object arg1, Object arg2) {
+    lbLogger.debug(message, arg1, arg2);
+  }
+  
+  /**
+   * Delegates to {@link ch.qos.logback.classic.Logger#info(String)} 
+   * method of logback.
    */
   public void info(Object message) {
     lbLogger.info((String) message);
   }
 
   /**
-   * Delegates to {@link org.slf4j.Logger#info(String, Throwable)} method of the
-   * SLF4J API.
+   * Delegates to {@link ch.qos.logback.classic.Logger#info(String,Throwable)} 
+   * method of logback.
    */
   public void info(Object message, Throwable t) {
     lbLogger.info((String) message, t);
   }
 
   /**
-   * Delegates to {@link org.slf4j.Logger#warn(String)} method of the SLF4J API.
+   * Delegates to {@link ch.qos.logback.classic.Logger#info(String,Object)} 
+   * method of logback.
+   */
+  public void info(Object message, Object o) {
+    lbLogger.info((String) message, o);
+  }  
+  
+  /**
+   * Delegates to {@link ch.qos.logback.classic.Logger#info(String,Object,Object)} 
+   * method of logback.
+   */
+  public void info(String message, Object arg1, Object arg2) {
+    lbLogger.info(message, arg1, arg2);
+  }
+  
+  /**
+   * Delegates to {@link ch.qos.logback.classic.Logger#warn(String)} 
+   * method of logback.
    */
   public void warn(Object message) {
     lbLogger.warn((String) message);
   }
 
   /**
-   * Delegates to {@link org.slf4j.Logger#warn(String,Throwable)} method of the
-   * SLF4J API.
+   * Delegates to {@link ch.qos.logback.classic.Logger#warn(String,Throwable)} 
+   * method of logback.
    */
   public void warn(Object message, Throwable t) {
     lbLogger.warn((String) message, t);
   }
 
   /**
-   * Delegates to {@link org.slf4j.Logger#error(String)} method of the SLF4J
-   * API.
+   * Delegates to {@link ch.qos.logback.classic.Logger#warn(String,Object)} 
+   * method of logback.
+   */
+  public void warn(Object message, Object o) {
+    lbLogger.warn((String)message, o);
+  }
+  
+  /**
+   * Delegates to {@link ch.qos.logback.classic.Logger#warn(String,Object,Object)} 
+   * method of logback.
+   */
+  public void warn(String message, Object arg1, Object arg2) {
+    lbLogger.warn(message, arg1, arg2);
+  }
+  
+  /**
+   * Delegates to {@link ch.qos.logback.classic.Logger#error(String)} 
+   * method of logback.
    */
   public void error(Object message) {
     lbLogger.error((String) message);
   }
 
   /**
-   * Delegates to {@link org.slf4j.Logger#error(String,Throwable)} method of the
-   * SLF4J API.
+   * Delegates to {@link ch.qos.logback.classic.Logger#error(String,Throwable)} 
+   * method of logback.
    */
   public void error(Object message, Throwable t) {
     lbLogger.error((String) message, t);
   }
 
   /**
-   * Delegates to {@link org.slf4j.Logger#error(String)} method of the SLF4J
-   * API, in addition, the call is marked with a marker named "FATAL".
+   * Delegates to {@link ch.qos.logback.classic.Logger#error(String,Object)} 
+   * method of logback.
+   */
+  public void error(Object message, Object o) {
+    lbLogger.error((String)message, o);
+  }
+  
+  /**
+   * Delegates to {@link ch.qos.logback.classic.Logger#error(String,Object,Object)} 
+   * method of logback.
+   */
+  public void error(String message, Object arg1, Object arg2) {
+    lbLogger.error(message, arg1, arg2);
+  }
+  
+  /**
+   * Delegates to {@link ch.qos.logback.classic.Logger#error(String)} 
+   * method of logback.
    */
   public void fatal(Object message) {
     lbLogger.error(FATAL_MARKER, (String) message);
   }
 
   /**
-   * Delegates to {@link org.slf4j.Logger#error(String,Throwable)} method of the
-   * SLF4J API, in addition, the call is marked with a marker named "FATAL".
+   * Delegates to {@link ch.qos.logback.classic.Logger#error(String,Throwable)} 
+   * method of logback in addition, the call is marked with a marker named "FATAL".
    */
   public void fatal(Object message, Throwable t) {
     lbLogger.error(FATAL_MARKER, (String) message, t);
   }
 
+  /**
+   * Delegates to {@link ch.qos.logback.classic.Logger#error(String,Object)} 
+   * method of logback in addition, the call is marked with a marker named "FATAL".
+   */
+  public void fatal(Object message, Object o) {
+    lbLogger.error(FATAL_MARKER, (String)message, o);
+  } 
+  
+  /**
+   * Delegates to {@link ch.qos.logback.classic.Logger#error(String,Object,Object)} 
+   * method of logback in addition, the call is marked with a marker named "FATAL".
+   */
+  public void fatal(String message, Object arg1, Object arg2) {
+    lbLogger.error(FATAL_MARKER, message, arg1, arg2);
+  } 
+  
   public void log(String FQCN, Priority p, Object msg, Throwable t) {
-    ch.qos.logback.classic.Level level;
+    ch.qos.logback.classic.Level level = priorityToLevel(p);
+    lbLogger.filterAndLog(FQCN, null, level, msg.toString(), null, t);
+  }
+  
+  private ch.qos.logback.classic.Level priorityToLevel(Priority p) {
     switch (p.level) {
     case Priority.DEBUG_INT:
-      level = ch.qos.logback.classic.Level.DEBUG;
-      break;
+      return ch.qos.logback.classic.Level.DEBUG;
     case Priority.INFO_INT:
-      level = ch.qos.logback.classic.Level.INFO;
-      break;
+      return ch.qos.logback.classic.Level.INFO;
     case Priority.WARN_INT:
-      level = ch.qos.logback.classic.Level.WARN;
-      break;
+      return ch.qos.logback.classic.Level.WARN;
     case Priority.ERROR_INT:
-      level = ch.qos.logback.classic.Level.ERROR;
-      break;
+      return ch.qos.logback.classic.Level.ERROR;
     case Priority.FATAL_INT:
-      level = ch.qos.logback.classic.Level.ERROR;
-      break;
+      return ch.qos.logback.classic.Level.ERROR;
     default:
       throw new IllegalStateException("Unknown Priority " + p);
     }
-    lbLogger.filterAndLog(FQCN, null, level, msg.toString(), null, t);
   }
 
 }

Added: logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/MDC.java
==============================================================================
--- (empty file)
+++ logback/trunk/log4j-bridge/src/main/java/org/apache/log4j/MDC.java	Wed Dec 13 21:40:54 2006
@@ -0,0 +1,28 @@
+package org.apache.log4j;
+
+public class MDC {
+
+  public static void put(String key, String value) {
+    ch.qos.logback.classic.MDC.put(key, value);
+  }
+  
+  public static void put(String key, Object value) {
+    if (value != null) {
+      put(key, value.toString());
+    } else {
+      put(key, null);
+    }
+  }
+  
+  public static Object get(String key) {
+    return ch.qos.logback.classic.MDC.get(key);
+  }
+  
+  public static void remove(String key) {
+    ch.qos.logback.classic.MDC.remove(key);
+  }
+  
+  public static void clear() {
+    ch.qos.logback.classic.MDC.clear();
+  }
+}



More information about the logback-dev mailing list