[slf4j-dev] svn commit: r1154 - in slf4j/trunk/slf4j-ext: . src/main/java/org/slf4j/ext

ceki at slf4j.org ceki at slf4j.org
Wed Oct 1 18:20:10 CEST 2008


Author: ceki
Date: Wed Oct  1 18:20:09 2008
New Revision: 1154

Added:
   slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/ext/LoggerWrapper.java
   slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/ext/XLoggerFactory.java
Modified:
   slf4j/trunk/slf4j-ext/pom.xml
   slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/ext/XLogger.java

Log:
Fixing bug 104

Modified: slf4j/trunk/slf4j-ext/pom.xml
==============================================================================
--- slf4j/trunk/slf4j-ext/pom.xml	(original)
+++ slf4j/trunk/slf4j-ext/pom.xml	Wed Oct  1 18:20:09 2008
@@ -5,7 +5,7 @@
   <parent>
     <groupId>org.slf4j</groupId>
     <artifactId>slf4j-parent</artifactId>
-    <version>1.5.4-SNAPSHOT</version>
+    <version>1.5.4-SNAPSHOT
</version>
   </parent>
 
   <modelVersion>4.0.0</modelVersion>

Added: slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/ext/LoggerWrapper.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/ext/LoggerWrapper.java	Wed Oct  1 18:20:09 2008
@@ -0,0 +1,868 @@
+package org.slf4j.ext;
+
+import org.slf4j.Logger;
+import org.slf4j.Marker;
+import org.slf4j.helpers.MessageFormatter;
+import org.slf4j.spi.LocationAwareLogger;
+
+/**
+ * A helper class wrapping an org.slf4j.Logger instance
+ * preserving location information if the wrapped
+ * instance supports it.
+ * 
+ * @author Ralph Goers
+ * @author Ceki Gulcu
+ */
+public class LoggerWrapper implements Logger {
+
+  // To ensure consistency between two instances sharing the same name (homonyms)
+  // a LoggerWrapper should not contain any state beyond 
+  // the Logger instance it wraps.
+  // Note that 'instanceofLAL' directly depends on Logger.
+  // fqcn depend on the caller, but its value would not be different
+  // between successive invocations of a factory class
+  
+  final Logger logger;
+  final String fqcn;
+  // is this logger instance a LocationAwareLogger
+  final boolean instanceofLAL;
+  
+  public LoggerWrapper(Logger logger, String fcqn) {
+    this.logger = logger;
+    this.fqcn = fcqn;
+    if (logger instanceof LocationAwareLogger) {
+      instanceofLAL = true;
+    } else {
+      instanceofLAL = false;
+    }
+  }
+  
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public boolean isTraceEnabled() {
+    return logger.isTraceEnabled();
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public boolean isTraceEnabled(Marker marker) {
+    return logger.isTraceEnabled(marker);
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void trace(String msg) {
+    if (!logger.isTraceEnabled())
+      return;
+
+    if (instanceofLAL) {
+      ((LocationAwareLogger) logger).log(null, fqcn,
+          LocationAwareLogger.TRACE_INT, msg, null);
+    } else {
+      logger.trace(msg);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void trace(String format, Object arg) {
+    if (!logger.isTraceEnabled())
+      return;
+
+    if (instanceofLAL) {
+      String formattedMessage = MessageFormatter.format(format, arg);
+      ((LocationAwareLogger) logger).log(null, fqcn,
+          LocationAwareLogger.TRACE_INT, formattedMessage, null);
+    } else {
+      logger.trace(format, arg);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void trace(String format, Object arg1, Object arg2) {
+    if (!logger.isTraceEnabled())
+      return;
+
+    if (instanceofLAL) {
+      String formattedMessage = MessageFormatter.format(format, arg1, arg2);
+      ((LocationAwareLogger) logger).log(null, fqcn,
+          LocationAwareLogger.TRACE_INT, formattedMessage, null);
+    } else {
+      logger.trace(format, arg1, arg2);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void trace(String format, Object[] argArray) {
+    if (!logger.isTraceEnabled())
+      return;
+
+    if (instanceofLAL) {
+      String formattedMessage = MessageFormatter.arrayFormat(format, argArray);
+      ((LocationAwareLogger) logger).log(null, fqcn,
+          LocationAwareLogger.TRACE_INT, formattedMessage, null);
+    } else {
+      logger.trace(format, argArray);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void trace(String msg, Throwable t) {
+    if (!logger.isTraceEnabled())
+      return;
+
+    if (instanceofLAL) {
+      ((LocationAwareLogger) logger).log(null, fqcn,
+          LocationAwareLogger.TRACE_INT, msg, t);
+    } else {
+      logger.trace(msg, t);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void trace(Marker marker, String msg) {
+    if (!logger.isTraceEnabled())
+      return;
+    if (instanceofLAL) {
+      ((LocationAwareLogger) logger).log(marker, fqcn,
+          LocationAwareLogger.TRACE_INT, msg, null);
+    } else {
+      logger.trace(marker, msg);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void trace(Marker marker, String format, Object arg) {
+    if (!logger.isTraceEnabled())
+      return;
+    if (instanceofLAL) {
+      String formattedMessage = MessageFormatter.format(format, arg);
+      ((LocationAwareLogger) logger).log(marker, fqcn,
+          LocationAwareLogger.TRACE_INT, formattedMessage, null);
+    } else {
+      logger.trace(marker, format, arg);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void trace(Marker marker, String format, Object arg1, Object arg2) {
+    if (!logger.isTraceEnabled())
+      return;
+    if (instanceofLAL) {
+      String formattedMessage = MessageFormatter.format(format, arg1, arg2);
+      ((LocationAwareLogger) logger).log(marker, fqcn,
+          LocationAwareLogger.TRACE_INT, formattedMessage, null);
+    } else {
+      logger.trace(marker, format, arg1, arg2);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void trace(Marker marker, String format, Object[] argArray) {
+    if (!logger.isTraceEnabled())
+      return;
+    if (instanceofLAL) {
+      String formattedMessage = MessageFormatter.arrayFormat(format, argArray);
+      ((LocationAwareLogger) logger).log(marker, fqcn,
+          LocationAwareLogger.TRACE_INT, formattedMessage, null);
+    } else {
+      logger.trace(marker, format, argArray);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void trace(Marker marker, String msg, Throwable t) {
+    if (!logger.isTraceEnabled())
+      return;
+    if (instanceofLAL) {
+      ((LocationAwareLogger) logger).log(marker, fqcn,
+          LocationAwareLogger.TRACE_INT, msg, t);
+    } else {
+      logger.trace(marker, msg, t);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public boolean isDebugEnabled() {
+    return logger.isDebugEnabled();
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public boolean isDebugEnabled(Marker marker) {
+    return logger.isDebugEnabled(marker);
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void debug(String msg) {
+    if (!logger.isDebugEnabled())
+      return;
+
+    if (instanceofLAL) {
+      ((LocationAwareLogger) logger).log(null, fqcn,
+          LocationAwareLogger.DEBUG_INT, msg, null);
+    } else {
+      logger.debug(msg);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void debug(String format, Object arg) {
+    if (!logger.isDebugEnabled())
+      return;
+
+    if (instanceofLAL) {
+      String formattedMessage = MessageFormatter.format(format, arg);
+      ((LocationAwareLogger) logger).log(null, fqcn,
+          LocationAwareLogger.DEBUG_INT, formattedMessage, null);
+    } else {
+      logger.debug(format, arg);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void debug(String format, Object arg1, Object arg2) {
+    if (!logger.isDebugEnabled())
+      return;
+
+    if (instanceofLAL) {
+      String formattedMessage = MessageFormatter.format(format, arg1, arg2);
+      ((LocationAwareLogger) logger).log(null, fqcn,
+          LocationAwareLogger.DEBUG_INT, formattedMessage, null);
+    } else {
+      logger.debug(format, arg1, arg2);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void debug(String format, Object[] argArray) {
+    if (!logger.isDebugEnabled())
+      return;
+
+    if (instanceofLAL) {
+      String formattedMessage = MessageFormatter.arrayFormat(format, argArray);
+      ((LocationAwareLogger) logger).log(null, fqcn,
+          LocationAwareLogger.DEBUG_INT, formattedMessage, null);
+    } else {
+      logger.debug(format, argArray);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void debug(String msg, Throwable t) {
+    if (!logger.isDebugEnabled())
+      return;
+
+    if (instanceofLAL) {
+      ((LocationAwareLogger) logger).log(null, fqcn,
+          LocationAwareLogger.DEBUG_INT, msg, t);
+    } else {
+      logger.debug(msg, t);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void debug(Marker marker, String msg) {
+    if (!logger.isDebugEnabled())
+      return;
+    if (instanceofLAL) {
+      ((LocationAwareLogger) logger).log(marker, fqcn,
+          LocationAwareLogger.DEBUG_INT, msg, null);
+    } else {
+      logger.debug(marker, msg);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void debug(Marker marker, String format, Object arg) {
+    if (!logger.isDebugEnabled())
+      return;
+    if (instanceofLAL) {
+      String formattedMessage = MessageFormatter.format(format, arg);
+      ((LocationAwareLogger) logger).log(marker, fqcn,
+          LocationAwareLogger.DEBUG_INT, formattedMessage, null);
+    } else {
+      logger.debug(marker, format, arg);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void debug(Marker marker, String format, Object arg1, Object arg2) {
+    if (!logger.isDebugEnabled())
+      return;
+    if (instanceofLAL) {
+      String formattedMessage = MessageFormatter.format(format, arg1, arg2);
+      ((LocationAwareLogger) logger).log(marker, fqcn,
+          LocationAwareLogger.DEBUG_INT, formattedMessage, null);
+    } else {
+      logger.debug(marker, format, arg1, arg2);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void debug(Marker marker, String format, Object[] argArray) {
+    if (!logger.isDebugEnabled())
+      return;
+    if (instanceofLAL) {
+      String formattedMessage = MessageFormatter.arrayFormat(format, argArray);
+      ((LocationAwareLogger) logger).log(marker, fqcn,
+          LocationAwareLogger.DEBUG_INT, formattedMessage, null);
+    } else {
+      logger.debug(marker, format, argArray);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void debug(Marker marker, String msg, Throwable t) {
+    if (!logger.isDebugEnabled())
+      return;
+    if (instanceofLAL) {
+      ((LocationAwareLogger) logger).log(marker, fqcn,
+          LocationAwareLogger.DEBUG_INT, msg, t);
+    } else {
+      logger.debug(marker, msg, t);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public boolean isInfoEnabled() {
+    return logger.isInfoEnabled();
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public boolean isInfoEnabled(Marker marker) {
+    return logger.isInfoEnabled(marker);
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void info(String msg) {
+    if (!logger.isInfoEnabled())
+      return;
+
+    if (instanceofLAL) {
+      ((LocationAwareLogger) logger).log(null, fqcn,
+          LocationAwareLogger.INFO_INT, msg, null);
+    } else {
+      logger.info(msg);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void info(String format, Object arg) {
+    if (!logger.isInfoEnabled())
+      return;
+
+    if (instanceofLAL) {
+      String formattedMessage = MessageFormatter.format(format, arg);
+      ((LocationAwareLogger) logger).log(null, fqcn,
+          LocationAwareLogger.INFO_INT, formattedMessage, null);
+    } else {
+      logger.info(format, arg);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void info(String format, Object arg1, Object arg2) {
+    if (!logger.isInfoEnabled())
+      return;
+
+    if (instanceofLAL) {
+      String formattedMessage = MessageFormatter.format(format, arg1, arg2);
+      ((LocationAwareLogger) logger).log(null, fqcn,
+          LocationAwareLogger.INFO_INT, formattedMessage, null);
+    } else {
+      logger.info(format, arg1, arg2);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void info(String format, Object[] argArray) {
+    if (!logger.isInfoEnabled())
+      return;
+
+    if (instanceofLAL) {
+      String formattedMessage = MessageFormatter.arrayFormat(format, argArray);
+      ((LocationAwareLogger) logger).log(null, fqcn,
+          LocationAwareLogger.INFO_INT, formattedMessage, null);
+    } else {
+      logger.info(format, argArray);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void info(String msg, Throwable t) {
+    if (!logger.isInfoEnabled())
+      return;
+
+    if (instanceofLAL) {
+      ((LocationAwareLogger) logger).log(null, fqcn,
+          LocationAwareLogger.INFO_INT, msg, t);
+    } else {
+      logger.info(msg, t);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void info(Marker marker, String msg) {
+    if (!logger.isInfoEnabled())
+      return;
+    if (instanceofLAL) {
+      ((LocationAwareLogger) logger).log(marker, fqcn,
+          LocationAwareLogger.INFO_INT, msg, null);
+    } else {
+      logger.info(marker, msg);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void info(Marker marker, String format, Object arg) {
+    if (!logger.isInfoEnabled())
+      return;
+    if (instanceofLAL) {
+      String formattedMessage = MessageFormatter.format(format, arg);
+      ((LocationAwareLogger) logger).log(marker, fqcn,
+          LocationAwareLogger.INFO_INT, formattedMessage, null);
+    } else {
+      logger.info(marker, format, arg);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void info(Marker marker, String format, Object arg1, Object arg2) {
+    if (!logger.isInfoEnabled())
+      return;
+    if (instanceofLAL) {
+      String formattedMessage = MessageFormatter.format(format, arg1, arg2);
+      ((LocationAwareLogger) logger).log(marker, fqcn,
+          LocationAwareLogger.INFO_INT, formattedMessage, null);
+    } else {
+      logger.info(marker, format, arg1, arg2);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void info(Marker marker, String format, Object[] argArray) {
+    if (!logger.isInfoEnabled())
+      return;
+    if (instanceofLAL) {
+      String formattedMessage = MessageFormatter.arrayFormat(format, argArray);
+      ((LocationAwareLogger) logger).log(marker, fqcn,
+          LocationAwareLogger.INFO_INT, formattedMessage, null);
+    } else {
+      logger.info(marker, format, argArray);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void info(Marker marker, String msg, Throwable t) {
+    if (!logger.isInfoEnabled())
+      return;
+    if (instanceofLAL) {
+      ((LocationAwareLogger) logger).log(marker, fqcn,
+          LocationAwareLogger.INFO_INT, msg, t);
+    } else {
+      logger.info(marker, msg, t);
+    }
+  }
+
+  public boolean isWarnEnabled() {
+    return logger.isWarnEnabled();
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public boolean isWarnEnabled(Marker marker) {
+    return logger.isWarnEnabled(marker);
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void warn(String msg) {
+    if (!logger.isWarnEnabled())
+      return;
+
+    if (instanceofLAL) {
+      ((LocationAwareLogger) logger).log(null, fqcn,
+          LocationAwareLogger.WARN_INT, msg, null);
+    } else {
+      logger.warn(msg);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void warn(String format, Object arg) {
+    if (!logger.isWarnEnabled())
+      return;
+
+    if (instanceofLAL) {
+      String formattedMessage = MessageFormatter.format(format, arg);
+      ((LocationAwareLogger) logger).log(null, fqcn,
+          LocationAwareLogger.WARN_INT, formattedMessage, null);
+    } else {
+      logger.warn(format, arg);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void warn(String format, Object arg1, Object arg2) {
+    if (!logger.isWarnEnabled())
+      return;
+
+    if (instanceofLAL) {
+      String formattedMessage = MessageFormatter.format(format, arg1, arg2);
+      ((LocationAwareLogger) logger).log(null, fqcn,
+          LocationAwareLogger.WARN_INT, formattedMessage, null);
+    } else {
+      logger.warn(format, arg1, arg2);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void warn(String format, Object[] argArray) {
+    if (!logger.isWarnEnabled())
+      return;
+
+    if (instanceofLAL) {
+      String formattedMessage = MessageFormatter.arrayFormat(format, argArray);
+      ((LocationAwareLogger) logger).log(null, fqcn,
+          LocationAwareLogger.WARN_INT, formattedMessage, null);
+    } else {
+      logger.warn(format, argArray);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void warn(String msg, Throwable t) {
+    if (!logger.isWarnEnabled())
+      return;
+
+    if (instanceofLAL) {
+      ((LocationAwareLogger) logger).log(null, fqcn,
+          LocationAwareLogger.WARN_INT, msg, t);
+    } else {
+      logger.warn(msg, t);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void warn(Marker marker, String msg) {
+    if (!logger.isWarnEnabled())
+      return;
+    if (instanceofLAL) {
+      ((LocationAwareLogger) logger).log(marker, fqcn,
+          LocationAwareLogger.WARN_INT, msg, null);
+    } else {
+      logger.warn(marker, msg);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void warn(Marker marker, String format, Object arg) {
+    if (!logger.isWarnEnabled())
+      return;
+    if (instanceofLAL) {
+      String formattedMessage = MessageFormatter.format(format, arg);
+      ((LocationAwareLogger) logger).log(marker, fqcn,
+          LocationAwareLogger.WARN_INT, formattedMessage, null);
+    } else {
+      logger.warn(marker, format, arg);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void warn(Marker marker, String format, Object arg1, Object arg2) {
+    if (!logger.isWarnEnabled())
+      return;
+    if (instanceofLAL) {
+      String formattedMessage = MessageFormatter.format(format, arg1, arg2);
+      ((LocationAwareLogger) logger).log(marker, fqcn,
+          LocationAwareLogger.WARN_INT, formattedMessage, null);
+    } else {
+      logger.warn(marker, format, arg1, arg2);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void warn(Marker marker, String format, Object[] argArray) {
+    if (!logger.isWarnEnabled())
+      return;
+    if (instanceofLAL) {
+      String formattedMessage = MessageFormatter.arrayFormat(format, argArray);
+      ((LocationAwareLogger) logger).log(marker, fqcn,
+          LocationAwareLogger.WARN_INT, formattedMessage, null);
+    } else {
+      logger.warn(marker, format, argArray);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void warn(Marker marker, String msg, Throwable t) {
+    if (!logger.isWarnEnabled())
+      return;
+    if (instanceofLAL) {
+      ((LocationAwareLogger) logger).log(marker, fqcn,
+          LocationAwareLogger.WARN_INT, msg, t);
+    } else {
+      logger.warn(marker, msg, t);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public boolean isErrorEnabled() {
+    return logger.isErrorEnabled();
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public boolean isErrorEnabled(Marker marker) {
+    return logger.isErrorEnabled(marker);
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void error(String msg) {
+    if (!logger.isErrorEnabled())
+      return;
+
+    if (instanceofLAL) {
+      ((LocationAwareLogger) logger).log(null, fqcn,
+          LocationAwareLogger.ERROR_INT, msg, null);
+    } else {
+      logger.error(msg);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void error(String format, Object arg) {
+    if (!logger.isErrorEnabled())
+      return;
+
+    if (instanceofLAL) {
+      String formattedMessage = MessageFormatter.format(format, arg);
+      ((LocationAwareLogger) logger).log(null, fqcn,
+          LocationAwareLogger.ERROR_INT, formattedMessage, null);
+    } else {
+      logger.error(format, arg);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void error(String format, Object arg1, Object arg2) {
+    if (!logger.isErrorEnabled())
+      return;
+
+    if (instanceofLAL) {
+      String formattedMessage = MessageFormatter.format(format, arg1, arg2);
+      ((LocationAwareLogger) logger).log(null, fqcn,
+          LocationAwareLogger.ERROR_INT, formattedMessage, null);
+    } else {
+      logger.error(format, arg1, arg2);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void error(String format, Object[] argArray) {
+    if (!logger.isErrorEnabled())
+      return;
+
+    if (instanceofLAL) {
+      String formattedMessage = MessageFormatter.arrayFormat(format, argArray);
+      ((LocationAwareLogger) logger).log(null, fqcn,
+          LocationAwareLogger.ERROR_INT, formattedMessage, null);
+    } else {
+      logger.error(format, argArray);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void error(String msg, Throwable t) {
+    if (!logger.isErrorEnabled())
+      return;
+
+    if (instanceofLAL) {
+      ((LocationAwareLogger) logger).log(null, fqcn,
+          LocationAwareLogger.ERROR_INT, msg, t);
+    } else {
+      logger.error(msg, t);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void error(Marker marker, String msg) {
+    if (!logger.isErrorEnabled())
+      return;
+    if (instanceofLAL) {
+      ((LocationAwareLogger) logger).log(marker, fqcn,
+          LocationAwareLogger.ERROR_INT, msg, null);
+    } else {
+      logger.error(marker, msg);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void error(Marker marker, String format, Object arg) {
+    if (!logger.isErrorEnabled())
+      return;
+    if (instanceofLAL) {
+      String formattedMessage = MessageFormatter.format(format, arg);
+      ((LocationAwareLogger) logger).log(marker, fqcn,
+          LocationAwareLogger.ERROR_INT, formattedMessage, null);
+    } else {
+      logger.error(marker, format, arg);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void error(Marker marker, String format, Object arg1, Object arg2) {
+    if (!logger.isErrorEnabled())
+      return;
+    if (instanceofLAL) {
+      String formattedMessage = MessageFormatter.format(format, arg1, arg2);
+      ((LocationAwareLogger) logger).log(marker, fqcn,
+          LocationAwareLogger.ERROR_INT, formattedMessage, null);
+    } else {
+      logger.error(marker, format, arg1, arg2);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void error(Marker marker, String format, Object[] argArray) {
+    if (!logger.isErrorEnabled())
+      return;
+    if (instanceofLAL) {
+      String formattedMessage = MessageFormatter.arrayFormat(format, argArray);
+      ((LocationAwareLogger) logger).log(marker, fqcn,
+          LocationAwareLogger.ERROR_INT, formattedMessage, null);
+    } else {
+      logger.error(marker, format, argArray);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public void error(Marker marker, String msg, Throwable t) {
+    if (!logger.isErrorEnabled())
+      return;
+    if (instanceofLAL) {
+      ((LocationAwareLogger) logger).log(marker, fqcn,
+          LocationAwareLogger.ERROR_INT, msg, t);
+    } else {
+      logger.error(marker, msg, t);
+    }
+  }
+
+  /**
+   * Delegate to the appropriate method of the underlying logger.
+   */
+  public String getName() {
+    return logger.getName();
+  }
+}

Modified: slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/ext/XLogger.java
==============================================================================
--- slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/ext/XLogger.java	(original)
+++ slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/ext/XLogger.java	Wed Oct  1 18:20:09 2008
@@ -4,7 +4,6 @@
 import org.slf4j.Marker;
 import org.slf4j.MarkerFactory;
 import org.slf4j.helpers.MessageFormatter;
-import org.slf4j.helpers.NOPLogger;
 import org.slf4j.spi.LocationAwareLogger;
 
 /**
@@ -14,7 +13,7 @@
  * @author Ralph Goers
  * @author Ceki Gulcu
  */
-public class XLogger implements Logger {
+public class XLogger extends LoggerWrapper implements Logger {
 
   private static final String FQCN = XLogger.class.getName();
   static Marker FLOW_MARKER = MarkerFactory.getMarker("FLOW");
@@ -48,22 +47,14 @@
     ENTRY_MESSAGE_ARRAY[4] = ENTRY_MESSAGE_4;
   }
 
-  final Logger logger;
-
   /**
    * Given an underlying logger, constuct an XLogger
    * 
-   * @param logger underlying logger
+   * @param logger
+   *                underlying logger
    */
   public XLogger(Logger logger) {
-
-    if (logger instanceof LocationAwareLogger) {
-      this.logger = logger;
-    } else {
-      // if the logger is not location aware, assume that
-      // there is no point in further effort
-      this.logger = NOPLogger.NOP_LOGGER;
-    }
+    super(logger, FQCN);
   }
 
   /**
@@ -73,7 +64,7 @@
    *                supplied parameters
    */
   public void entry(Object... argArray) {
-    if (logger.isTraceEnabled(ENTRY_MARKER)) {
+    if (instanceofLAL && logger.isTraceEnabled(ENTRY_MARKER)) {
       String messagePattern = null;
       if (argArray.length <= ENTRY_MESSAGE_ARRAY_LEN) {
         messagePattern = ENTRY_MESSAGE_ARRAY[argArray.length];
@@ -91,7 +82,7 @@
    * Log method exit
    */
   public void exit() {
-    if (logger.isTraceEnabled(ENTRY_MARKER)) {
+    if (instanceofLAL && logger.isTraceEnabled(ENTRY_MARKER)) {
       ((LocationAwareLogger) logger).log(EXIT_MARKER, FQCN,
           LocationAwareLogger.TRACE_INT, EXIT_MESSAGE_0, null);
     }
@@ -104,7 +95,7 @@
    *                The result of the method being exited
    */
   public void exit(Object result) {
-    if (logger.isTraceEnabled(ENTRY_MARKER)) {
+    if (instanceofLAL && logger.isTraceEnabled(ENTRY_MARKER)) {
       String formattedMessage = MessageFormatter.format(EXIT_MESSAGE_0, result);
       ((LocationAwareLogger) logger).log(EXIT_MARKER, FQCN,
           LocationAwareLogger.TRACE_INT, formattedMessage, null);
@@ -118,8 +109,10 @@
    *                the exception being caught.
    */
   public void throwing(Throwable throwable) {
-    ((LocationAwareLogger) logger).log(THROWING_MARKER, FQCN,
-        LocationAwareLogger.ERROR_INT, "throwing", throwable);
+    if (instanceofLAL) {
+      ((LocationAwareLogger) logger).log(THROWING_MARKER, FQCN,
+          LocationAwareLogger.ERROR_INT, "throwing", throwable);
+    }
   }
 
   /**
@@ -129,8 +122,10 @@
    *                the exception being caught.
    */
   public void catching(Throwable throwable) {
-    ((LocationAwareLogger) logger).log(CATCHING_MARKER, FQCN,
-        LocationAwareLogger.ERROR_INT, "catching", throwable);
+    if (instanceofLAL) {
+      ((LocationAwareLogger) logger).log(CATCHING_MARKER, FQCN,
+          LocationAwareLogger.ERROR_INT, "catching", throwable);
+    }
   }
 
   private static String buildMessagePattern(int len) {
@@ -144,440 +139,4 @@
     sb.append(')');
     return sb.toString();
   }
-
-  // =====================================
-  // org.slf4j.Logger methods
-  // =====================================
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public boolean isTraceEnabled() {
-    return logger.isTraceEnabled();
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public boolean isTraceEnabled(Marker marker) {
-    return logger.isTraceEnabled(marker);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void trace(String msg) {
-    logger.trace(msg);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void trace(String format, Object arg) {
-    logger.trace(format, arg);
-  }
-  
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void trace(String format, Object arg1, Object arg2) {
-    logger.trace(format, arg1, arg2);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void trace(String format, Object[] argArray) {
-    logger.trace(format, argArray);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void trace(String msg, Throwable t) {
-    logger.trace(msg, t);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void trace(Marker marker, String msg) {
-    logger.trace(marker, msg);
-  }
-  
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void trace(Marker marker, String format, Object arg) {
-    logger.trace(marker, format, arg);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void trace(Marker marker, String format, Object arg1, Object arg2) {
-    logger.trace(marker, format, arg1, arg2);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void trace(Marker marker, String format, Object[] argArray) {
-    logger.trace(marker, format, argArray);
-  }
-  
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void trace(Marker marker, String msg, Throwable t) {
-    logger.trace(marker, msg, t);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public boolean isDebugEnabled() {
-    return logger.isDebugEnabled();
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public boolean isDebugEnabled(Marker marker) {
-    return logger.isDebugEnabled(marker);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void debug(String msg) {
-    logger.debug(msg);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void debug(String format, Object arg) {
-    logger.debug(format, arg);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void debug(String format, Object arg1, Object arg2) {
-    logger.debug(format, arg1, arg2);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void debug(String format, Object[] argArray) {
-    logger.debug(format, argArray);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void debug(String msg, Throwable t) {
-    logger.debug(msg, t);
-  }
-  
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void debug(Marker marker, String msg) {
-    logger.debug(marker, msg);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void debug(Marker marker, String format, Object arg) {
-    logger.debug(marker, format, arg);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void debug(Marker marker, String format, Object arg1, Object arg2) {
-    logger.debug(marker, format, arg1, arg2);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void debug(Marker marker, String format, Object[] argArray) {
-    logger.debug(marker, format, argArray);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void debug(Marker marker, String msg, Throwable t) {
-    logger.debug(marker, msg, t);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public boolean isInfoEnabled() {
-    return logger.isInfoEnabled();
-  }
-  
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public boolean isInfoEnabled(Marker marker) {
-    return logger.isInfoEnabled(marker);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void info(String msg) {
-    logger.info(msg);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void info(String format, Object arg) {
-    logger.info(format, arg);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void info(String format, Object arg1, Object arg2) {
-    logger.info(format, arg1, arg2);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void info(String format, Object[] argArray) {
-    logger.info(format, argArray);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void info(String msg, Throwable t) {
-    logger.info(msg, t);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void info(Marker marker, String msg) {
-    logger.info(marker, msg);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void info(Marker marker, String format, Object arg) {
-    logger.info(marker, format, arg);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void info(Marker marker, String format, Object arg1, Object arg2) {
-    logger.info(marker, format, arg1, arg2);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void info(Marker marker, String format, Object[] argArray) {
-    logger.info(marker, format, argArray);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void info(Marker marker, String msg, Throwable t) {
-    logger.info(marker, msg, t);
-  }
-
-  public boolean isWarnEnabled() {
-    return logger.isWarnEnabled();
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public boolean isWarnEnabled(Marker marker) {
-    return logger.isWarnEnabled(marker);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void warn(String msg) {
-    logger.warn(msg);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void warn(String format, Object arg) {
-    logger.warn(format, arg);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void warn(String format, Object arg1, Object arg2) {
-    logger.warn(format, arg1, arg2);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void warn(String format, Object[] argArray) {
-    logger.warn(format, argArray);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void warn(String msg, Throwable t) {
-    logger.warn(msg, t);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void warn(Marker marker, String msg) {
-    logger.warn(marker, msg);
-  }
-  
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void warn(Marker marker, String format, Object arg) {
-    logger.warn(marker, format, arg);
-  }
-  
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void warn(Marker marker, String format, Object arg1, Object arg2) {
-    logger.warn(marker, format, arg1, arg2);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void warn(Marker marker, String format, Object[] argArray) {
-    logger.warn(marker, format, argArray);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void warn(Marker marker, String msg, Throwable t) {
-    logger.warn(marker, msg, t);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public boolean isErrorEnabled() {
-    return logger.isErrorEnabled();
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public boolean isErrorEnabled(Marker marker) {
-    return logger.isErrorEnabled(marker);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void error(String msg) {
-    logger.error(msg);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void error(String format, Object arg) {
-    logger.error(format, arg);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void errot(String format, Object arg1, Object arg2) {
-    logger.error(format, arg1, arg2);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void error(String format, Object[] argArray) {
-    logger.error(format, argArray);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void error(String msg, Throwable t) {
-    logger.error(msg, t);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void error(Marker marker, String msg) {
-    logger.error(marker, msg);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void error(Marker marker, String format, Object arg) {
-    logger.error(marker, format, arg);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void error(String format, Object arg1, Object arg2) {
-    logger.error(format, arg1, arg2);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void error(Marker marker, String format, Object arg1, Object arg2) {
-    logger.error(marker, format, arg1, arg2);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void error(Marker marker, String format, Object[] argArray) {
-    logger.error(marker, format, argArray);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public void error(Marker marker, String msg, Throwable t) {
-    logger.error(marker, msg, t);
-  }
-
-  /**
-   * Delegate to the appropriate method of the underlying logger.
-   */
-  public String getName() {
-    return logger.getName();
-  }
-
 }

Added: slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/ext/XLoggerFactory.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/ext/XLoggerFactory.java	Wed Oct  1 18:20:09 2008
@@ -0,0 +1,30 @@
+package org.slf4j.ext;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * 
+ * This class is essentially a wrapper around an
+ * {@link LoggerFactory} producing {@link XLogger} instances.
+ * 
+ * <p>Contrary to {@link LoggerFactory#getLogger(String)} method of 
+ * {@link LoggerFactory}, each call to {@link getXLogger} 
+ * produces a new instance of XLogger. This should not matter because an 
+ * XLogger instance does not have any state beyond that of the Logger instance 
+ * it wraps.
+ * 
+ * @author Ralph Goers
+ * @author Ceki Gulcu
+ */
+public class XLoggerFactory {
+
+  public static XLogger getXLogger(String name) {
+    return new XLogger(LoggerFactory.getLogger(name));
+  }
+
+  @SuppressWarnings("unchecked")
+  public static Logger getXLogger(Class clazz) {
+    return getXLogger(clazz.getName());
+  }
+}



More information about the slf4j-dev mailing list