Author: ceki
Date: Tue Dec 27 11:31:58 2005
New Revision: 473

Modified:
   nlog4j/trunk/src/java/org/slf4j/Constants.java
   nlog4j/trunk/src/java/org/slf4j/ILoggerFactory.java
   nlog4j/trunk/src/java/org/slf4j/Logger.java
   nlog4j/trunk/src/java/org/slf4j/impl/MessageFormatter.java
   nlog4j/trunk/src/java/org/slf4j/impl/NOPLogger.java
   nlog4j/trunk/src/java/org/slf4j/impl/NOPLoggerFactory.java
   nlog4j/trunk/src/java/org/slf4j/impl/SimpleLogger.java
   nlog4j/trunk/src/java/org/slf4j/impl/StaticLoggerBinder.java
   nlog4j/trunk/src/java/org/slf4j/impl/SystemPropBinder.java
   nlog4j/trunk/src/java/org/slf4j/impl/Util.java
   nlog4j/trunk/src/java/org/slf4j/spi/LoggerFactoryBinder.java
Log:
sync with SLF4J 1.0RC4

Modified: nlog4j/trunk/src/java/org/slf4j/Constants.java
==============================================================================
--- nlog4j/trunk/src/java/org/slf4j/Constants.java      (original)
+++ nlog4j/trunk/src/java/org/slf4j/Constants.java      Tue Dec 27 11:31:58 2005
@@ -35,7 +35,7 @@
 /**
  * Various constants used in the SLF4J API.
  * 
- * @author <a href="http://www.qos.ch/log4j/";>Ceki G&uuml;lc&uuml;</a>
+ * @author Ceki G&uuml;lc&uuml;
  */
 public interface Constants {
     

Modified: nlog4j/trunk/src/java/org/slf4j/ILoggerFactory.java
==============================================================================
--- nlog4j/trunk/src/java/org/slf4j/ILoggerFactory.java (original)
+++ nlog4j/trunk/src/java/org/slf4j/ILoggerFactory.java Tue Dec 27 11:31:58 2005
@@ -38,7 +38,7 @@
  * instances by name.
  * 
  * <p>Most users retreive [EMAIL PROTECTED] Logger} instances through the 
static
- * [EMAIL PROTECTED] LoggerFactory#getLogger} mehtod. An instance of of this
+ * [EMAIL PROTECTED] LoggerFactory#getLogger(String)} method. An instance of 
of this
  * interface is bound internally with [EMAIL PROTECTED] LoggerFactory} class 
at 
  * compile time. Only developers of SLF4J conformant logging systems 
  * need to worry about this interface. 

Modified: nlog4j/trunk/src/java/org/slf4j/Logger.java
==============================================================================
--- nlog4j/trunk/src/java/org/slf4j/Logger.java (original)
+++ nlog4j/trunk/src/java/org/slf4j/Logger.java Tue Dec 27 11:31:58 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. 
    * 
@@ -142,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. 
    * 
@@ -176,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.
@@ -239,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: nlog4j/trunk/src/java/org/slf4j/impl/MessageFormatter.java
==============================================================================
--- nlog4j/trunk/src/java/org/slf4j/impl/MessageFormatter.java  (original)
+++ nlog4j/trunk/src/java/org/slf4j/impl/MessageFormatter.java  Tue Dec 27 
11:31:58 2005
@@ -35,12 +35,28 @@
 
 
 /**
- * Formats messages according to very simple rules. 
- * See [EMAIL PROTECTED] #format(String, Object)} and 
- * [EMAIL PROTECTED] #format(String, Object, Object)} for more details.
- *
- * @author <a href="http://www.qos.ch/log4j/";>Ceki G&uuml;lc&uuml;</a>
- */
+  * 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 [EMAIL PROTECTED] #format(String, Object)}, [EMAIL PROTECTED] 
#format(String, Object, Object)} 
+  * and [EMAIL PROTECTED] #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 = '}';
@@ -49,71 +65,60 @@
    * 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.
-   * 
    * @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 argument) {
-    int j = messagePattern.indexOf(DELIM_START);
-    int len = messagePattern.length();
-    char escape = 'x';
-
-    // if there are no { characters or { is the last character of the messsage
-    // then we just return messagePattern
-    if (j == -1 || (j+1 == len)) {
-      return messagePattern;
-    } else {
-      if(j+1 == len) {
-      }
-      
-      char delimStop = messagePattern.charAt(j + 1);
-      if (j > 0) {
-        escape = messagePattern.charAt(j - 1);
-      }
-      if ((delimStop != DELIM_STOP) || (escape == '\\')) {
-        // invalid DELIM_START/DELIM_STOP pair or espace character is
-        // present
-        return messagePattern;
-      } else {
-        StringBuffer sbuf = new StringBuffer(len + 20);
-        sbuf.append(messagePattern.substring(0, j));
-        sbuf.append(argument);
-        sbuf.append(messagePattern.substring(j + 2));
-        return sbuf.toString();
-      }
-    }
-  }
-
+  public static String format(String messagePattern, Object arg) {
+    return arrayFormat(messagePattern, new Object[] {arg});   
+   }
+  
   /**
-   * /**
+   *
    * 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.".
    * 
    * @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) 
{
+   return arrayFormat(messagePattern, new Object[] {arg1, arg2});   
+  }
+  
+  /**
+   * Same principle as the [EMAIL PROTECTED] #format(String, Object)} and 
+   * [EMAIL PROTECTED] #format(String, Object, Object)} methods except that
+   * any number of arguments can be passed in an array.
+   * 
+   * @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) {
+    if(messagePattern == null) {
+      return null;
+    }
     int i = 0;
     int len = messagePattern.length();
     int j = messagePattern.indexOf(DELIM_START);
-
+    
+  
+    
     StringBuffer sbuf = new StringBuffer(messagePattern.length() + 50);
 
-    for (int L = 0; L < 2; L++) {
+    for (int L = 0; L < argArray.length; L++) {
+      
+      char escape = 'x';
+      
       j = messagePattern.indexOf(DELIM_START, i);
 
       if (j == -1 || (j+1 == len)) {
@@ -126,14 +131,25 @@
         }
       } else {
         char delimStop = messagePattern.charAt(j + 1);
-        if ((delimStop != DELIM_STOP)) {
+        if (j > 0) {
+          escape = messagePattern.charAt(j - 1);
+        }
+        
+        if(escape == '\\') {
+          L--; // DELIM_START was escaped, thus should not be incremented
+          sbuf.append(messagePattern.substring(i, j-1));
+          sbuf.append(DELIM_START);
+          i = j + 1;
+        } else if ((delimStop != DELIM_STOP)) {
           // invalid DELIM_START/DELIM_STOP pair
           sbuf.append(messagePattern.substring(i, messagePattern.length()));
           return sbuf.toString();
+        } else {
+          // normal case
+          sbuf.append(messagePattern.substring(i, j));
+          sbuf.append(argArray[L]);
+          i = j + 2;
         }
-        sbuf.append(messagePattern.substring(i, j));
-        sbuf.append((L == 0) ? arg1 : arg2);
-        i = j + 2;
       }
     }
     // append the characters following the second {} pair.

Modified: nlog4j/trunk/src/java/org/slf4j/impl/NOPLogger.java
==============================================================================
--- nlog4j/trunk/src/java/org/slf4j/impl/NOPLogger.java (original)
+++ nlog4j/trunk/src/java/org/slf4j/impl/NOPLogger.java Tue Dec 27 11:31:58 2005
@@ -39,7 +39,7 @@
 /**
  * A direct NOP (no operation) implementation of [EMAIL PROTECTED] Logger}.
  *
- * @author <a href="http://www.qos.ch/log4j/";>Ceki G&uuml;lc&uuml;</a>
+ * @author Ceki G&uuml;lc&uuml;
  */
 public class NOPLogger implements Logger {
   /**
@@ -84,6 +84,13 @@
     // NOP
   }
 
+  /** A NOP implementation.  */
+  public final void debug(String format, Object[] argArray) {
+    // NOP
+  }
+  
+  
+  
   /** A NOP implementation. */
   final public void debug(String msg, Throwable t) {
     // NOP
@@ -113,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) {
@@ -142,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) {
@@ -168,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: nlog4j/trunk/src/java/org/slf4j/impl/NOPLoggerFactory.java
==============================================================================
--- nlog4j/trunk/src/java/org/slf4j/impl/NOPLoggerFactory.java  (original)
+++ nlog4j/trunk/src/java/org/slf4j/impl/NOPLoggerFactory.java  Tue Dec 27 
11:31:58 2005
@@ -42,7 +42,7 @@
  * ILoggerFactory} which always returns the unique instance of
  * NOPLogger.
  * 
- * @author Ceki Gulcu
+ * @author Ceki G&uuml;lc&uuml;
  */
 public class NOPLoggerFactory implements ILoggerFactory {
   

Modified: nlog4j/trunk/src/java/org/slf4j/impl/SimpleLogger.java
==============================================================================
--- nlog4j/trunk/src/java/org/slf4j/impl/SimpleLogger.java      (original)
+++ nlog4j/trunk/src/java/org/slf4j/impl/SimpleLogger.java      Tue Dec 27 
11:31:58 2005
@@ -59,7 +59,7 @@
 467 [main] INFO  examples.Sort - Exiting main method.
 </pre>
  *
- * @author <a href="http://www.qos.ch/log4j/";>Ceki G&uuml;lc&uuml;</a>
+ * @author Ceki G&uuml;lc&uuml;
  */
 public class SimpleLogger implements Logger {
   /**
@@ -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.
@@ -172,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.
@@ -205,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) {
@@ -243,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) {
@@ -281,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) {

Modified: nlog4j/trunk/src/java/org/slf4j/impl/StaticLoggerBinder.java
==============================================================================
--- nlog4j/trunk/src/java/org/slf4j/impl/StaticLoggerBinder.java        
(original)
+++ nlog4j/trunk/src/java/org/slf4j/impl/StaticLoggerBinder.java        Tue Dec 
27 11:31:58 2005
@@ -42,9 +42,6 @@
  * The binding of [EMAIL PROTECTED] LoggerFactory} class with an actual 
instance of 
  * [EMAIL PROTECTED] ILoggerFactory} is performed using information returned 
by this class. 
  * 
- * This class also contains the information for binding [EMAIL PROTECTED] 
MarkerFactory}
- * with the appropriate [EMAIL PROTECTED] IMarkerFactory} instance.
- * 
  * @author <a href="http://www.qos.ch/log4j/";>Ceki G&uuml;lc&uuml;</a>
  */
 public class StaticLoggerBinder implements LoggerFactoryBinder {

Modified: nlog4j/trunk/src/java/org/slf4j/impl/SystemPropBinder.java
==============================================================================
--- nlog4j/trunk/src/java/org/slf4j/impl/SystemPropBinder.java  (original)
+++ nlog4j/trunk/src/java/org/slf4j/impl/SystemPropBinder.java  Tue Dec 27 
11:31:58 2005
@@ -40,7 +40,7 @@
  * Allows for dynamic binding as specified by information contained
  * in the [EMAIL PROTECTED] Constants#LOGGER_FACTORY_PROPERTY} java system 
property.
  * 
- * @author <a href="http://www.qos.ch/log4j/";>Ceki G&uuml;lc&uuml;</a>
+ * @author Ceki G&uuml;lc&uuml;
  */
 public class SystemPropBinder implements LoggerFactoryBinder {
   String factoryFactoryClassName = null;

Modified: nlog4j/trunk/src/java/org/slf4j/impl/Util.java
==============================================================================
--- nlog4j/trunk/src/java/org/slf4j/impl/Util.java      (original)
+++ nlog4j/trunk/src/java/org/slf4j/impl/Util.java      Tue Dec 27 11:31:58 2005
@@ -38,7 +38,7 @@
  *
  * An internal utility class.
  *
- * @author Ceki Gulcu
+ * @author Ceki G&uuml;lc&uuml;
  */
 public class Util {
     

Modified: nlog4j/trunk/src/java/org/slf4j/spi/LoggerFactoryBinder.java
==============================================================================
--- nlog4j/trunk/src/java/org/slf4j/spi/LoggerFactoryBinder.java        
(original)
+++ nlog4j/trunk/src/java/org/slf4j/spi/LoggerFactoryBinder.java        Tue Dec 
27 11:31:58 2005
@@ -39,7 +39,7 @@
  * An internal interface which helps the static [EMAIL PROTECTED] 
org.slf4j.LoggerFactory} 
  * class bind with the appropriate [EMAIL PROTECTED] ILoggerFactory} instance. 
  * 
- * @author <a href="http://www.qos.ch/log4j/";>Ceki G&uuml;lc&uuml;</a>
+ * @author Ceki G&uuml;lc&uuml;
  */
 public interface LoggerFactoryBinder {
 
_______________________________________________
nlog4j-dev mailing list
[email protected]
http://slf4j.org/mailman/listinfo/nlog4j-dev

Reply via email to