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

ceki at slf4j.org ceki at slf4j.org
Tue Dec 27 10:25:01 CET 2005


Author: ceki
Date: Tue Dec 27 10:24:59 2005
New Revision: 468

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/MessageFormatter.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/InvokingSLF4J.java
   slf4j/trunk/tests/src/java/org/slf4j/impl/MLogger.java
   slf4j/trunk/tests/src/java/org/slf4j/impl/XLogger.java
Log:

- improved javadocs
- In Logger interface adding parameterized printing methods taking in an array as argument 

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 10:24:59 2005
@@ -90,6 +90,18 @@
   public void debug(String format, Object arg1, Object arg2);
 
   /**
+   * Log a message at the DEBUG level 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);
+  
+  /**
    * Log an exception (throwable) at the DEBUG 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 10:24:59 2005
@@ -122,6 +122,12 @@
     }
   }
 
+  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.

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 10:24:59 2005
@@ -113,6 +113,14 @@
     }
   }
 
+  
+  public void debug(String format, Object[] argArray) {
+    if (logger.isLoggable(Level.FINE)) {
+      String msgStr = MessageFormatter.arrayFormat(format, argArray);
+      logger.fine(msgStr);
+    }
+  }
+  
    /**
    * Log an exception (throwable) at  level FINE 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 10:24:59 2005
@@ -118,6 +118,13 @@
       logger.log(FQCN, Level.DEBUG, msgStr, null);
     }
   }
+  
+  public void debug(String format, Object[] argArray) {
+    if (logger.isDebugEnabled()) {
+      String msgStr = MessageFormatter.arrayFormat(format, argArray);
+      logger.log(FQCN, Level.DEBUG, msgStr, null);
+    }
+  }
 
   /**
    * Log an exception (throwable) at  level DEBUG with an

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 10:24:59 2005
@@ -125,6 +125,10 @@
     // NOP
   }
 
+  public void debug(String format, Object[] argArray) {
+    // NOP
+  }
+  
   /**
    * A NOP implementation, as this logger is permanently disabled for
    * the DEBUG level.

Modified: slf4j/trunk/src/java/org/slf4j/impl/MessageFormatter.java
==============================================================================
--- slf4j/trunk/src/java/org/slf4j/impl/MessageFormatter.java	(original)
+++ slf4j/trunk/src/java/org/slf4j/impl/MessageFormatter.java	Tue Dec 27 10:24:59 2005
@@ -35,11 +35,28 @@
 
 
 /**
- * Formats messages according to very simple rules. See {@link #format(String, Object)} and 
- * {@link #format(String, Object, Object)} for more details.
- *
- * @author Ceki G&uuml;lc&uuml;
- */
+  * Formats messages according to very simple substitution rules. Substitutions can be
+  * made 1, 2 or more arguments.
+  * <p>
+  * For example, 
+  * <pre>MessageFormatter.format("Hi {}.", "there");</pre> will
+  * return the string "Hi there.".
+  * <p>
+  * The {} pair is called the <em>formatting anchor</em>. It serves to designate the
+  * location where arguments need to be substituted within the message pattern.
+  * <p>
+  * In the rare case where you need to place the '{' or '}' in the message pattern 
+  * itself but do not want them to be interpreted as a formatting anchors, you can
+  * espace the '{' character with '\', that is the backslash character. Only the
+  * '{' character should be escaped. There is no need to escape the '}' character.  
+  * For example, <pre>MessageFormatter.format("File name is \\{{}}.", "App folder.zip");</pre>
+  * will return the string "File name is {App folder.zip}.". 
+  * 
+  * See {@link #format(String, Object)}, {@link #format(String, Object, Object)} 
+  * and {@link #arrayFormat(String, Object[])} methods for more details.
+  *
+  * @author Ceki G&uuml;lc&uuml;
+  */
 public class MessageFormatter {
   static final char DELIM_START = '{';
   static final char DELIM_STOP = '}';
@@ -48,21 +65,11 @@
    * Performs single argument substitution for the 'messagePattern' passed as
    * parameter.
    * <p>
-   * For example, <code>MessageFormatter.format("Hi {}.", "there");</code> will
+   * For example, <pre>MessageFormatter.format("Hi {}.", "there");</pre> will
    * return the string "Hi there.".
    * <p>
-   * The {} pair is called the formatting element. It serves to designate the
-   * location where the argument needs to be inserted within the pattern.
-   * <p>
-   * In the rare case where you need to place the '{' or '}' in the message pattern 
-   * but do not want them to be interpreted as a formatting element, then you can
-   * espace the '{' character with '\', that is the backslash character. Only the
-   * first '{' should be escaped. For example, 
-   * <code>MessageFormatter.format("File name is \\{{}}.", "App folder.zip");</code>
-   * will return the string "File name is {App folder.zip}.".
-   * 
    * @param messagePattern The message pattern which will be parsed and formatted
-   * @param argument The argument to be inserted instead of the formatting element
+   * @param argument The argument to be substituted in place of the formatting anchor
    * @return The formatted message
    */
   public static String format(String messagePattern, Object arg) {
@@ -74,24 +81,13 @@
    * Performs a two argument substitution for the 'messagePattern' passed as
    * parameter.
    * <p>
-   * For example, <code>MessageFormatter.format("Hi {}. My name is {}.", 
-   * "there", "David");</code> will return the string "Hi there. My name is David.".
-   * 
-   * <p>
-   * The '{}' pair is called a formatting element. It serves to designate the
-   * location where the arguments need to be inserted within the message pattern.
+   * For example, 
+   * <pre>MessageFormatter.format("Hi {}. My name is {}.", "Alice", "Bob");</pre> will 
+   * return the string "Hi Alice. My name is Bob.".
    * 
-   * <p>
-   * In the rare case where you need to place the '{' or '}' in the message pattern 
-   * but do not want them to be interpreted as a formatting element, then you can
-   * espace the '{' character with '\', that is the backslash character. Only the
-   * first '{' should be escaped. For example, 
-   * <code>MessageFormatter.format("File name is \\{{}}.", "App folder.zip");</code>
-   * will return the string "File name is {App folder.zip}.".
-  
    * @param messagePattern The message pattern which will be parsed and formatted
-   * @param arg1 The first argument to replace the first formatting element
-   * @param arg2 The second argument to replace the second formatting element
+   * @param arg1 The argument to be substituted in place of the first formatting anchor 
+   * @param arg2 The argument to be substituted in place of the second formatting anchor 
    * @return The formatted message
    */
   public static String format(String messagePattern, Object arg1, Object arg2) {
@@ -103,8 +99,8 @@
    * {@link #format(String, Object, Object)} methods except that
    * any number of arguments can be passed in an array.
    * 
-   * @param messagePattern
-   * @param argArray
+   * @param messagePattern The message pattern which will be parsed and formatted
+   * @param argArray An array of arguments to be substituted in place of formatting anchors
    * @return
    */
   public static String arrayFormat(String messagePattern, Object[] argArray) {

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 10:24:59 2005
@@ -84,6 +84,10 @@
     // NOP
   }
 
+  final public void debug(String format, Object[] argArray) {
+    // NOP
+  }
+  
   /** A NOP implementation. */
   final public void debug(String msg, Throwable t) {
     // NOP

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 10:24:59 2005
@@ -108,6 +108,7 @@
     // NOP
   }
 
+  
   /**
    * A NOP implementation, as this logger is permanently disabled for
    * the DEBUG level.
@@ -116,6 +117,10 @@
     // NOP
   }
 
+  public void debug(String format, Object[] argArray) {
+    // NOP
+  }
+  
   /**
    * A NOP implementation, as this logger is permanently disabled for
    * the DEBUG level.

Modified: slf4j/trunk/tests/src/java/org/slf4j/InvokingSLF4J.java
==============================================================================
--- slf4j/trunk/tests/src/java/org/slf4j/InvokingSLF4J.java	(original)
+++ slf4j/trunk/tests/src/java/org/slf4j/InvokingSLF4J.java	Tue Dec 27 10:24:59 2005
@@ -68,11 +68,18 @@
   }
   
   public void test2() {
+    Integer i1 = new Integer(1);
+    Integer i2 = new Integer(2);
+    Integer i3 = new Integer(3);
     Exception e = new Exception("This is a test exception.");
     Logger logger = LoggerFactory.getLogger("test2");
     logger.debug("Hello world 1.");
-    logger.debug("Hello world {}", new Integer(1));
+    logger.debug("Hello world {}", i1);
+    logger.debug("val={} val={}", i1, i2);
+    logger.debug("val={} val={} val={}", new Object[]{i1, i2, i3});
+    
     logger.debug("Hello world 1", e);
+    
     logger.info("Hello world 2.");
     logger.info("Hello world {}", new Integer(2)); 
     logger.warn("Hello world 3.");

Modified: slf4j/trunk/tests/src/java/org/slf4j/impl/MLogger.java
==============================================================================
--- slf4j/trunk/tests/src/java/org/slf4j/impl/MLogger.java	(original)
+++ slf4j/trunk/tests/src/java/org/slf4j/impl/MLogger.java	Tue Dec 27 10:24:59 2005
@@ -55,6 +55,8 @@
 
   public void debug(String parameterizedMsg, Object arg1, Object arg2) {  }
 
+  public void debug(String parameterizedMsg, Object[] arg) {  }
+  
   public void debug(String msg, Throwable t) {  }
 
   public boolean isInfoEnabled() {  return false;

Modified: slf4j/trunk/tests/src/java/org/slf4j/impl/XLogger.java
==============================================================================
--- slf4j/trunk/tests/src/java/org/slf4j/impl/XLogger.java	(original)
+++ slf4j/trunk/tests/src/java/org/slf4j/impl/XLogger.java	Tue Dec 27 10:24:59 2005
@@ -57,7 +57,9 @@
   public void debug(String parameterizedMsg, Object arg) {  }
 
   public void debug(String parameterizedMsg, Object arg1, Object arg2) {  }
+  public void debug(String parameterizedMsg, Object[] arg) {  }
 
+  
   public void debug(String msg, Throwable t) {  }
 
   public boolean isInfoEnabled() {  return false;



More information about the slf4j-dev mailing list