You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ce...@apache.org on 2005/02/10 13:09:48 UTC

cvs commit: logging-log4j/src/filtered-java/org/apache/ugli/impl NOPLoggerFA.java JDK14Logger.java SimpleLoggerFA.java NOPLogger.java MessageFormatter.java JDK14LoggerFA.java SimpleLogger.java

ceki        2005/02/10 04:09:48

  Modified:    src/filtered-java/org/apache/ugli LoggerFactory.java
  Added:       src/filtered-java/org/apache/ugli ULogger.java
                        LoggerFactoryAdapter.java
               src/filtered-java/org/apache/ugli/impl NOPLoggerFA.java
                        JDK14Logger.java SimpleLoggerFA.java NOPLogger.java
                        MessageFormatter.java JDK14LoggerFA.java
                        SimpleLogger.java
  Log:
  Binding implementations at compile time
  
  Revision  Changes    Path
  1.2       +12 -17    logging-log4j/src/filtered-java/org/apache/ugli/LoggerFactory.java
  
  Index: LoggerFactory.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/filtered-java/org/apache/ugli/LoggerFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LoggerFactory.java	9 Feb 2005 21:33:17 -0000	1.1
  +++ LoggerFactory.java	10 Feb 2005 12:09:48 -0000	1.2
  @@ -16,12 +16,10 @@
   
   package org.apache.ugli;
   
  -import org.apache.ugli.impl.NOPLoggerFA;
  -
  -import java.io.InputStream;
  -
  -import java.util.Properties;
  -
  +// WARNING
  +// WARNING Modifications MUST be made to the original file found at
  +// WARNING $LOG4J_HOME/src/filtered-java/org/apache/ugli/LoggerFactory.java
  +// WARNING
   
   /**
    * The <code>LoggerFactory</code> can produce Loggers for various logging APIs,
  @@ -34,24 +32,21 @@
   public class LoggerFactory {
     static LoggerFactoryAdapter adapter;
   
  +  //WARNING Modify the original in
  +  //        $LOG4J_HOME/src/filtered-java/org/apache/ugli/
  +  
     static {
  -    String adapterClassStr = "@ADAPTER_CLASS@";
  -    System.out.println("Built for "+adapterClassStr);
  +    String adapterClassStr = "org.apache.ugli.impl.@IMPL@LoggerFA";
  +    System.out.println("UGLI built for "+adapterClassStr);
       try {
  -      adapter = new @ADAPTER_CLASS@();
  -    } catch (ClassNotFoundException cnfe) {
  -      System.err.println("Could not find class [" + adapterClassStr + "]");
  -      cnfe.printStackTrace();
  +      adapter = new org.apache.ugli.impl.@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();
       }
  -
  -    if (adapter == null) {
  -      // TODO consider falling back on something more meaningful
  -      adapter = new NOPLoggerFA();
  -    }
     }
   
     public static ULogger getLogger(String name) {
  
  
  
  1.1                  logging-log4j/src/filtered-java/org/apache/ugli/ULogger.java
  
  Index: ULogger.java
  ===================================================================
  /*
   * Copyright 1999,2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.ugli;
  
  
  /**
   * 
   * 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);
  
  }
  
  
  
  1.1                  logging-log4j/src/filtered-java/org/apache/ugli/LoggerFactoryAdapter.java
  
  Index: LoggerFactoryAdapter.java
  ===================================================================
  /*
   * Created on Dec 30, 2004
   *
   * To change the template for this generated file go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  package org.apache.ugli;
  
  
  
  /**
   * 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);  
  }
  
  
  
  1.1                  logging-log4j/src/filtered-java/org/apache/ugli/impl/NOPLoggerFA.java
  
  Index: NOPLoggerFA.java
  ===================================================================
  /*
   * Created on Dec 30, 2004
   *
   * To change the template for this generated file go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  package org.apache.ugli.impl;
  
  import org.apache.ugli.LoggerFactoryAdapter;
  import org.apache.ugli.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;  
    }  
  }
  
  
  
  1.1                  logging-log4j/src/filtered-java/org/apache/ugli/impl/JDK14Logger.java
  
  Index: JDK14Logger.java
  ===================================================================
  /*
   * Copyright 1999,2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  /*
   * Created on Dec 30, 2004
   *
   * To change the template for this generated file go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  package org.apache.ugli.impl;
  
  
  import org.apache.ugli.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);
    }
  }
  
  
  
  1.1                  logging-log4j/src/filtered-java/org/apache/ugli/impl/SimpleLoggerFA.java
  
  Index: SimpleLoggerFA.java
  ===================================================================
  /*
   * Created on Dec 30, 2004
   *
   * To change the template for this generated file go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  package org.apache.ugli.impl;
  
  import java.util.HashMap;
  import java.util.Map;
  
  import org.apache.ugli.LoggerFactoryAdapter;
  import org.apache.ugli.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.apache.ugli.LoggerFactoryAdapter#getLogger(java.lang.String, java.lang.String)
     */
    public ULogger getLogger(String domainName, String subDomainName) {
      return getLogger(domainName);
    }
    
    
  }
  
  
  
  1.1                  logging-log4j/src/filtered-java/org/apache/ugli/impl/NOPLogger.java
  
  Index: NOPLogger.java
  ===================================================================
  /*
   * Copyright 1999,2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.ugli.impl;
  
  import org.apache.ugli.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.apache.ugli.Logger#isDebugEnabled()
     */
    public boolean isDebugEnabled() {
      return false;
    }
  
    /* A NOP implementation.
     * @see org.apache.ugli.Logger#debug(java.lang.Object)
     */
    public void debug(Object msg) {
      // NOP
    }
  
    /* A NOP implementation.
     * @see org.apache.ugli.Logger#debug(java.lang.Object, java.lang.Object)
     */
    public void debug(Object parameterizedMsg, Object param1) {
      // NOP
    }
  
    /* A NOP implementation.
     * @see org.apache.ugli.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.apache.ugli.Logger#debug(java.lang.Object, java.lang.Throwable)
     */
    public void debug(Object msg, Throwable t) {
      // NOP
    }
  
    /* Always returns false.
     * @see org.apache.ugli.Logger#isInfoEnabled()
     */
    public boolean isInfoEnabled() {
      // NOP
      return false;
    }
  
    /* A NOP implementation.
     * @see org.apache.ugli.Logger#info(java.lang.Object)
     */
    public void info(Object msg) {
      // NOP
    }
  
    /* A NOP implementation.
     * @see org.apache.ugli.Logger#info(java.lang.Object, java.lang.Object)
     */
    public void info(Object parameterizedMsg, Object param1) {
      // NOP
    }
  
    /* A NOP implementation.
     * @see org.apache.ugli.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.apache.ugli.Logger#info(java.lang.Object, java.lang.Throwable)
     */
    public void info(Object msg, Throwable t) {
      // NOP
    }
  
    /* Always returns false.
     * @see org.apache.ugli.Logger#isWarnEnabled()
     */
    public boolean isWarnEnabled() {
      return false;
    }
  
    /* A NOP implementation.
     * @see org.apache.ugli.Logger#warn(java.lang.Object)
     */
    public void warn(Object msg) {
      // NOP
    }
  
    /* A NOP implementation.
     * @see org.apache.ugli.Logger#warn(java.lang.Object, java.lang.Object)
     */
    public void warn(Object parameterizedMsg, Object param1) {
      // NOP
    }
  
    /* A NOP implementation.
     * @see org.apache.ugli.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.apache.ugli.Logger#warn(java.lang.Object, java.lang.Throwable)
     */
    public void warn(Object msg, Throwable t) {
      // NOP
    }
  
    /* Always returns false.
     * @see org.apache.ugli.Logger#isErrorEnabled()
     */
    public boolean isErrorEnabled() {
      return false;
    }
  
    /* A NOP implementation.
     * @see org.apache.ugli.Logger#error(java.lang.Object)
     */
    public void error(Object msg) {
      // NOP
    }
  
    /* A NOP implementation.
     * @see org.apache.ugli.Logger#error(java.lang.Object, java.lang.Object)
     */
    public void error(Object parameterizedMsg, Object param1) {
      // NOP
    }
  
    /* A NOP implementation.
     * @see org.apache.ugli.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.apache.ugli.Logger#error(java.lang.Object, java.lang.Throwable)
     */
    public void error(Object msg, Throwable t) {
      // NOP
    }
  
  }
  
  
  
  1.1                  logging-log4j/src/filtered-java/org/apache/ugli/impl/MessageFormatter.java
  
  Index: MessageFormatter.java
  ===================================================================
  /*
   * Copyright 1999,2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.ugli.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();
    }
  }
  
  
  
  1.1                  logging-log4j/src/filtered-java/org/apache/ugli/impl/JDK14LoggerFA.java
  
  Index: JDK14LoggerFA.java
  ===================================================================
  /*
   * Copyright 1999,2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.ugli.impl;
  
  import org.apache.ugli.LoggerFactoryAdapter;
  import org.apache.ugli.ULogger;
  
  import java.util.HashMap;
  import java.util.Map;
  import java.util.logging.Logger;
  
  
  /**
   * @author ceki
   *
   * To change the template for this generated type comment go to
   * Window>Preferences>Java>Code Generation>Code and Comments
   */
  public class JDK14LoggerFA implements LoggerFactoryAdapter {
    Map map;
  
    public JDK14LoggerFA() {
      map = new HashMap();
    }
  
    /* (non-Javadoc)
     * @see org.apache.ugli.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.apache.ugli.LoggerFactoryAdapter#getLogger(java.lang.String, java.lang.String)
     */
    public ULogger getLogger(String domainName, String subDomainName) {
      return getLogger(domainName);
    }
  }
  
  
  
  1.1                  logging-log4j/src/filtered-java/org/apache/ugli/impl/SimpleLogger.java
  
  Index: SimpleLogger.java
  ===================================================================
  /*
   * Copyright 1999,2004 The Apache Software Foundation.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.ugli.impl;
  
  import org.apache.ugli.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);
    }
  
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org