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

ceki at slf4j.org ceki at slf4j.org
Fri Apr 15 18:01:36 CEST 2005


Author: ceki
Date: Fri Apr 15 17:45:03 2005
New Revision: 5

Added:
   slf4j/trunk/src/
   slf4j/trunk/src/filtered-java/
   slf4j/trunk/src/filtered-java/org/
   slf4j/trunk/src/filtered-java/org/slf4j/
   slf4j/trunk/src/filtered-java/org/slf4j/LoggerFactory.java
   slf4j/trunk/src/filtered-java/org/slf4j/LoggerFactoryAdapter.java
   slf4j/trunk/src/filtered-java/org/slf4j/ULogger.java
   slf4j/trunk/src/filtered-java/org/slf4j/impl/
   slf4j/trunk/src/filtered-java/org/slf4j/impl/JDK14Logger.java
   slf4j/trunk/src/filtered-java/org/slf4j/impl/JDK14LoggerFA.java
   slf4j/trunk/src/filtered-java/org/slf4j/impl/MessageFormatter.java
   slf4j/trunk/src/filtered-java/org/slf4j/impl/NOPLogger.java
   slf4j/trunk/src/filtered-java/org/slf4j/impl/NOPLoggerFA.java
   slf4j/trunk/src/filtered-java/org/slf4j/impl/SimpleLogger.java
   slf4j/trunk/src/filtered-java/org/slf4j/impl/SimpleLoggerFA.java
Log:
Initial import from UGLI

Added: slf4j/trunk/src/filtered-java/org/slf4j/LoggerFactory.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/src/filtered-java/org/slf4j/LoggerFactory.java	Fri Apr 15 17:45:03 2005
@@ -0,0 +1,52 @@
+package org.slf4j;
+
+// WARNING
+// WARNING Modifications MUST be made to the original file found at
+// WARNING $SLF4J_HOME/src/filtered-java/org/slf4j/LoggerFactory.java
+// WARNING
+
+/**
+ * The <code>LoggerFactory</code> can produce Loggers for various logging APIs,
+ * most notably for log4j, JDK 1.4 logging. Other implemenations such as
+ * {@link org.slf4j.impl.NOPLogger NOPLogger} and
+ * {@link org.slf4j.impl.DumbLogger DumbLogger} are also supported.
+ *
+ * @author Ceki G&uuml;lc&uuml;
+ */
+public class LoggerFactory {
+  static LoggerFactoryAdapter adapter;
+
+  // 
+  // WARNING Modify the original in
+  //         $SLF4J_HOME/src/filtered-java/org/apache/slf4j/
+  
+  static {
+    String adapterClassStr = "org.slf4j.impl. at IMPL@LoggerFA";
+    System.out.println("SLF4J built for "+adapterClassStr);
+    try {
+      adapter = new org.slf4j.impl. at IMPL@LoggerFA();
+    } catch (Exception e) {
+      // unless there was a problem with the build or the JVM we will never
+      // get exceptions
+      System.err.println(
+        "Could not instantiate instance of class [" + adapterClassStr + "]");
+      e.printStackTrace();
+    }
+  }
+
+  public static ULogger getLogger(String name) {
+    return adapter.getLogger(name);
+  }
+
+  public static ULogger getLogger(String domainName, String subDomainName) {
+    return adapter.getLogger(domainName, subDomainName);
+  }
+
+  public static ULogger getLogger(Class clazz) {
+    return adapter.getLogger(clazz.getName());
+  }
+
+  public static ULogger getLogger(Class clazz, String subDomainName) {
+    return adapter.getLogger(clazz.getName(), subDomainName);
+  }
+}

Added: slf4j/trunk/src/filtered-java/org/slf4j/LoggerFactoryAdapter.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/src/filtered-java/org/slf4j/LoggerFactoryAdapter.java	Fri Apr 15 17:45:03 2005
@@ -0,0 +1,28 @@
+package org.slf4j;
+
+/**
+ * LoggerFactoryAdapter interface is used internally by {@link
+ * LoggerFactory}.
+ * 
+ * <p>Only developers wishing to write new UGLI adapters need to worry
+ * about this interface.
+ * 
+ * @author Ceki G&uuml;lc&uuml;
+ *
+ */
+public interface LoggerFactoryAdapter {
+  
+  /**
+   * Return the appropriate named {@link ULogger} instance.
+   */
+  public ULogger getLogger(String name);
+  
+  /**
+   * Return a {@link ULogger} instance in <code>domain</code>, <code>subDomain</code>. 
+   *
+   * @param domain
+   * @param subDomain
+   * @return ULogger instance
+   */
+  public ULogger getLogger(String domain, String subDomain);  
+}

Added: slf4j/trunk/src/filtered-java/org/slf4j/ULogger.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/src/filtered-java/org/slf4j/ULogger.java	Fri Apr 15 17:45:03 2005
@@ -0,0 +1,72 @@
+package org.slf4j;
+
+
+/**
+ * 
+ * The main user inteface to logging. It is expected that logging
+ * takes places through concerete implemetations of the ULogger
+ * interface.
+ * 
+ * @author Ceki G&uuml;lc&uuml;
+ */
+public interface ULogger {
+
+  /**
+   * Is the logger instance enabled for the DEBUG level?
+   * @return 
+   */
+  public boolean isDebugEnabled();
+  
+  /**
+   * Log a message object with the DEBUG level. 
+   * @param msg - the message object to be logged
+   */
+  public void debug(Object msg);
+  
+  
+  /**
+   * Log a parameterized message object at the DEBUG level. 
+   * 
+   * <p>This form is useful in avoiding the superflous object creation
+   * problem when invoking this method while it is disabled.
+   * </p>
+   * @param parameterizedMsg - the parameterized message object
+   * @param param1 - the parameter 
+   */
+  public void debug(Object parameterizedMsg, Object param1);
+  
+  /**
+   * Log a parameterized message object at the DEBUG level. 
+   * 
+   * <p>This form is useful in avoiding the superflous object creation
+   * problem when invoking this method while it is disabled.
+   * </p>
+   * @param parameterizedMsg - the parameterized message object
+   * @param param1 - the first parameter 
+   * @param param2 - the second parameter 
+   */
+  public void debug(String parameterizedMsg, Object param1, Object param2);
+  public void debug(Object msg, Throwable t);
+
+
+  public boolean isInfoEnabled();
+  public void info(Object msg);
+  public void info(Object parameterizedMsg, Object param1);
+  public void info(String parameterizedMsg, Object param1, Object param2);
+  public void info(Object msg, Throwable t);
+
+
+  public boolean isWarnEnabled();
+  public void warn(Object msg);
+  public void warn(Object parameterizedMsg, Object param1);
+  public void warn(String parameterizedMsg, Object param1, Object param2);
+  public void warn(Object msg, Throwable t);
+
+
+  public boolean isErrorEnabled();
+  public void error(Object msg);
+  public void error(Object parameterizedMsg, Object param1);
+  public void error(String parameterizedMsg, Object param1, Object param2);
+  public void error(Object msg, Throwable t);
+
+}

Added: slf4j/trunk/src/filtered-java/org/slf4j/impl/JDK14Logger.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/src/filtered-java/org/slf4j/impl/JDK14Logger.java	Fri Apr 15 17:45:03 2005
@@ -0,0 +1,212 @@
+package org.slf4j.impl;
+
+
+import org.slf4j.ULogger;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+
+/**
+ * A wrapper over @{link java.utill.Logger} which conforms to the 
+ * {@link ULogger} interface.
+ * 
+ * @author Ceki G&uuml;lc&uuml;
+ */
+public class JDK14Logger implements ULogger {
+  final Logger logger;
+
+  // WARN: JDK14Logger constructor should have only package access so that
+  // only JDK14LoggerFA be able to create one.
+  JDK14Logger(Logger logger) {
+    this.logger = logger;
+  }
+
+  /**
+   * Is the logger instance enabled for the DEBUG level?
+   * @return
+   */
+  public boolean isDebugEnabled() {
+    return logger.isLoggable(Level.FINE);
+  }
+
+  //
+
+  /**
+   * Log a message object with the DEBUG level.
+   * @param msg - the message object to be logged
+   */
+  public void debug(Object msg) {
+    logger.fine(String.valueOf(msg));
+  }
+
+  /**
+   * Log a parameterized message object at the DEBUG level.
+   *
+   * <p>This form is useful in avoiding the superflous object creation
+   * problem when invoking this method while it is disabled.
+   * </p>
+   * @param parameterizedMsg - the parameterized message object
+   * @param param1 - the parameter
+   */
+  public void debug(Object parameterizedMsg, Object param1) {
+    if (logger.isLoggable(Level.FINE)) {
+      if (parameterizedMsg instanceof String) {
+        String msgStr = (String) parameterizedMsg;
+        msgStr = MessageFormatter.format(msgStr, param1);
+        logger.fine(msgStr);
+      } else {
+        // To be failsafe, we handle the case where 'messagePattern' is not
+        // a String. Unless the user makes a mistake, this should not happen.
+        logger.fine(parameterizedMsg.toString());
+      }
+    }
+  }
+
+  /**
+   * Log a parameterized message object at the DEBUG level.
+   *
+   * <p>This form is useful in avoiding the superflous object creation
+   * problem when invoking this method while it is disabled.
+   * </p>
+   * @param parameterizedMsg - the parameterized message object
+   * @param param1 - the first parameter
+   * @param param2 - the second parameter
+   */
+  public void debug(String parameterizedMsg, Object param1, Object param2) {
+    if (logger.isLoggable(Level.FINE)) {
+      if (parameterizedMsg instanceof String) {
+        String msgStr = (String) parameterizedMsg;
+        msgStr = MessageFormatter.format(msgStr, param1, param2);
+        logger.fine(msgStr);
+      } else {
+        // To be failsafe, we handle the case where 'messagePattern' is not
+        // a String. Unless the user makes a mistake, this should not happen.
+        logger.fine(parameterizedMsg.toString());
+      }
+    }
+  }
+
+  public void debug(Object msg, Throwable t) {
+    logger.log(Level.FINE, msg.toString(), t);
+  }
+
+  public boolean isInfoEnabled() {
+    return logger.isLoggable(Level.INFO);
+  }
+
+  public void info(Object msg) {
+    logger.info(msg.toString());
+  }
+
+  public void info(Object parameterizedMsg, Object param1) {
+    if (logger.isLoggable(Level.INFO)) {
+      if (parameterizedMsg instanceof String) {
+        String msgStr = (String) parameterizedMsg;
+        msgStr = MessageFormatter.format(msgStr, param1);
+        logger.info(msgStr);
+      } else {
+        // To be failsafe, we handle the case where 'messagePattern' is not
+        // a String. Unless the user makes a mistake, this should not happen.
+        logger.info(parameterizedMsg.toString());
+      }
+    }
+  }
+
+  public void info(String parameterizedMsg, Object param1, Object param2) {
+    if (logger.isLoggable(Level.INFO)) {
+      if (parameterizedMsg instanceof String) {
+        String msgStr = (String) parameterizedMsg;
+        msgStr = MessageFormatter.format(msgStr, param1, param2);
+        logger.info(msgStr);
+      } else {
+        // To be failsafe, we handle the case where 'messagePattern' is not
+        // a String. Unless the user makes a mistake, this should not happen.
+        logger.info(parameterizedMsg.toString());
+      }
+    }
+  }
+
+  public void info(Object msg, Throwable t) {
+    logger.log(Level.INFO, msg.toString(), t);
+  }
+
+  public boolean isWarnEnabled() {
+    return logger.isLoggable(Level.WARNING);
+  }
+
+  public void warn(Object msg) {
+    logger.warning(msg.toString());
+  }
+
+  public void warn(Object parameterizedMsg, Object param1) {
+    if (logger.isLoggable(Level.WARNING)) {
+      if (parameterizedMsg instanceof String) {
+        String msgStr = (String) parameterizedMsg;
+        msgStr = MessageFormatter.format(msgStr, param1);
+        logger.warning(msgStr);
+      } else {
+        // To be failsafe, we handle the case where 'messagePattern' is not
+        // a String. Unless the user makes a mistake, this should not happen.
+        logger.warning(parameterizedMsg.toString());
+      }
+    }
+  }
+
+  public void warn(String parameterizedMsg, Object param1, Object param2) {
+    if (logger.isLoggable(Level.WARNING)) {
+      if (parameterizedMsg instanceof String) {
+        String msgStr = (String) parameterizedMsg;
+        msgStr = MessageFormatter.format(msgStr, param1, param2);
+        logger.warning(msgStr);
+      } else {
+        // To be failsafe, we handle the case where 'messagePattern' is not
+        // a String. Unless the user makes a mistake, this should not happen.
+        logger.warning(parameterizedMsg.toString());
+      }
+    }
+  }
+
+  public void warn(Object msg, Throwable t) {
+    logger.log(Level.WARNING, msg.toString(), t);
+  }
+
+  public boolean isErrorEnabled() {
+    return logger.isLoggable(Level.SEVERE);
+  }
+
+  public void error(Object msg) {
+    logger.severe(msg.toString());
+  }
+
+  public void error(Object parameterizedMsg, Object param1) {
+    if (logger.isLoggable(Level.WARNING)) {
+      if (parameterizedMsg instanceof String) {
+        String msgStr = (String) parameterizedMsg;
+        msgStr = MessageFormatter.format(msgStr, param1);
+        logger.severe(msgStr);
+      } else {
+        // To be failsafe, we handle the case where 'messagePattern' is not
+        // a String. Unless the user makes a mistake, this should not happen.
+        logger.severe(parameterizedMsg.toString());
+      }
+    }
+  }
+  
+  public void error(String parameterizedMsg, Object param1, Object param2) {
+    if (logger.isLoggable(Level.WARNING)) {
+      if (parameterizedMsg instanceof String) {
+        String msgStr = (String) parameterizedMsg;
+        msgStr = MessageFormatter.format(msgStr, param1, param2);
+        logger.severe(msgStr);
+      } else {
+        // To be failsafe, we handle the case where 'messagePattern' is not
+        // a String. Unless the user makes a mistake, this should not happen.
+        logger.severe(parameterizedMsg.toString());
+      }
+    }
+  }
+  public void error(Object msg, Throwable t) {
+    logger.log(Level.SEVERE, msg.toString(), t);
+  }
+}

Added: slf4j/trunk/src/filtered-java/org/slf4j/impl/JDK14LoggerFA.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/src/filtered-java/org/slf4j/impl/JDK14LoggerFA.java	Fri Apr 15 17:45:03 2005
@@ -0,0 +1,41 @@
+package org.slf4j.impl;
+
+import org.slf4j.LoggerFactoryAdapter;
+import org.slf4j.ULogger;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Logger;
+
+
+/**
+ *
+ * @author Ceki G&uuml;lc&uuml;
+ */
+public class JDK14LoggerFA implements LoggerFactoryAdapter {
+  Map map;
+
+  public JDK14LoggerFA() {
+    map = new HashMap();
+  }
+
+  /* (non-Javadoc)
+   * @see org.slf4j.LoggerFactoryAdapter#getLogger(java.lang.String)
+   */
+  public ULogger getLogger(String name) {
+    ULogger ulogger = (ULogger) map.get(name);
+    if (ulogger == null) {
+      Logger logger = Logger.getLogger(name);
+      ulogger = new JDK14Logger(logger);
+      map.put(name, ulogger);
+    }
+    return ulogger;
+  }
+
+  /* (non-Javadoc)
+   * @see org.slf4j.LoggerFactoryAdapter#getLogger(java.lang.String, java.lang.String)
+   */
+  public ULogger getLogger(String domainName, String subDomainName) {
+    return getLogger(domainName);
+  }
+}

Added: slf4j/trunk/src/filtered-java/org/slf4j/impl/MessageFormatter.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/src/filtered-java/org/slf4j/impl/MessageFormatter.java	Fri Apr 15 17:45:03 2005
@@ -0,0 +1,110 @@
+package org.slf4j.impl;
+
+
+/**
+ * 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;
+ */
+public class MessageFormatter {
+  static final char DELIM_START = '{';
+  static final char DELIM_STOP = '}';
+
+  /**
+   * Performs single argument substitution for the 'messagePattern' passed as
+   * parameter.
+   * <p>
+   * For example, <code>MessageFormatter.format("Hi {}.", "there");</code> 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
+   * @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();
+      }
+    }
+  }
+
+  /**
+   * /**
+   * 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.
+   * 
+   * @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
+   * @return The formatted message
+   */
+  public static String format(String messagePattern, Object arg1, Object arg2) {
+    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++) {
+      j = messagePattern.indexOf(DELIM_START, i);
+
+      if (j == -1 || (j+1 == len)) {
+        // no more variables
+        if (i == 0) { // this is a simple string
+          return messagePattern;
+        } else { // add the tail string which contains no variables and return the result.
+          sbuf.append(messagePattern.substring(i, messagePattern.length()));
+          return sbuf.toString();
+        }
+      } else {
+        char delimStop = messagePattern.charAt(j + 1);
+        if ((delimStop != DELIM_STOP)) {
+          // invalid DELIM_START/DELIM_STOP pair
+          sbuf.append(messagePattern.substring(i, messagePattern.length()));
+          return sbuf.toString();
+        }
+        sbuf.append(messagePattern.substring(i, j));
+        sbuf.append((L == 0) ? arg1 : arg2);
+        i = j + 2;
+      }
+    }
+    // append the characters following the second {} pair.
+    sbuf.append(messagePattern.substring(i, messagePattern.length()));
+    return sbuf.toString();
+  }
+}

Added: slf4j/trunk/src/filtered-java/org/slf4j/impl/NOPLogger.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/src/filtered-java/org/slf4j/impl/NOPLogger.java	Fri Apr 15 17:45:03 2005
@@ -0,0 +1,167 @@
+package org.slf4j.impl;
+
+import org.slf4j.ULogger;
+
+
+/**
+ * A no operation (NOP) implementation of {@link ULogger}.
+ * 
+ * @author Ceki G&uuml;lc&uuml;
+ */
+public class NOPLogger implements ULogger {
+
+  /**
+   * The unique instance of NOPLogger.
+   */
+  public final static NOPLogger NOP_LOGGER = new NOPLogger();
+  
+  /**
+   * There is no point in people creating multiple instances of NullLogger. 
+   * Hence, the private access modifier. 
+   */
+  private NOPLogger() {
+  }
+  
+  /* Always returns false.
+   * 
+   * @see org.slf4j.Logger#isDebugEnabled()
+   */
+  public boolean isDebugEnabled() {
+    return false;
+  }
+
+  /* A NOP implementation.
+   * @see org.slf4j.Logger#debug(java.lang.Object)
+   */
+  public void debug(Object msg) {
+    // NOP
+  }
+
+  /* A NOP implementation.
+   * @see org.slf4j.Logger#debug(java.lang.Object, java.lang.Object)
+   */
+  public void debug(Object parameterizedMsg, Object param1) {
+    // NOP
+  }
+
+  /* A NOP implementation.
+   * @see org.slf4j.Logger#debug(java.lang.Object, java.lang.Object, java.lang.Object)
+   */
+  public void debug(String parameterizedMsg, Object param1, Object param2) {
+    // NOP
+  }
+
+  /* A NOP implementation.
+   * @see org.slf4j.Logger#debug(java.lang.Object, java.lang.Throwable)
+   */
+  public void debug(Object msg, Throwable t) {
+    // NOP
+  }
+
+  /* Always returns false.
+   * @see org.slf4j.Logger#isInfoEnabled()
+   */
+  public boolean isInfoEnabled() {
+    // NOP
+    return false;
+  }
+
+  /* A NOP implementation.
+   * @see org.slf4j.Logger#info(java.lang.Object)
+   */
+  public void info(Object msg) {
+    // NOP
+  }
+
+  /* A NOP implementation.
+   * @see org.slf4j.Logger#info(java.lang.Object, java.lang.Object)
+   */
+  public void info(Object parameterizedMsg, Object param1) {
+    // NOP
+  }
+
+  /* A NOP implementation.
+   * @see org.slf4j.Logger#info(java.lang.Object, java.lang.Object, java.lang.Object)
+   */
+  public void info(String parameterizedMsg, Object param1, Object param2) {
+    // NOP
+  }
+
+  /* A NOP implementation.
+   * @see org.slf4j.Logger#info(java.lang.Object, java.lang.Throwable)
+   */
+  public void info(Object msg, Throwable t) {
+    // NOP
+  }
+
+  /* Always returns false.
+   * @see org.slf4j.Logger#isWarnEnabled()
+   */
+  public boolean isWarnEnabled() {
+    return false;
+  }
+
+  /* A NOP implementation.
+   * @see org.slf4j.Logger#warn(java.lang.Object)
+   */
+  public void warn(Object msg) {
+    // NOP
+  }
+
+  /* A NOP implementation.
+   * @see org.slf4j.Logger#warn(java.lang.Object, java.lang.Object)
+   */
+  public void warn(Object parameterizedMsg, Object param1) {
+    // NOP
+  }
+
+  /* A NOP implementation.
+   * @see org.slf4j.Logger#warn(java.lang.Object, java.lang.Object, java.lang.Object)
+   */
+  public void warn(String parameterizedMsg, Object param1, Object param2) {
+    // NOP
+  }
+
+  /* A NOP implementation.
+   * @see org.slf4j.Logger#warn(java.lang.Object, java.lang.Throwable)
+   */
+  public void warn(Object msg, Throwable t) {
+    // NOP
+  }
+
+  /* Always returns false.
+   * @see org.slf4j.Logger#isErrorEnabled()
+   */
+  public boolean isErrorEnabled() {
+    return false;
+  }
+
+  /* A NOP implementation.
+   * @see org.slf4j.Logger#error(java.lang.Object)
+   */
+  public void error(Object msg) {
+    // NOP
+  }
+
+  /* A NOP implementation.
+   * @see org.slf4j.Logger#error(java.lang.Object, java.lang.Object)
+   */
+  public void error(Object parameterizedMsg, Object param1) {
+    // NOP
+  }
+
+  /* A NOP implementation.
+   * @see org.slf4j.Logger#error(java.lang.Object, java.lang.Object, java.lang.Object)
+   */
+  public void error(String parameterizedMsg, Object param1, Object param2) {
+    // NOP
+  }
+
+  /* A NOP implementation.
+   * @see org.slf4j.Logger#error(java.lang.Object, java.lang.Throwable)
+   */
+  public void error(Object msg, Throwable t) {
+    // NOP
+  }
+
+}

Added: slf4j/trunk/src/filtered-java/org/slf4j/impl/NOPLoggerFA.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/src/filtered-java/org/slf4j/impl/NOPLoggerFA.java	Fri Apr 15 17:45:03 2005
@@ -0,0 +1,25 @@
+package org.slf4j.impl;
+
+import org.slf4j.LoggerFactoryAdapter;
+import org.slf4j.ULogger;
+
+
+/**
+ * NOPLoggerFA is am implementation of {@link LoggerFactoryAdapter}
+ * which always returns the unique instance of NOPLogger.
+ * 
+ * @author Ceki Gulcu
+ */
+public class NOPLoggerFA implements LoggerFactoryAdapter {
+  
+  public NOPLoggerFA() {
+    // nothing to do
+  }
+  
+  public ULogger getLogger(String name) {
+    return NOPLogger.NOP_LOGGER;
+  }
+  public ULogger getLogger(String domainName, String subDomainName) {
+    return NOPLogger.NOP_LOGGER;  
+  }  
+}

Added: slf4j/trunk/src/filtered-java/org/slf4j/impl/SimpleLogger.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/src/filtered-java/org/slf4j/impl/SimpleLogger.java	Fri Apr 15 17:45:03 2005
@@ -0,0 +1,257 @@
+package org.slf4j.impl;
+
+import org.slf4j.ULogger;
+
+
+/**
+ * A simple 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 separator for the host. 
+ * In log4j terms it amounts to the "%r  [%t] %level %logger - %m%n" pattern.
+ * <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 SortAlgo.DUMP - Dump of interger array:
+317 [main] INFO SortAlgo.DUMP - Element [0] = 0
+331 [main] INFO SortAlgo.DUMP - Element [1] = 1
+343 [main] INFO examples.Sort - The next log statement should be an error message.
+346 [main] ERROR SortAlgo.DUMP - 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;
+ */
+public class SimpleLogger implements ULogger {
+
+  String loggerName;
+  
+  /**
+   * Mark the time when this class gets loaded into memory.
+   */
+  static private long startTime = System.currentTimeMillis();
+  
+  public static final String LINE_SEPARATOR = System.getProperty("line.separator");
+  
+  static private String INFO_STR = "INFO";
+  static private String WARN_STR = "WARN";
+  static private String ERROR_STR = "ERROR";
+  
+  /**
+   * Package access allows only {@link SimpleLoggerFA} to instantiate 
+   * SimpleLogger instances.
+   */
+  SimpleLogger(String name) {
+    this.loggerName = name;
+  }
+  
+  /**
+   * Always returns false.
+   */
+  public boolean isDebugEnabled() {
+    return false;
+  }
+
+  /**
+   * A NOP implementation.
+   */
+  public void debug(Object msg) {
+    // NOP
+  }
+
+  /**
+   * A NOP implementation.
+   */
+  public void debug(Object parameterizedMsg, Object param1) {
+    // NOP
+  }
+
+  /**
+   * A NOP implementation.
+   */
+  public void debug(String parameterizedMsg, Object param1, Object param2) {
+    // NOP
+  }
+
+  /**
+   * A NOP implementation.
+   */
+  public void debug(Object msg, Throwable t) {
+    // NOP
+  }
+
+  /**
+   * This is our internal implementation for logging regular (non-parameterized)
+   * log messages.
+   * 
+   * @param level
+   * @param message
+   * @param t
+   */
+  private void log(String level, String message, Throwable t) {
+    StringBuffer buf = new StringBuffer();
+    
+    long millis  = System.currentTimeMillis();
+    buf.append(millis-startTime);
+    
+    buf.append(" [");
+    buf.append(Thread.currentThread().getName());
+    buf.append("] ");
+    
+    buf.append(level);
+    buf.append(" ");
+    
+    buf.append(loggerName);
+    buf.append(" - ");
+
+    buf.append(message);
+
+    buf.append(LINE_SEPARATOR);
+    
+    System.out.print(buf.toString());
+    if(t != null) {
+      t.printStackTrace(System.out);
+    }
+    System.out.flush();
+  }
+  /**
+   * For parameterized messages, first substitute parameters and then log.
+   * 
+   * @param level
+   * @param parameterizedMsg
+   * @param param1
+   * @param param2
+   */
+  private void parameterizedLog(String level, Object parameterizedMsg, Object param1, Object param2) {
+    if (parameterizedMsg instanceof String) {
+      String msgStr = (String) parameterizedMsg;
+      msgStr = MessageFormatter.format(msgStr, param1, param2);
+      log(level, msgStr, null);
+    } else {
+      // To be failsafe, we handle the case where 'messagePattern' is not
+      // a String. Unless the user makes a mistake, this should not happen.
+      log(level, parameterizedMsg.toString(), null);
+    }
+  }
+  
+  /**
+   * Always returns true.
+   */
+  public boolean isInfoEnabled() {
+    return true;
+  }
+
+  /**
+   * A simple implementation which always logs messages of level INFO according
+   * to the format outlined above.
+   */
+  public void info(Object msg) {
+    log(INFO_STR, msg.toString(), null);
+  }
+
+  
+  /**
+   * Perform single parameter substituion before logging the message of level 
+   * INFO according to the format outlined above.
+   */
+  public void info(Object parameterizedMsg, Object param1) {
+    parameterizedLog(INFO_STR, parameterizedMsg, param1, null);
+  }
+
+  /**
+   * Perform double parameter substituion before logging the message of level 
+   * INFO according to the format outlined above.
+   */
+  
+  public void info(String parameterizedMsg, Object param1, Object param2) {
+    parameterizedLog(INFO_STR, parameterizedMsg, param1, param2);
+  }
+
+  /** 
+   * Log a message of level INFO, including an exception.
+   */
+  public void info(Object msg, Throwable t) {
+    log(INFO_STR, msg.toString(), t);
+  }
+
+  /**
+   * Always returns true.
+   */
+  public boolean isWarnEnabled() {
+    return true;
+  }
+
+  /**
+   * A simple implementation which always logs messages of level WARN according
+   * to the format outlined above.
+  */
+  public void warn(Object msg) {
+    log(WARN_STR, msg.toString(), null);
+  }
+
+  /**
+   * Perform single parameter substituion before logging the message of level 
+   * WARN according to the format outlined above.
+   */
+  public void warn(Object parameterizedMsg, Object param1) {
+    parameterizedLog(WARN_STR, parameterizedMsg, param1, null);
+  }
+
+  /**
+   * Perform double parameter substituion before logging the message of level 
+   * WARN according to the format outlined above.
+   */
+  public void warn(String parameterizedMsg, Object param1, Object param2) {
+    parameterizedLog(WARN_STR, parameterizedMsg, param1, param2);
+  }
+
+  /**
+   * Log a message of level WARN, including an exception.
+   */
+  public void warn(Object msg, Throwable t) {
+    log(WARN_STR, msg.toString(), t);
+  }
+
+  /**
+   * Always returns true.
+   */
+  public boolean isErrorEnabled() {
+    return true;
+  }
+
+  /**
+   * A simple implementation which always logs messages of level ERROR acoording
+   * to the format outlined above.
+   */
+  public void error(Object msg) {
+    log(ERROR_STR, msg.toString(), null);
+  }
+
+
+  /**
+   * Perform single parameter substituion before logging the message of level 
+   * ERROR according to the format outlined above.
+   */
+  public void error(Object parameterizedMsg, Object param1) {
+    parameterizedLog(ERROR_STR, parameterizedMsg, param1, null);
+  }
+
+  /**
+   * Perform double parameter substituion before logging the message of level 
+   * ERROR according to the format outlined above.
+   */
+  public void error(String parameterizedMsg, Object param1, Object param2) {
+    parameterizedLog(ERROR_STR, parameterizedMsg, param1, param2);
+  }
+
+  /** 
+   * Log a message of level ERROR, including an exception.
+   */
+  public void error(Object msg, Throwable t) {
+    log(ERROR_STR, msg.toString(), t);
+  }
+
+}

Added: slf4j/trunk/src/filtered-java/org/slf4j/impl/SimpleLoggerFA.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/src/filtered-java/org/slf4j/impl/SimpleLoggerFA.java	Fri Apr 15 17:45:03 2005
@@ -0,0 +1,50 @@
+package org.slf4j.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.slf4j.LoggerFactoryAdapter;
+import org.slf4j.ULogger;
+
+
+/**
+ * An implementation of {@link LoggerFactoryAdapter} which always returns
+ * {@link SimpleLogger} instances.
+ * 
+ * @author Ceki G&uuml;lc&uuml;
+ */
+public class SimpleLoggerFA implements LoggerFactoryAdapter {
+
+  Map map;
+  
+  public SimpleLoggerFA() {
+    map = new HashMap();
+  }
+
+
+  /**
+   * Return an appropriate {@link SimpleLogger} instance by name. At this time,
+   * 
+   */
+  /**
+   * Return an appropriate {@link SimpleLogger} instance.
+   * */
+  public ULogger getLogger(String name) {
+    ULogger ulogger = (ULogger) map.get(name);
+    if(ulogger == null) {
+      ulogger = new SimpleLogger(name);
+      map.put(name, ulogger);
+    }
+    return ulogger;
+  }
+
+  /*
+   *  (non-Javadoc)
+   * @see org.slf4j.LoggerFactoryAdapter#getLogger(java.lang.String, java.lang.String)
+   */
+  public ULogger getLogger(String domainName, String subDomainName) {
+    return getLogger(domainName);
+  }
+  
+  
+}



More information about the slf4j-dev mailing list