[slf4j-dev] svn commit: r520 - in slf4j/trunk: . src/java/org/slf4j src/java/org/slf4j/impl tests/src/java/org/slf4j

ceki at slf4j.org ceki at slf4j.org
Thu Jan 26 14:11:15 CET 2006


Author: ceki
Date: Thu Jan 26 14:11:13 2006
New Revision: 520

Added:
   slf4j/trunk/src/java/org/slf4j/impl/WrappingLoggerAdapter.java
Modified:
   slf4j/trunk/build.xml
   slf4j/trunk/src/java/org/slf4j/Logger.java
   slf4j/trunk/src/java/org/slf4j/impl/JCLLoggerAdapter.java
   slf4j/trunk/src/java/org/slf4j/impl/JDK14LoggerAdapter.java
   slf4j/trunk/src/java/org/slf4j/impl/Log4jLoggerAdapter.java
   slf4j/trunk/src/java/org/slf4j/impl/NOPLogger.java
   slf4j/trunk/src/java/org/slf4j/impl/SimpleLogger.java
   slf4j/trunk/tests/src/java/org/slf4j/BasicMarkerTest.java
Log:

- Merged Logger and MakingLogger interfaces.
- Added the WrappingLoggerAdapter class which implements the methods handling 
  marker data by delegating to thier non-marker equivalents.
- Adapters to log systems now extend WrappingLoggerAdapter
- Minor adjustment in BasicMarkerTest 

Modified: slf4j/trunk/build.xml
==============================================================================
--- slf4j/trunk/build.xml	(original)
+++ slf4j/trunk/build.xml	Thu Jan 26 14:11:13 2006
@@ -194,6 +194,7 @@
 			      ${SLF4J_STEM}/spi/LoggerFactoryBinder.class,
                   ${SLF4J_STEM}/impl/MessageFormatter.class,
     	          ${SLF4J_STEM}/impl/Util.class,
+			      ${SLF4J_STEM}/impl/WrappingLoggerAdapter.class,
 		          ${SLF4J_STEM}/impl/StaticLoggerBinder.class,
                   ${SLF4J_STEM}/impl/${IMPL}*.class">
 			<manifest>

Modified: slf4j/trunk/src/java/org/slf4j/Logger.java
==============================================================================
--- slf4j/trunk/src/java/org/slf4j/Logger.java	(original)
+++ slf4j/trunk/src/java/org/slf4j/Logger.java	Thu Jan 26 14:11:13 2006
@@ -112,6 +112,68 @@
  
   
   /**
+   * Similar to {@link #isDebugEnabled()} method except that the
+   * marker data is also taken into account.
+   * 
+   * @param marker The marker data to take into consideration
+   */
+  public boolean isDebugEnabled(Marker marker);
+  
+  /**
+   * Log a message with the specific Marker at the DEBUG level.
+   * 
+   * @param marker the marker data specific to this log statement
+   * @param msg the message string to be logged
+   */
+  public void debug(Marker marker, String msg);
+  
+  /**
+   * This method is similar to {@link #debug(String, Object)} method except that the 
+   * marker data is also taken into consideration.
+   * 
+   * @param marker the marker data specific to this log statement
+   * @param format the format string
+   * @param arg the argument
+   */
+  public void debug(Marker marker, String format, Object arg);
+ 
+ 
+  /**
+   * This method is similar to {@link #debug(String, Object, Object)}
+   * method except that the marker data is also taken into
+   * consideration.
+   *
+   * @param marker the marker data specific to this log statement
+   * @param format  the format string
+   * @param arg1  the first argument
+   * @param arg2  the second argument
+   */
+  public void debug(Marker marker, String format, Object arg1, Object arg2);
+
+  /**
+   * This method is similar to {@link #debug(String, Object[])}
+   * method except that the marker data is also taken into
+   * consideration.
+   *
+   * @param marker the marker data specific to this log statement
+   * @param format  the format string
+   * @param argArray an array of arguments
+   */
+  public void debug(Marker marker, String format, Object[] argArray);
+
+  
+  /**
+   * This method is similar to {@link #debug(String, Throwable)} method except that the
+   * marker data is also taken into consideration.
+   * 
+   * @param marker the marker data specific to this log statement
+   * @param msg the message accompanying the exception
+   * @param t the exception (throwable) to log
+   */ 
+  public void debug(Marker marker, String msg, Throwable t);
+  
+  
+  /**
    * Is the logger instance enabled for the INFO level?
    * @return True if this Logger is enabled for the INFO level,
    * false otherwise.
@@ -175,6 +237,68 @@
   public void info(String msg, Throwable t);
 
   /**
+   * Similar to {@link #isInfoEnabled()} method except that the marker
+   * data is also taken into consideration.
+   *
+   * @param marker The marker data to take into consideration
+   */
+  public boolean isInfoEnabled(Marker marker);
+  
+  /**
+   * Log a message with the specific Marker at the INFO level.
+   * 
+   * @param marker The marker specific to this log statement
+   * @param msg the message string to be logged
+   */
+  public void info(Marker marker, String msg);
+  
+  /**
+   * This method is similar to {@link #info(String, Object)} method except that the 
+   * marker data is also taken into consideration.
+   *
+   * @param marker the marker data specific to this log statement
+   * @param format the format string
+   * @param arg the argument
+   */
+  public void info(Marker marker, String format, Object arg);
+  
+  /**
+   * This method is similar to {@link #info(String, Object, Object)}
+   * method except that the marker data is also taken into
+   * consideration.
+   * 
+   * @param marker the marker data specific to this log statement
+   * @param format  the format string
+   * @param arg1  the first argument
+   * @param arg2  the second argument
+   */
+  public void info(Marker marker, String format, Object arg1, Object arg2);  
+  
+  
+  /**
+   * This method is similar to {@link #info(String, Object[])}
+   * method except that the marker data is also taken into
+   * consideration.
+   *
+   * @param marker the marker data specific to this log statement
+   * @param format  the format string
+   * @param argArray an array of arguments
+   */
+  public void info(Marker marker, String format, Object[] argArray);
+
+  
+  /**
+   * This method is similar to {@link #info(String, Throwable)} method
+   * except that the marker data is also taken into consideration.
+   * 
+   * @param marker the marker data for this log statement
+   * @param msg the message accompanying the exception
+   * @param t the exception (throwable) to log
+   */ 
+  public void info(Marker marker, String msg, Throwable t); 
+
+  
+  /**
    * Is the logger instance enabled for the WARN level?
    * @return True if this Logger is enabled for the WARN level,
    * false otherwise.
@@ -237,6 +361,67 @@
   
 
   /**
+   * Similar to {@link #isWarnEnabled()} method except that the marker
+   * data is also taken into consideration.
+   *
+   * @param marker The marker data to take into consideration
+   */
+  public boolean isWarnEnabled(Marker marker);
+ 
+  /**
+   * Log a message with the specific Marker at the WARN level.
+   * 
+   * @param marker The marker specific to this log statement
+   * @param msg the message string to be logged
+   */
+  public void warn(Marker marker, String msg); 
+  
+  /**
+   * This method is similar to {@link #warn(String, Object)} method except that the 
+   * marker data is also taken into consideration.
+   * 
+   * @param marker the marker data specific to this log statement
+   * @param format the format string
+   * @param arg the argument
+   */
+  public void warn(Marker marker, String format, Object arg);
+  
+  /**
+   * This method is similar to {@link #warn(String, Object, Object)}
+   * method except that the marker data is also taken into
+   * consideration.
+   * 
+   * @param marker the marker data specific to this log statement
+   * @param format  the format string
+   * @param arg1  the first argument
+   * @param arg2  the second argument
+   */
+  public void warn(Marker marker, String format, Object arg1, Object arg2);  
+  
+  /**
+   * This method is similar to {@link #warn(String, Object[])}
+   * method except that the marker data is also taken into
+   * consideration.
+   *
+   * @param marker the marker data specific to this log statement
+   * @param format  the format string
+   * @param argArray an array of arguments
+   */
+  public void warn(Marker marker, String format, Object[] argArray);
+
+  
+  /**
+   * This method is similar to {@link #warn(String, Throwable)} method
+   * except that the marker data is also taken into consideration.
+   * 
+   * @param marker the marker data for this log statement
+   * @param msg the message accompanying the exception
+   * @param t the exception (throwable) to log
+   */ 
+  public void warn(Marker marker, String msg, Throwable t); 
+  
+
+  /**
    * Is the logger instance enabled for the ERROR level?
    * @return True if this Logger is enabled for the ERROR level,
    * false otherwise.
@@ -296,4 +481,66 @@
    */
   public void error(String msg, Throwable t);
 
+
+  /**
+   * Similar to {@link #isErrorEnabled()} method except that the
+   * marker data is also taken into consideration.
+   *
+   * @param marker The marker data to take into consideration
+   */
+  public boolean isErrorEnabled(Marker marker);
+  
+  /**
+   * Log a message with the specific Marker at the ERROR level.
+   * 
+   * @param marker The marker specific to this log statement
+   * @param msg the message string to be logged
+   */
+  public void error(Marker marker, String msg); 
+  
+  /**
+   * This method is similar to {@link #error(String, Object)} method except that the 
+   * marker data is also taken into consideration.
+   * 
+   * @param marker the marker data specific to this log statement
+   * @param format the format string
+   * @param arg the argument
+   */
+  public void error(Marker marker, String format, Object arg);
+  
+  /**
+   * This method is similar to {@link #error(String, Object, Object)}
+   * method except that the marker data is also taken into
+   * consideration.
+   * 
+   * @param marker the marker data specific to this log statement
+   * @param format  the format string
+   * @param arg1  the first argument
+   * @param arg2  the second argument
+   */
+  public void error(Marker marker, String format, Object arg1, Object arg2);  
+  
+  /**
+   * This method is similar to {@link #error(String, Object[])}
+   * method except that the marker data is also taken into
+   * consideration.
+   *
+   * @param marker the marker data specific to this log statement
+   * @param format  the format string
+   * @param argArray an array of arguments
+   */
+  public void error(Marker marker, String format, Object[] argArray);
+
+  
+  /**
+   * This method is similar to {@link #error(String, Throwable)}
+   * method except that the marker data is also taken into
+   * consideration.
+   * 
+   * @param marker the marker data specific to this log statement
+   * @param msg the message accompanying the exception
+   * @param t the exception (throwable) to log
+   */ 
+  public void error(Marker marker, String msg, Throwable t);
+
 }

Modified: slf4j/trunk/src/java/org/slf4j/impl/JCLLoggerAdapter.java
==============================================================================
--- slf4j/trunk/src/java/org/slf4j/impl/JCLLoggerAdapter.java	(original)
+++ slf4j/trunk/src/java/org/slf4j/impl/JCLLoggerAdapter.java	Thu Jan 26 14:11:13 2006
@@ -43,7 +43,7 @@
  * 
  * @author Ceki G&uuml;lc&uuml;
  */
-public final class JCLLoggerAdapter implements Logger {
+public final class JCLLoggerAdapter extends WrappingLoggerAdapter {
   final Log log;
   final String name;
   

Modified: slf4j/trunk/src/java/org/slf4j/impl/JDK14LoggerAdapter.java
==============================================================================
--- slf4j/trunk/src/java/org/slf4j/impl/JDK14LoggerAdapter.java	(original)
+++ slf4j/trunk/src/java/org/slf4j/impl/JDK14LoggerAdapter.java	Thu Jan 26 14:11:13 2006
@@ -45,7 +45,7 @@
  * 
  * @author Ceki G&uuml;lc&uuml;
  */
-public final class JDK14LoggerAdapter implements Logger {
+public final class JDK14LoggerAdapter extends WrappingLoggerAdapter {
   final java.util.logging.Logger logger;
 
   // WARN: JDK14LoggerAdapter constructor should have only package access so that

Modified: slf4j/trunk/src/java/org/slf4j/impl/Log4jLoggerAdapter.java
==============================================================================
--- slf4j/trunk/src/java/org/slf4j/impl/Log4jLoggerAdapter.java	(original)
+++ slf4j/trunk/src/java/org/slf4j/impl/Log4jLoggerAdapter.java	Thu Jan 26 14:11:13 2006
@@ -46,7 +46,7 @@
 
  * @author Ceki G&uuml;lc&uuml;
  */
-public final class Log4jLoggerAdapter implements Logger {
+public final class Log4jLoggerAdapter extends WrappingLoggerAdapter {
   final org.apache.log4j.Logger logger;
   
   /**

Modified: slf4j/trunk/src/java/org/slf4j/impl/NOPLogger.java
==============================================================================
--- slf4j/trunk/src/java/org/slf4j/impl/NOPLogger.java	(original)
+++ slf4j/trunk/src/java/org/slf4j/impl/NOPLogger.java	Thu Jan 26 14:11:13 2006
@@ -41,7 +41,7 @@
  *
  * @author Ceki G&uuml;lc&uuml;
  */
-public class NOPLogger implements Logger {
+public class NOPLogger extends WrappingLoggerAdapter {
   /**
    * The unique instance of NOPLogger.
    */

Modified: slf4j/trunk/src/java/org/slf4j/impl/SimpleLogger.java
==============================================================================
--- slf4j/trunk/src/java/org/slf4j/impl/SimpleLogger.java	(original)
+++ slf4j/trunk/src/java/org/slf4j/impl/SimpleLogger.java	Thu Jan 26 14:11:13 2006
@@ -33,9 +33,6 @@
 
 package org.slf4j.impl;
 
-import org.slf4j.Logger;
-
-
 /**
  * A simple (and direct) implementation that logs messages of level
  * INFO or higher on the console (<code>System.out<code>).
@@ -49,7 +46,7 @@
 <pre>
 176 [main] INFO examples.Sort - Populating an array of 2 elements in reverse order.
 225 [main] INFO examples.SortAlgo - Entered the sort method.
-304 [main] INFO examples.SortAlgo - Dump of interger array:
+304 [main] INFO examples.SortAlgo - Dump of integer array:
 317 [main] INFO examples.SortAlgo - Element [0] = 0
 331 [main] INFO examples.SortAlgo - Element [1] = 1
 343 [main] INFO examples.Sort - The next log statement should be an error message.
@@ -61,7 +58,7 @@
  *
  * @author Ceki G&uuml;lc&uuml;
  */
-public class SimpleLogger implements Logger {
+public class SimpleLogger extends WrappingLoggerAdapter {
   /**
    * Mark the time when this class gets loaded into memory.
    */
@@ -206,7 +203,7 @@
   }
 
   /**
-   * Perform single parameter substituion before logging the message of level
+   * Perform single parameter substitution before logging the message of level
    * INFO according to the format outlined above.
    */
   public void info(String format, Object arg) {
@@ -214,7 +211,7 @@
   }
 
   /**
-   * Perform double parameter substituion before logging the message of level
+   * Perform double parameter substitution before logging the message of level
    * INFO according to the format outlined above.
    */
   public void info(String format, Object arg1, Object arg2) {
@@ -222,7 +219,7 @@
   }
 
   /**
-   * Perform double parameter substituion before logging the message of level
+   * Perform double parameter substitution before logging the message of level
    * INFO according to the format outlined above.
    */
   public void info(String format, Object[] argArray) {
@@ -253,7 +250,7 @@
   }
 
   /**
-   * Perform single parameter substituion before logging the message of level
+   * Perform single parameter substitution before logging the message of level
    * WARN according to the format outlined above.
    */
   public void warn(String format, Object arg) {
@@ -261,7 +258,7 @@
   }
 
   /**
-   * Perform double parameter substituion before logging the message of level
+   * Perform double parameter substitution before logging the message of level
    * WARN according to the format outlined above.
    */
   public void warn(String format, Object arg1, Object arg2) {
@@ -269,7 +266,7 @@
   }
 
   /**
-   * Perform double parameter substituion before logging the message of level
+   * Perform double parameter substitution before logging the message of level
    * WARN according to the format outlined above.
    */
   public void warn(String format, Object[] argArray) {
@@ -291,7 +288,7 @@
   }
 
   /**
-   * A simple implementation which always logs messages of level ERROR acoording
+   * A simple implementation which always logs messages of level ERROR according
    * to the format outlined above.
    */
   public void error(String msg) {
@@ -299,7 +296,7 @@
   }
 
   /**
-   * Perform single parameter substituion before logging the message of level
+   * Perform single parameter substitution before logging the message of level
    * ERROR according to the format outlined above.
    */
   public void error(String format, Object arg) {
@@ -307,7 +304,7 @@
   }
 
   /**
-   * Perform double parameter substituion before logging the message of level
+   * Perform double parameter substitution before logging the message of level
    * ERROR according to the format outlined above.
    */
   public void error(String format, Object arg1, Object arg2) {
@@ -315,7 +312,7 @@
   }
 
   /**
-   * Perform double parameter substituion before logging the message of level
+   * Perform double parameter substitution before logging the message of level
    * ERROR according to the format outlined above.
    */
   public void error(String format, Object[] argArray) {

Added: slf4j/trunk/src/java/org/slf4j/impl/WrappingLoggerAdapter.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/src/java/org/slf4j/impl/WrappingLoggerAdapter.java	Thu Jan 26 14:11:13 2006
@@ -0,0 +1,115 @@
+// TOTO
+
+package org.slf4j.impl;
+
+import org.slf4j.Logger;
+import org.slf4j.Marker;
+
+/**
+ * This class serves as base for adapters for logging systems lacking Marker
+ * support. In this implementation, methods taking marker data simply invoke the
+ * corresponding method without the Marker argument, ignoring Marker data in the
+ * process.
+ * 
+ * @author Ceki Gulcu
+ */
+abstract class WrappingLoggerAdapter implements Logger {
+
+  public boolean isDebugEnabled(Marker marker) {
+    return isDebugEnabled();
+  }
+
+  public void debug(Marker marker, String msg) {
+    debug(msg);
+  }
+
+  public void debug(Marker marker, String format, Object arg) {
+    debug(format, arg);
+  }
+
+  public void debug(Marker marker, String format, Object arg1, Object arg2) {
+    debug(format, arg1, arg2);
+  }
+
+  public void debug(Marker marker, String format, Object[] argArray) {
+    debug(format, argArray);
+  }
+
+  public void debug(Marker marker, String msg, Throwable t) {
+    debug(msg, t);
+  }
+
+  public boolean isInfoEnabled(Marker marker) {
+    return isInfoEnabled();
+  }
+
+  public void info(Marker marker, String msg) {
+    info(msg);
+  }
+
+  public void info(Marker marker, String format, Object arg) {
+    info(format, arg);
+  }
+
+  public void info(Marker marker, String format, Object arg1, Object arg2) {
+    info(format, arg1, arg2);
+  }
+
+  public void info(Marker marker, String format, Object[] argArray) {
+    info(format, argArray);
+  }
+
+  public void info(Marker marker, String msg, Throwable t) {
+    info(msg, t);
+  }
+
+  public boolean isWarnEnabled(Marker marker) {
+    return isWarnEnabled();
+  }
+
+  public void warn(Marker marker, String msg) {
+    warn(msg);
+  }
+
+  public void warn(Marker marker, String format, Object arg) {
+    warn(format, arg);
+  }
+
+  public void warn(Marker marker, String format, Object arg1, Object arg2) {
+    warn(format, arg1, arg2);
+  }
+
+  public void warn(Marker marker, String format, Object[] argArray) {
+    warn(format, argArray);
+  }
+
+  public void warn(Marker marker, String msg, Throwable t) {
+    warn(msg, t);
+  }
+
+ 
+  public boolean isErrorEnabled(Marker marker) {
+    return isErrorEnabled();
+  }
+
+  public void error(Marker marker, String msg) {
+    error(msg);
+  }
+
+  public void error(Marker marker, String format, Object arg) {
+    error(format, arg);
+  }
+
+  public void error(Marker marker, String format, Object arg1, Object arg2) {
+    error(format, arg1, arg2);
+  }
+
+  public void error(Marker marker, String format, Object[] argArray) {
+    error(format, argArray);
+  }
+
+  public void error(Marker marker, String msg, Throwable t) {
+    error(msg, t);
+  }
+
+}

Modified: slf4j/trunk/tests/src/java/org/slf4j/BasicMarkerTest.java
==============================================================================
--- slf4j/trunk/tests/src/java/org/slf4j/BasicMarkerTest.java	(original)
+++ slf4j/trunk/tests/src/java/org/slf4j/BasicMarkerTest.java	Thu Jan 26 14:11:13 2006
@@ -47,6 +47,7 @@
   static final String COMP_STR = "COMP";
   static final String MULTI_COMP_STR = "MULTI_COMP";
   
+  final IMarkerFactory factory;
   final Marker blue;
   final Marker red;
   final Marker green;
@@ -54,7 +55,7 @@
   final Marker multiComp;
   
   public BasicMarkerTest() {
-    IMarkerFactory factory = new BasicMarkerFactory();
+    factory = new BasicMarkerFactory();
     
     blue = factory.getMarker(BLUE_STR);
     red = factory.getMarker(RED_STR);
@@ -71,7 +72,7 @@
     assertEquals(BLUE_STR, blue.getName());
     assertTrue(blue.contains(blue));
     
-    Marker blue2 = MarkerFactory.getMarker(BLUE_STR);
+    Marker blue2 = factory.getMarker(BLUE_STR);
     assertEquals(BLUE_STR, blue2.getName());
     assertEquals(blue, blue2);
     assertTrue(blue.contains(blue2));



More information about the slf4j-dev mailing list