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

ceki at slf4j.org ceki at slf4j.org
Tue Dec 27 11:21:54 CET 2005


Author: ceki
Date: Tue Dec 27 11:21:52 2005
New Revision: 470

Modified:
   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/MSimpleLogger.java
   slf4j/trunk/src/java/org/slf4j/impl/NOPLogger.java
   slf4j/trunk/src/java/org/slf4j/impl/SimpleLogger.java
Log:

added missing printing methods for supporting array arguments

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	Tue Dec 27 11:21:52 2005
@@ -97,7 +97,7 @@
    * is disabled for the DEBUG level. </p>
    *
    * @param format the format string
-   * @param argArray  an array of arguments
+   * @param argArray an array of arguments
    */
   public void debug(String format, Object[] argArray);
   
@@ -154,6 +154,18 @@
   public void info(String format, Object arg1, Object arg2);
 
   /**
+   * Log a message at the INFO level according to the specified format
+   * and arguments.
+   * 
+   * <p>This form avoids superfluous object creation when the logger
+   * is disabled for the INFO level. </p>
+   *
+   * @param format the format string
+   * @param argArray an array of arguments
+   */
+  public void info(String format, Object[] argArray);
+  
+  /**
    * Log an exception (throwable) at the INFO level with an
    * accompanying message. 
    * 
@@ -188,6 +200,19 @@
    */
   public void warn(String format, Object arg);
 
+  
+  /**
+   * Log a message at the WARN level according to the specified format
+   * and arguments.
+   * 
+   * <p>This form avoids superfluous object creation when the logger
+   * is disabled for the WARN level. </p>
+   *
+   * @param format the format string
+   * @param argArray an array of arguments
+   */
+  public void warn(String format, Object[] argArray);
+  
   /**
    * Log a message at the WARN level according to the specified format
    * and arguments.
@@ -251,6 +276,18 @@
   public void error(String format, Object arg1, Object arg2);
 
   /**
+   * Log a message at the ERROR level according to the specified format
+   * and arguments.
+   * 
+   * <p>This form avoids superfluous object creation when the logger
+   * is disabled for the ERROR level. </p>
+   *
+   * @param format the format string
+   * @param argArray an array of arguments
+   */
+  public void error(String format, Object[] argArray);
+  
+  /**
    * Log an exception (throwable) at the ERROR level with an
    * accompanying message. 
    * 

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	Tue Dec 27 11:21:52 2005
@@ -121,13 +121,27 @@
       log.debug(msgStr);
     }
   }
+  
 
+  /**
+   * Delegates to the {@link Log#debug(java.lang.Object)} method of the underlying
+   * {@link Log} instance.
+   * 
+   * <p>
+   * However, this form avoids superfluous object creation when the logger is disabled
+   * for level DEBUG.
+   * </p>
+   * 
+   * @param format the format string
+   * @param argArray an array of arguments
+   */
   public void debug(String format, Object[] argArray) {
     if (log.isDebugEnabled()) {
       String msgStr = MessageFormatter.arrayFormat(format, argArray);
       log.debug(msgStr);
     }
   }
+  
   /**
    * Delegates to the {@link Log#debug(java.lang.Object, java.lang.Throwable)} method of 
    * the underlying {@link Log} instance.
@@ -204,6 +218,26 @@
   }
 
   /**
+   * Delegates to the {@link Log#info(java.lang.Object)} method of the underlying
+   * {@link Log} instance.
+   * 
+   * <p>
+   * However, this form avoids superfluous object creation when the logger is disabled
+   * for level INFO.
+   * </p>
+   * 
+   * @param format the format string
+   * @param argArray an array of arguments
+   */
+  public void info(String format, Object[] argArray) {
+    if (log.isInfoEnabled()) {
+      String msgStr = MessageFormatter.arrayFormat(format, argArray);
+      log.info(msgStr);
+    }
+  }
+  
+  
+  /**
    * Delegates to the {@link Log#info(java.lang.Object, java.lang.Throwable)} method of 
    * the underlying {@link Log} instance.
    * 
@@ -277,6 +311,26 @@
       log.warn(msgStr);
     }
   }
+  
+  /**
+   * Delegates to the {@link Log#warn(java.lang.Object)} method of the underlying
+   * {@link Log} instance.
+   * 
+   * <p>
+   * However, this form avoids superfluous object creation when the logger is disabled
+   * for level WARN.
+   * </p>
+   * 
+   * @param format the format string
+   * @param argArray an array of arguments
+   */
+  public void warn(String format, Object[] argArray) {
+    if (log.isWarnEnabled()) {
+      String msgStr = MessageFormatter.arrayFormat(format, argArray);
+      log.warn(msgStr);
+    }
+  }
+  
 
   /**
    * Delegates to the {@link Log#warn(java.lang.Object, java.lang.Throwable)} method of 
@@ -356,6 +410,26 @@
   }
 
   /**
+   * Delegates to the {@link Log#error(java.lang.Object)} method of the underlying
+   * {@link Log} instance.
+   * 
+   * <p>
+   * However, this form avoids superfluous object creation when the logger is disabled
+   * for level ERROR.
+   * </p>
+   * 
+   * @param format the format string
+   * @param argArray an array of arguments
+   */
+  public void error(String format, Object[] argArray) {
+    if (log.isErrorEnabled()) {
+      String msgStr = MessageFormatter.arrayFormat(format, argArray);
+      log.error(msgStr);
+    }
+  }
+  
+  
+  /**
    * Delegates to the {@link Log#error(java.lang.Object, java.lang.Throwable)} method of 
    * the underlying {@link Log} instance.
    * 

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	Tue Dec 27 11:21:52 2005
@@ -114,6 +114,16 @@
   }
 
   
+  /**
+   * Log a message at level FINE according to the specified format and
+   * arguments.
+   *
+   * <p>This form avoids superfluous object creation when the logger
+   * is disabled for the FINE level. </p>
+   *
+   * @param format the format string
+   * @param argArray an array of arguments
+   */
   public void debug(String format, Object[] argArray) {
     if (logger.isLoggable(Level.FINE)) {
       String msgStr = MessageFormatter.arrayFormat(format, argArray);
@@ -186,6 +196,25 @@
       logger.info(msgStr);
     }
   }
+  
+  /**
+   * Log a message at level INFO according to the specified format and
+   * arguments.
+   *
+   * <p>This form avoids superfluous object creation when the logger
+   * is disabled for the INFO level. </p>
+   *
+   * @param format the format string
+   * @param argArray an array of arguments
+   */
+  public void info(String format, Object[] argArray) {
+    if (logger.isLoggable(Level.INFO)) {
+      String msgStr = MessageFormatter.arrayFormat(format, argArray);
+      logger.info(msgStr);
+    }
+  }
+  
+
 
   /**
    * Log an exception (throwable) at the INFO level with an
@@ -253,6 +282,23 @@
   }
 
   /**
+   * Log a message at level WARNING according to the specified format and
+   * arguments.
+   *
+   * <p>This form avoids superfluous object creation when the logger
+   * is disabled for the WARNING level. </p>
+   *
+   * @param format the format string
+   * @param argArray an array of arguments
+   */
+  public void warn(String format, Object[] argArray) {
+    if (logger.isLoggable(Level.WARNING)) {
+      String msgStr = MessageFormatter.arrayFormat(format, argArray);
+      logger.warning(msgStr);
+    }
+  }
+  
+  /**
    * Log an exception (throwable) at the WARNING level with an
    * accompanying message.
    *
@@ -317,6 +363,24 @@
     }
   }
 
+  
+  /**
+   * Log a message at level INFO according to the specified format and
+   * arguments.
+   *
+   * <p>This form avoids superfluous object creation when the logger
+   * is disabled for the INFO level. </p>
+   *
+   * @param format the format string
+   * @param argArray an array of arguments
+   */
+  public void error(String format, Object[] argArray) {
+    if (logger.isLoggable(Level.SEVERE)) {
+      String msgStr = MessageFormatter.arrayFormat(format, argArray);
+      logger.severe(msgStr);
+    }
+  }
+  
   /**
    * Log an exception (throwable) at the SEVERE level with an
    * accompanying message.

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	Tue Dec 27 11:21:52 2005
@@ -119,6 +119,16 @@
     }
   }
   
+  /**
+   * Log a message at level DEBUG according to the specified format and
+   * arguments.
+   *
+   * <p>This form avoids superfluous object creation when the logger
+   * is disabled for the DEBUG level. </p>
+   *
+   * @param format the format string
+   * @param argArray an array of arguments
+   */
   public void debug(String format, Object[] argArray) {
     if (logger.isDebugEnabled()) {
       String msgStr = MessageFormatter.arrayFormat(format, argArray);
@@ -192,6 +202,23 @@
   }
 
   /**
+   * Log a message at level INFO according to the specified format and
+   * arguments.
+   *
+   * <p>This form avoids superfluous object creation when the logger
+   * is disabled for the INFO level. </p>
+   *
+   * @param format the format string
+   * @param argArray an array of arguments
+   */
+  public void info(String format, Object[] argArray) {
+    if (logger.isInfoEnabled()) {
+      String msgStr = MessageFormatter.arrayFormat(format, argArray);
+      logger.log(FQCN, Level.INFO, msgStr, null);
+    }
+  }
+
+  /**
    * Log an exception (throwable) at the INFO level with an
    * accompanying message.
    *
@@ -257,6 +284,24 @@
   }
 
   /**
+   * Log a message at level WARN according to the specified format and
+   * arguments.
+   *
+   * <p>This form avoids superfluous object creation when the logger
+   * is disabled for the WARN level. </p>
+   *
+   * @param format the format string
+   * @param argArray an array of arguments
+   */
+  public void warn(String format, Object[] argArray) {
+    if (logger.isEnabledFor(Level.WARN)) {
+      String msgStr = MessageFormatter.arrayFormat(format, argArray);
+      logger.log(FQCN, Level.WARN, msgStr, null);
+    }
+  }
+
+  
+  /**
    * Log an exception (throwable) at the WARN level with an
    * accompanying message.
    *
@@ -322,6 +367,25 @@
   }
 
   /**
+   * Log a message at level ERROR according to the specified format and
+   * arguments.
+   *
+   * <p>This form avoids superfluous object creation when the logger
+   * is disabled for the ERROR level. </p>
+   *
+   * @param format the format string
+   * @param argArray an array of arguments
+   */
+  public void error(String format, Object[] argArray) {
+    if (logger.isEnabledFor(Level.ERROR)) {
+      String msgStr = MessageFormatter.arrayFormat(format, argArray);
+      logger.log(FQCN, Level.ERROR, msgStr, null);
+    }
+  }
+
+  
+  
+  /**
    * Log an exception (throwable) at the ERROR level with an
    * accompanying message.
    *

Modified: slf4j/trunk/src/java/org/slf4j/impl/MSimpleLogger.java
==============================================================================
--- slf4j/trunk/src/java/org/slf4j/impl/MSimpleLogger.java	(original)
+++ slf4j/trunk/src/java/org/slf4j/impl/MSimpleLogger.java	Tue Dec 27 11:21:52 2005
@@ -36,10 +36,9 @@
 import org.slf4j.Marker;
 import org.slf4j.MarkingLogger;
 
-
 /**
- * A simple (and direct) implementation that logs messages of level
- * INFO or higher on the console (<code>System.out<code>).
+ * A simple (and direct) implementation that logs messages of level INFO or
+ * higher on the console (<code>System.out<code>).
  *
  * <p>The output includes the relative time in milliseconds, thread
  * name, the level, logger name, and the message followed by the line
@@ -48,17 +47,17 @@
  *
  * <p>Sample output follows.</p>
  * <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:
-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.
-346 [main] ERROR examples.SortAlgo - Tried to dump an uninitialized array.
-        at org.log4j.examples.SortAlgo.dump(SortAlgo.java:58)
-        at org.log4j.examples.Sort.main(Sort.java:64)
-467 [main] INFO  examples.Sort - Exiting main method.
-</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:
+ *  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.
+ *  346 [main] ERROR examples.SortAlgo - Tried to dump an uninitialized array.
+ *  at org.log4j.examples.SortAlgo.dump(SortAlgo.java:58)
+ *  at org.log4j.examples.Sort.main(Sort.java:64)
+ *  467 [main] INFO  examples.Sort - Exiting main method.
+ * </pre>
  *
  * @author Ceki G&uuml;lc&uuml;
  */
@@ -67,11 +66,16 @@
    * Mark the time when this class gets loaded into memory.
    */
   private static long startTime = System.currentTimeMillis();
-  public static final String LINE_SEPARATOR =
-    System.getProperty("line.separator");
+
+  public static final String LINE_SEPARATOR = System
+      .getProperty("line.separator");
+
   private static String INFO_STR = "INFO";
+
   private static String WARN_STR = "WARN";
+
   private static String ERROR_STR = "ERROR";
+
   String name;
 
   /**
@@ -83,10 +87,12 @@
   }
 
   public String getName() {
-    return name;    
+    return name;
   }
+
   /**
    * Always returns false.
+   * 
    * @return always false
    */
   public boolean isDebugEnabled() {
@@ -95,31 +101,32 @@
 
   /**
    * Always returns false.
+   * 
    * @return always false
    */
   public boolean isDebugEnabled(Marker marker) {
     return false;
   }
-  
+
   /**
-   * A NOP implementation, as this logger is permanently disabled for
-   * the DEBUG level.
+   * A NOP implementation, as this logger is permanently disabled for the DEBUG
+   * level.
    */
   public void debug(String msg) {
     // NOP
   }
 
   /**
-   * A NOP implementation, as this logger is permanently disabled for
-   * the DEBUG level.
+   * A NOP implementation, as this logger is permanently disabled for the DEBUG
+   * level.
    */
   public void debug(String format, Object param1) {
     // NOP
   }
 
   /**
-   * A NOP implementation, as this logger is permanently disabled for
-   * the DEBUG level.
+   * A NOP implementation, as this logger is permanently disabled for the DEBUG
+   * level.
    */
   public void debug(String format, Object param1, Object param2) {
     // NOP
@@ -128,10 +135,10 @@
   public void debug(String format, Object[] argArray) {
     // NOP
   }
-  
+
   /**
-   * A NOP implementation, as this logger is permanently disabled for
-   * the DEBUG level.
+   * A NOP implementation, as this logger is permanently disabled for the DEBUG
+   * level.
    */
   public void debug(String msg, Throwable t) {
     // NOP
@@ -155,7 +162,7 @@
   /**
    * This is our internal implementation for logging regular (non-parameterized)
    * log messages.
-   *
+   * 
    * @param level
    * @param message
    * @param t
@@ -189,19 +196,31 @@
 
   /**
    * For formatted messages, first substitute arguments and then log.
-   *
+   * 
    * @param level
    * @param format
    * @param param1
    * @param param2
    */
-  private void formatAndLog(
-    String level, String format, Object arg1, Object arg2) {
+  private void formatAndLog(String level, String format, Object arg1,
+      Object arg2) {
     String message = MessageFormatter.format(format, arg1, arg2);
     log(level, message, null);
   }
 
   /**
+   * For formatted messages, first substitute arguments and then log.
+   * 
+   * @param level
+   * @param format
+   * @param argArray
+   */
+  private void formatAndLog(String level, String format, Object[] argArray) {
+    String message = MessageFormatter.arrayFormat(format, argArray);
+    log(level, message, null);
+  }
+
+  /**
    * Always returns true.
    */
   public boolean isInfoEnabled() {
@@ -214,7 +233,7 @@
   public boolean isInfoEnabled(Marker marker) {
     return true;
   }
-  
+
   /**
    * A simple implementation which always logs messages of level INFO according
    * to the format outlined above.
@@ -240,6 +259,14 @@
   }
 
   /**
+   * Perform double parameter substituion before logging the message of level
+   * INFO according to the format outlined above.
+   */
+  public void info(String format, Object[] argArray) {
+    formatAndLog(INFO_STR, format, argArray);
+  }
+
+  /**
    * Log a message of level INFO, including an exception.
    */
   public void info(String msg, Throwable t) {
@@ -268,7 +295,7 @@
   public boolean isWarnEnabled() {
     return true;
   }
-  
+
   /**
    * Always returns true.
    */
@@ -279,7 +306,7 @@
   /**
    * A simple implementation which always logs messages of level WARN according
    * to the format outlined above.
-  */
+   */
   public void warn(String msg) {
     log(WARN_STR, msg.toString(), null);
   }
@@ -299,6 +326,14 @@
   public void warn(String format, Object arg1, Object arg2) {
     formatAndLog(WARN_STR, format, arg1, arg2);
   }
+  
+  /**
+   * Perform double parameter substituion before logging the message of level
+   * WARN according to the format outlined above.
+   */
+  public void warn(String format, Object[] argArray) {
+    formatAndLog(WARN_STR, format, argArray);
+  }
 
   /**
    * Log a message of level WARN, including an exception.
@@ -362,6 +397,15 @@
   }
 
   /**
+   * Perform double parameter substituion before logging the message of level
+   * WARN according to the format outlined above.
+   */
+  public void error(String format, Object[] argArray) {
+    formatAndLog(ERROR_STR, format, argArray);
+  }
+
+  
+  /**
    * Log a message of level ERROR, including an exception.
    */
   public void error(String msg, Throwable t) {

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	Tue Dec 27 11:21:52 2005
@@ -84,10 +84,13 @@
     // NOP
   }
 
-  final public void debug(String format, Object[] argArray) {
+  /** A NOP implementation.  */
+  public final void debug(String format, Object[] argArray) {
     // NOP
   }
   
+  
+  
   /** A NOP implementation. */
   final public void debug(String msg, Throwable t) {
     // NOP
@@ -117,6 +120,12 @@
   final public void info(String format, Object arg1, Object arg2) {
     // NOP
   }
+  
+  /** A NOP implementation.  */
+  public final void info(String format, Object[] argArray) {
+    // NOP
+  }
+
 
   /** A NOP implementation. */
   final public void info(String msg, Throwable t) {
@@ -146,6 +155,12 @@
   final public void warn(String format, Object arg1, Object arg2) {
     // NOP
   }
+  
+  /** A NOP implementation.  */
+  public final void warn(String format, Object[] argArray) {
+    // NOP
+  }
+
 
   /** A NOP implementation. */
   final public void warn(String msg, Throwable t) {
@@ -172,6 +187,12 @@
   final public void error(String format, Object arg1, Object arg2) {
     // NOP
   }
+  
+  /** A NOP implementation.  */
+  public final void error(String format, Object[] argArray) {
+    // NOP
+  }
+
 
   /** A NOP implementation. */
   final public void error(String msg, Throwable t) {

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	Tue Dec 27 11:21:52 2005
@@ -177,6 +177,18 @@
     String message = MessageFormatter.format(format, arg1, arg2);
     log(level, message, null);
   }
+  
+  /**
+   * For formatted messages, first substitute arguments and then log.
+   * 
+   * @param level
+   * @param format
+   * @param argArray
+   */
+  private void formatAndLog(String level, String format, Object[] argArray) {
+    String message = MessageFormatter.arrayFormat(format, argArray);
+    log(level, message, null);
+  }
 
   /**
    * Always returns true.
@@ -210,6 +222,15 @@
   }
 
   /**
+   * Perform double parameter substituion before logging the message of level
+   * INFO according to the format outlined above.
+   */
+  public void info(String format, Object[] argArray) {
+    formatAndLog(INFO_STR, format, argArray);
+  }
+
+
+  /**
    * Log a message of level INFO, including an exception.
    */
   public void info(String msg, Throwable t) {
@@ -248,6 +269,14 @@
   }
 
   /**
+   * Perform double parameter substituion before logging the message of level
+   * WARN according to the format outlined above.
+   */
+  public void warn(String format, Object[] argArray) {
+    formatAndLog(WARN_STR, format, argArray);
+  }
+
+  /**
    * Log a message of level WARN, including an exception.
    */
   public void warn(String msg, Throwable t) {
@@ -286,6 +315,15 @@
   }
 
   /**
+   * Perform double parameter substituion before logging the message of level
+   * ERROR according to the format outlined above.
+   */
+  public void error(String format, Object[] argArray) {
+    formatAndLog(ERROR_STR, format, argArray);
+  }
+
+  
+  /**
    * Log a message of level ERROR, including an exception.
    */
   public void error(String msg, Throwable t) {



More information about the slf4j-dev mailing list