You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by at...@apache.org on 2003/06/11 12:52:12 UTC

cvs commit: avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/util LoggerUtil.java

atagunov    2003/06/11 03:52:11

  Modified:    logger/src/java/org/apache/avalon/excalibur/logger
                        AbstractLoggerManager.java
                        Log4JConfLoggerManager.java Log4JLoggerManager.java
                        LogKitLoggerManager.java
  Added:       logger/src/java/org/apache/avalon/excalibur/logger
                        Facade.java
               logger/src/java/org/apache/avalon/excalibur/logger/decorator
                        CachingDecorator.java LogToSelfDecorator.java
                        LoggerManagerDecorator.java
                        OverrideDefaultDecorator.java PrefixDecorator.java
               logger/src/java/org/apache/avalon/excalibur/logger/log4j
                        Log4JAdapter.java Log4JConfAdapter.java
               logger/src/java/org/apache/avalon/excalibur/logger/logkit
                        ErrorHandlerAdapter.java LogKitAdapter.java
                        LogKitConfHelper.java LogKitLoggerHelper.java
               logger/src/java/org/apache/avalon/excalibur/logger/util
                        LoggerUtil.java
  Log:
  Modularization of *LogManager building system.
  The system has been modularized to the very bottom.
  Ultimate flexibility :-)
  
  The idea is to reimplement Log4J*LoggerManager and LogKitLoggerManager
  via these new modularized framework, or to switch completely
  to the Facade class.
  
  Revision  Changes    Path
  1.2       +9 -40     avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/AbstractLoggerManager.java
  
  Index: AbstractLoggerManager.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/AbstractLoggerManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractLoggerManager.java	10 Jun 2003 08:29:37 -0000	1.1
  +++ AbstractLoggerManager.java	11 Jun 2003 10:52:10 -0000	1.2
  @@ -55,6 +55,7 @@
   import org.apache.avalon.framework.logger.LogEnabled;
   import org.apache.avalon.framework.activity.Startable;
   import org.apache.avalon.excalibur.logger.util.LoggerSwitch;
  +import org.apache.avalon.excalibur.logger.util.LoggerUtil;
   
   /**
    *
  @@ -76,7 +77,7 @@
    * @author <a href="mailto:giacomo@apache.org">Giacomo Pati</a>
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
    * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
  - * @author <a href="mailto:tagunov at apache.org">Anton Tagunov</a>
  + * @author <a href="http://cvs.apache.org/~atagunov">Anton Tagunov</a>
    * @version CVS $Revision$ $Date$
    * @since 4.0
    */
  @@ -185,9 +186,9 @@
           {
               if ( m_logger.isDebugEnabled() )
               {
  -                final String message = "LogKitLoggerManager: switching logging to " + 
  +                final String message = "LoggerManager: switching logging to " + 
                           "this.getLoggerForCategory('" +
  -                        getFullCategoryName( m_prefix, m_switchTo) + "').";
  +                        LoggerUtil.getFullCategoryName( m_prefix, m_switchTo) + "').";
                   m_logger.debug( message );
               }
   
  @@ -202,9 +203,9 @@
   
               if ( m_logger.isDebugEnabled() )
               {
  -                final String message = "LogKitLoggerManager: have switched logging to " + 
  +                final String message = "LoggerManager: have switched logging to " + 
                           "this.getLoggerForCategory('" +
  -                        getFullCategoryName( m_prefix, m_switchTo) + "').";
  +                        LoggerUtil.getFullCategoryName( m_prefix, m_switchTo) + "').";
                   m_logger.debug( message );
               }
           }
  @@ -212,7 +213,7 @@
           {
               if ( m_logger.isDebugEnabled() )
               {
  -                final String message = "LogKitLoggerManager: m_switchTo is null, " +
  +                final String message = "LoggerManager: switchTo is null, " +
                           "no switch of our own logging.";
                   m_logger.debug( message );
               }
  @@ -224,39 +225,6 @@
       public void stop(){}
   
       /**
  -     * Generates a full category name given a prefix and category.  Either may be
  -     *  null.
  -     *
  -     * @param prefix Prefix or parent category.
  -     * @param category Child category name.
  -     */
  -    protected final String getFullCategoryName( String prefix, String category )
  -    {
  -        if( ( null == prefix ) || ( prefix.length() == 0 ) )
  -        {
  -            if( category == null )
  -            {
  -                return "";
  -            }
  -            else
  -            {
  -                return category;
  -            }
  -        }
  -        else
  -        {
  -            if( ( null == category ) || ( category.length() == 0 ) )
  -            {
  -                return prefix;
  -            }
  -            else
  -            {
  -                return prefix + org.apache.log.Logger.CATEGORY_SEPARATOR + category;
  -            }
  -        }
  -    }
  -
  -    /**
        * Retruns the logger for the <code>""</code> category.
        */
       public final Logger getDefaultLogger()
  @@ -286,7 +254,8 @@
               return m_defaultLoggerOverride;
           }
   
  -        final String fullCategoryName = getFullCategoryName( m_prefix, categoryName );
  +        final String fullCategoryName = 
  +                LoggerUtil.getFullCategoryName( m_prefix, categoryName );
   
           final Logger logger;
           final Logger newLogger;
  
  
  
  1.6       +0 -0      avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/Log4JConfLoggerManager.java
  
  Index: Log4JConfLoggerManager.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/Log4JConfLoggerManager.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  
  
  
  1.17      +1 -1      avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/Log4JLoggerManager.java
  
  Index: Log4JLoggerManager.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/Log4JLoggerManager.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- Log4JLoggerManager.java	10 Jun 2003 08:29:37 -0000	1.16
  +++ Log4JLoggerManager.java	11 Jun 2003 10:52:10 -0000	1.17
  @@ -63,7 +63,7 @@
    * leaves that as an excercise for Log4J's construction.
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @author <a href="mailto:tagunov at apache.org">Anton Tagunov</a>
  + * @author <a href="http://cvs.apache.org/~atagunov">Anton Tagunov</a>
    * @version CVS $Revision$ $Date$
    * @since 4.1
    */
  
  
  
  1.18      +10 -23    avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/LogKitLoggerManager.java
  
  Index: LogKitLoggerManager.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/LogKitLoggerManager.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- LogKitLoggerManager.java	10 Jun 2003 08:29:37 -0000	1.17
  +++ LogKitLoggerManager.java	11 Jun 2003 10:52:10 -0000	1.18
  @@ -63,6 +63,7 @@
   import org.apache.avalon.framework.logger.LogEnabled;
   import org.apache.avalon.framework.logger.LogKitLogger;
   import org.apache.avalon.framework.logger.Logger;
  +import org.apache.avalon.excalibur.logger.util.LoggerUtil;
   import org.apache.log.Hierarchy;
   import org.apache.log.LogTarget;
   import org.apache.log.Priority;
  @@ -77,7 +78,7 @@
    * @author <a href="mailto:giacomo@apache.org">Giacomo Pati</a>
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
    * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
  - * @author <a href="mailto:tagunov at apache.org">Anton Tagunov</a>
  + * @author <a href="http://cvs.apache.org/~atagunov">Anton Tagunov</a>
    * @version CVS $Revision$ $Date$
    * @since 4.0
    */
  @@ -93,9 +94,6 @@
       /** The hierarchy private to LogKitManager */
       private final Hierarchy m_hierarchy;
   
  -    /** The error handler we will supply to m_hierarchy if we create it locally.*/
  -    private OurErrorHandler m_errorHandler;
  -
       /**
        * Creates a new <code>LogKitLoggerManager</code>;
        * one of the preferred constructors.
  @@ -389,8 +387,8 @@
           {
               m_hierarchy = new Hierarchy();
               m_hierarchy.getRootLogger().unsetLogTargets( true );
  -            m_errorHandler = new OurErrorHandler( getLogger() );
  -            m_hierarchy.setErrorHandler( m_errorHandler );
  +            final ErrorHandler errorHandler = new OurErrorHandler( getLogger() );
  +            m_hierarchy.setErrorHandler( errorHandler );
           }
           else
           {
  @@ -410,7 +408,7 @@
        * @throws ContextException if the context is malformed
        */
       public final void contextualize( final Context context )
  -        throws ContextException
  +            throws ContextException
       {
           m_context = context;
       }
  @@ -447,11 +445,6 @@
                         category,
                         true,
                         categories.getAttributeAsBoolean( "additive", false ) );
  -
  -        /**
  -         * This is the last configuration stage, if we to initialize() or start()
  -         * we would call it from that method.
  -         */
       }
   
       /**
  @@ -547,7 +540,8 @@
                   rootLoggerAlive = true;
               }
   
  -            final String fullCategory = getFullCategoryName( parentCategory, category );
  +            final String fullCategory = 
  +                    LoggerUtil.getFullCategoryName( parentCategory, category );
   
               final org.apache.log.Logger logger = m_hierarchy.getLoggerFor( fullCategory );
               m_loggers.put( fullCategory, new LogKitLogger( logger ) );
  @@ -574,6 +568,9 @@
           }
       }
   
  +    /**
  +     * Closes all our LogTargets.
  +     */
       public void dispose()
       {
           final Iterator iterator = m_targets.iterator();
  @@ -584,7 +581,6 @@
               {
                   ( (Closeable)target ).close();
               }
  -
           }
       }
   
  @@ -595,13 +591,6 @@
            * that is really reliable.
            */
           private Logger m_reliableLogger;
  -        private boolean m_wasError = false;
  -        /**
  -         * Access to this variable is not synchronized. Justification: it is only
  -         * intended to be accessed from postConfigure when only one thread
  -         * is assumed to be using the whole LogKitLoggerManager.
  -         */
  -        public boolean getWasError() { return m_wasError; }
   
           OurErrorHandler( final Logger reliableLogger )
           {
  @@ -614,8 +603,6 @@
   
           public void error( final String message, final Throwable throwable, final LogEvent event )
           {
  -            // let them know if they are interested
  -            m_wasError = true;
               // let them know we're not OK
               m_reliableLogger.fatalError( message, throwable );
   
  
  
  
  1.1                  avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/Facade.java
  
  Index: Facade.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
      must not be used to endorse or promote products derived from this  software
      without  prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.avalon.excalibur.logger;
  
  import org.apache.avalon.excalibur.logger.LoggerManager;
  import org.apache.avalon.excalibur.logger.logkit.LogKitAdapter;
  import org.apache.avalon.excalibur.logger.logkit.LogKitLoggerHelper;
  import org.apache.avalon.excalibur.logger.logkit.LogKitConfHelper;
  import org.apache.avalon.excalibur.logger.log4j.Log4JConfAdapter;
  import org.apache.avalon.excalibur.logger.decorator.LogToSelfDecorator;
  import org.apache.avalon.excalibur.logger.decorator.PrefixDecorator;
  import org.apache.avalon.excalibur.logger.decorator.CachingDecorator;
  import org.apache.avalon.excalibur.logger.util.LoggerManagerTee;
  import org.apache.log.Hierarchy;
  
  /**
   * A facade to the modularized *LoggerManager building system.
   * Add methods here to create LoggerManagers to your preference.
   *
   * @author <a href="http://cvs.apache.org/~atagunov">Anton Tagunov</a>
   * @version CVS $Revision: 1.1 $ $Date: 2003/06/11 10:52:10 $
   * @since 4.0
   */
  
  public class Facade
  {
      /**
       * Assemble a new LoggerManager running on top of LogKit
       * configured from a configuration file logging to a supplied
       * logger as a fallback.
       * Use this method as a sample showing how to assemble your
       * own LoggerManager running on top of LogKit flavour.
       */
      public static LoggerManager createLogKitConfigurable( 
              final String prefix, final String switchTo )
      {
          final org.apache.log.Hierarchy hierarchy = new Hierarchy();
  
          final LoggerManager bare = new LogKitAdapter( hierarchy );
          final LoggerManager decorated = applyDecorators( bare, prefix, switchTo );
          final LoggerManagerTee tee = new LoggerManagerTee( decorated );
  
          tee.addTee( new LogKitLoggerHelper( hierarchy ) );
          tee.addTee( new LogKitConfHelper( hierarchy ) );
          tee.makeReadOnly();
  
          return tee;
      }
  
      /**
       * Assemble LoggerManager for Log4J system configured
       * via a configuration file. All the logging errors
       * will go to System.err however.
       */
      public static LoggerManager createLog4JConfigurable(
              final String prefix, final String switchTo )
      {
          final LoggerManager bare = new Log4JConfAdapter();
          final LoggerManager decorated = applyDecorators( bare, prefix, switchTo );
          return decorated;
      }
  
      private static LoggerManager applyDecorators( LoggerManager target,
              final String prefix, final String switchTo )
      {
          if ( switchTo != null )
          {
              target = new LogToSelfDecorator( target, switchTo );
          }
          if ( prefix != null && prefix.length() > 0 )
          {
              target = new PrefixDecorator( target, prefix );
          }
          target = new CachingDecorator( target );
          return target;
      }
  }
  
  
  
  1.1                  avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/decorator/CachingDecorator.java
  
  Index: CachingDecorator.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
      must not be used to endorse or promote products derived from this  software
      without  prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.avalon.excalibur.logger.decorator;
  
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.excalibur.logger.LoggerManager;
  import java.util.Map;
  import java.util.HashMap;
  
  /**
   * This class implements LoggerManager interface by
   * passing all the job to a wrapped LoggerManager,
   * but the returened Loggers are cached.
   *
   * All operations of this class are synchronized via
   * a single lock. As the <code>LoggerManager</code> is
   * not expected to be a performance bottleneck probably
   * this design will be good enough.
   *
   * @author <a href="mailto:giacomo@apache.org">Giacomo Pati</a>
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
   * @author <a href="http://cvs.apache.org/~atagunov">Anton Tagunov</a>
   * @version CVS $Revision: 1.1 $ $Date: 2003/06/11 10:52:10 $
   * @since 4.0
   */
  public class CachingDecorator extends LoggerManagerDecorator
  {
      /**
       * Logger-s cache. 
       * All access synchronized( m_loggers ).
       */
      private final Map m_loggers = new HashMap();
      /**
       * This variable caches the result of 
       * getDefaultLogger(). This class will
       * treat getDefaultLogger() and getLoggerForCategory("")
       * on our wrapped LoggerManager as being potentially
       * different, although all of the existing adapters
       * probably return the same Logger for both.
       *
       * Access synchronized( this );
       */
      private Logger m_defaultLogger = null;
  
      /**
       * Creates a <code>CachingDecorator</code> instance.
       */
      public CachingDecorator( final LoggerManager loggerManager )
      {
          super( loggerManager );
      }
  
      /**
       * Return the Logger for the specified category.
       */
      public Logger getLoggerForCategory( final String categoryName )
      {
          synchronized( m_loggers )
          {
              Logger logger = (Logger) m_loggers.get( categoryName );
  
              if ( logger == null )
              {
                  logger = m_loggerManager.getLoggerForCategory( categoryName );
  
                  if ( logger == null ) 
                  {
                      final String message = "getLoggerForCategory('" +
                              categoryName + "')";
                      throw new NullPointerException( message );
                  }
  
                  m_loggers.put( categoryName, logger );
              }
  
              return logger;
          }
      }
  
      /**
       * Return the default Logger.  Although it is expected
       * that the wrapped loggerManager will return the same
       * as getLoggerForCategory("") we cache the value separtely.
       */
      public Logger getDefaultLogger()
      {
          synchronized( this )
          {
              if ( m_defaultLogger == null )
              {
                  m_defaultLogger = m_loggerManager.getDefaultLogger();
  
                  if ( m_defaultLogger == null )
                  {
                      throw new NullPointerException ( "getDefaultLogger()" );
                  }
              }
              return m_defaultLogger;
          }
      }
  }
  
  
  
  1.1                  avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/decorator/LogToSelfDecorator.java
  
  Index: LogToSelfDecorator.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
      must not be used to endorse or promote products derived from this  software
      without  prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.avalon.excalibur.logger.decorator;
  
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.container.ContainerUtil;
  import org.apache.avalon.excalibur.logger.LoggerManager;
  import org.apache.avalon.excalibur.logger.util.LoggerSwitch;
  
  /**
   *
   * This class intercepts the class passed to us via
   * <code>enableLogging()</code> and substibutes it
   * by <code>LoggerSwitch.get()</code> logger.
   * <p>
   * Later on at the <code>start()</code> stage
   * we assume that our wrapped LoggerManager has already
   * completely initialized itself and extract
   * a <code>Logger</code> from it.
   * <p>
   * <code>LoggerSwitch</code> allowes us to supply this
   * logger to it via <code>LoggerSwitch.setPreferred()</code>.
   * This has the effect of all the log messages directed
   * to <code>LoggerSwitch.get()</code> obtained logger
   * being directed to the new <code>Logger</code> unless
   * a recursion error happens.
   *
   * @author <a href="http://cvs.apache.org/~atagunov">Anton Tagunov</a>
   * @version CVS $Revision: 1.1 $ $Date: 2003/06/11 10:52:10 $
   * @since 4.0
   */
  public class LogToSelfDecorator extends LoggerManagerDecorator
  {
      /* The category to switch our logging to. */
      private final String m_switchTo;
      /* The LoggerSwitch object controlling our substitute Logger. */
      private LoggerSwitch m_switch;
      /** 
       * Our substitute logger obtained from m_switch. 
       * Used for our own logging.
       */
      private Logger m_logger;
  
      /**
       * Creates a LogToSelfDecorator instance.
       * @param switchTo the name of the category we should extract
       *         a Logger and switch our logging to at the 
       *         <code>start()</code> stage; can not be null;
       *         empty value causes logging to be switched to the
       *         "" category.
       */
      public LogToSelfDecorator( final LoggerManager loggerManager, final String switchTo )
      {
          super( loggerManager );
          if ( switchTo == null ) throw new NullPointerException( "switchTo" );
          m_switchTo = switchTo;
      }
  
      /**
       * Substitutes the supplied logger by <code>m_switch.get()</code>.
       * The substiting logger is used both for our own logging and
       * passed onto our decorated <code>LoggerManager</code>.
       * @param logger the logger supplied for us and our wrapped
       *        LoggerManager; we chould survive with a null logger
       *        (LoggerSwitch create a NullLogger in this case), but 
       *        for better error detection we shall rather blow up.
       */
      public void enableLogging( final Logger logger )
      {
          if ( m_switch != null )
          {
              throw new IllegalStateException( "enableLogging() already called" );
          }
  
          if ( logger == null )
          {
              throw new NullPointerException( "logger" );
          }
  
          m_switch = new LoggerSwitch( logger );
          m_logger = m_switch.get();
          ContainerUtil.enableLogging( m_loggerManager, m_logger );
      }
  
      /**
       * Invokes <code>start()</code> on our wrapped
       * <code>LoggerManager</code> and swithces the
       * logger used by us and all objects that we
       * decorate for a logger extracted from our
       * wrapped <code>LoggerManager</code>.
       */
      public void start() throws Exception
      {
          /** 
           * If our LoggerManager is <code>Startable</code>
           * its <code>start()</code> will be invoked now.
           */    
          super.start();
  
          final Logger preferred = m_loggerManager.getLoggerForCategory( m_switchTo );
          if ( m_logger.isDebugEnabled() )
          {
              final String message = "LoggerManager: switching logging to '" + 
                      m_switchTo + "'";
              m_logger.debug( message );
          }
          
          m_switch.setPreferred( preferred );
  
          if ( m_logger.isDebugEnabled() )
          {
              final String message = "LoggerManager: have switched logging to '" + 
                      m_switchTo + "'";
              m_logger.debug( message );
          }
      }
  }
  
  
  
  1.1                  avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/decorator/LoggerManagerDecorator.java
  
  Index: LoggerManagerDecorator.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
      must not be used to endorse or promote products derived from this  software
      without  prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.avalon.excalibur.logger.decorator;
  
  import org.apache.avalon.excalibur.logger.LoggerManager;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.logger.LogEnabled;
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.activity.Startable;
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.container.ContainerUtil;
  
  /**
   * This is the base class to create LoggerManager decorators.
   * It passes all lifecycle and LoggerManagerc
   * calls onto the wrapped object.
   *
   * <p> Decorators are expected to be slim - be able to run
   * for instance both with and without having their 
   * enableLogging() method called.
   *
   * <p> This constraint is imposed to allow decorators to
   * be applicable to an object both at its burth, like
   *
   * <pre>
   * C c = new C();
   * DecoratorX d = new DecoratorX( c );
   * x.enableLogging( logger );
   * </pre>
   *
   * and after the object has been completely configured
   *
   * <pre>
   * C c = (C)manager.lookup( C.ROLE );
   * DecoratorX d = new DecoratorX( c );
   * </pre>
   * 
   * If this constrianed is not obeyed this should be clearly
   * stated in the javadocs. For instance, LogToSelfDecorator
   * _only_ makes sense if it passes the <code>enableLogging</code>
   * call through it.
   *
   * <p>
   * This implementation is incomplete, 
   * it passes only those calls that are needed in
   *
   * <code>org.apache.avalon.excalibur.logger.decorator.*</code> and
   * <code>org.apache.avalon.excalibur.logger.adapter.*</code>:
   * <pre>
   *    LogEnabled
   *    Contextualizable
   *    Configurable
   *    Startable
   *    Disposable
   * </pre>
   *
   * This object differes from LoggerManagerTee by being abstract,
   * by absence of addTee() public method and by implementation.
   * LoggerManagerTee might be used instead of this but maintaining
   * it as a separate class seemed cleaner.
   * 
   * @author <a href="http://cvs.apache.org/~atagunov">Anton Tagunov</a>
   * @version CVS $Revision: 1.1 $ $Date: 2003/06/11 10:52:10 $
   * @since 4.0
   */
  public abstract class LoggerManagerDecorator implements
          LoggerManager, 
          LogEnabled, 
          Contextualizable, 
          Configurable, 
          Startable, 
          Disposable
  {
      /**
       * The wrapped-in LoggerManager.
       */
      protected final LoggerManager m_loggerManager;
  
      public LoggerManagerDecorator( final LoggerManager loggerManager )
      {
          if ( loggerManager == null ) throw new NullPointerException( "loggerManager" );
          m_loggerManager = loggerManager;
      }
  
      public void enableLogging( final Logger logger )
      {
          ContainerUtil.enableLogging( m_loggerManager, logger );
      }
  
      public void contextualize( final Context context ) throws ContextException
      {
          ContainerUtil.contextualize( m_loggerManager, context );
      }
      
      public void configure( final Configuration configuration ) throws ConfigurationException
      {
          ContainerUtil.configure( m_loggerManager, configuration );
      }
  
      public void start() throws Exception
      {
          ContainerUtil.start( m_loggerManager );
      }
  
      public void stop() throws Exception
      {
          ContainerUtil.stop( m_loggerManager );
      }
  
      public void dispose()
      {
          ContainerUtil.dispose( m_loggerManager );
      }
  
      /**
       * Return the Logger for the specified category.
       */
      public Logger getLoggerForCategory( final String categoryName )
      {
          return m_loggerManager.getLoggerForCategory( categoryName );
      }
  
      /**
       * Return the default Logger.  This is basically the same
       * as getting the Logger for the "" category.
       */
      public Logger getDefaultLogger()
      {
          return m_loggerManager.getDefaultLogger();
      }
  }
  
  
  
  1.1                  avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/decorator/OverrideDefaultDecorator.java
  
  Index: OverrideDefaultDecorator.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
      must not be used to endorse or promote products derived from this  software
      without  prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.avalon.excalibur.logger.decorator;
  
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.excalibur.logger.LoggerManager;
  
  /**
   * Overrides the value passed from getDefaultLogger().
   *
   * @author <a href="http://cvs.apache.org/~atagunov">Anton Tagunov</a>
   * @version CVS $Revision: 1.1 $ $Date: 2003/06/11 10:52:10 $
   * @since 4.0
   */
  public class OverrideDefaultDecorator extends LoggerManagerDecorator
  {
      /**
       * The override value for getDefaultLogger() and for 
       * getLoggerForCategory(""), getLoggerForCategory( null );
       */
      private final Logger m_defaultLogger;
  
      /**
       * Creates an <code>OverrideDecorator</code> instance.
       * @param <code>OverrideDecorator</code> is unique in that
       *        it won't tolerate a null extra argument: if this
       *        argument is <code>null</code> a NullPointerException will
       *        be thrown. This ensures that no logging surprises will occur.
       */
      public OverrideDefaultDecorator( 
              final LoggerManager loggerManager, final Logger defaultLogger )
      {
          super( loggerManager );
          if ( defaultLogger == null ) throw new NullPointerException( "defaultLogger" );
          m_defaultLogger = defaultLogger;
      }
  
      /**
       * Return the Logger for the specified category.
       */
      public Logger getLoggerForCategory( final String categoryName )
      {
          if ( categoryName == null || categoryName.length() == 0 )
          {
              return m_defaultLogger;
          }
          else
          {
              return m_loggerManager.getLoggerForCategory( categoryName );
          }
      }
  
      /**
       * Return the default Logger.  This is basically the same
       * as getting the Logger for the "" category.
       */
      public Logger getDefaultLogger()
      {
          return m_defaultLogger;
      }
  }
  
  
  
  1.1                  avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/decorator/PrefixDecorator.java
  
  Index: PrefixDecorator.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
      must not be used to endorse or promote products derived from this  software
      without  prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.avalon.excalibur.logger.decorator;
  
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.excalibur.logger.LoggerManager;
  import org.apache.avalon.excalibur.logger.util.LoggerUtil;
  
  /**
   * This class implements LoggerManager interface by
   * prepending a prefix to all requests and letting the
   * wrapped LoggerManager actually create the loggers.
   *
   * @author <a href="mailto:giacomo@apache.org">Giacomo Pati</a>
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
   * @author <a href="http://cvs.apache.org/~atagunov">Anton Tagunov</a>
   * @version CVS $Revision: 1.1 $ $Date: 2003/06/11 10:52:10 $
   * @since 4.0
   */
  public class PrefixDecorator extends LoggerManagerDecorator implements LoggerManager
  {
      private final String m_prefix;
  
      /**
       * Creates a PrefixDecorator instance.
       * @param prefix the prefix to prepend; 
       *         can be neither null nor empty. 
       *         This is done to avoid ambiguity 
       *         in the getDefaultLogger() method - what would we call
       *         in such case getDefaultLogger() or getLoggerForCategory("") ?
       *
       */
      public PrefixDecorator( final LoggerManager loggerManager, final String prefix )
      {
          super( loggerManager );
          if ( prefix == null ) throw new NullPointerException( "prefix" );
          if ( "".equals( prefix ) ) throw new IllegalArgumentException( "prefix can't be empty" );
          m_prefix = prefix;
      }
  
      /**
       * Return the Logger for the specified category.
       */
      public Logger getLoggerForCategory( final String categoryName )
      {
          final String fullCategoryName = LoggerUtil.getFullCategoryName( m_prefix, categoryName );
          return m_loggerManager.getLoggerForCategory( fullCategoryName );
      }
  
      /**
       * Return the default Logger.  This is basically the same
       * as getting the Logger for the "" category. 
       */
      public Logger getDefaultLogger()
      {
          final String fullCategoryName = LoggerUtil.getFullCategoryName( m_prefix, null );
          return m_loggerManager.getLoggerForCategory( fullCategoryName );
      }
  }
  
  
  
  1.1                  avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/log4j/Log4JAdapter.java
  
  Index: Log4JAdapter.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
      must not be used to endorse or promote products derived from this  software
      without  prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.avalon.excalibur.logger.log4j;
  
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.excalibur.logger.LoggerManager;
  import org.apache.log4j.spi.LoggerRepository;
  import org.apache.avalon.framework.logger.Log4JLogger;
  
  /**
   * This class sits on top of an existing Log4J Hierarchy
   * and returns logger wrapping Log4J loggers.
   *
   * Attach PrefixDecorator and/or CachingDecorator if desired.
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   * @author <a href="http://cvs.apache.org/~atagunov">Anton Tagunov</a>
   * @version CVS $Revision: 1.1 $ $Date: 2003/06/11 10:52:10 $
   * @since 4.0
   */
  public class Log4JAdapter extends AbstractLogEnabled implements LoggerManager
  {
      protected final LoggerRepository m_hierarchy;
  
      public Log4JAdapter( final LoggerRepository hierarchy )
      {
          if ( hierarchy == null ) throw new NullPointerException( "hierarchy" );
          m_hierarchy = hierarchy;
      }
  
      /**
       * Return the Logger for the specified category.
       */
      public Logger getLoggerForCategory( final String categoryName )
      {
          return new Log4JLogger( m_hierarchy.getLogger( categoryName ) );
      }
  
      /**
       * Return the default Logger.  This is basically the same
       * as getting the Logger for the "" category.
       */
      public Logger getDefaultLogger()
      {
          return getLoggerForCategory( "" );
      }
  }
  
  
  
  1.1                  avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/log4j/Log4JConfAdapter.java
  
  Index: Log4JConfAdapter.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
      must not be used to endorse or promote products derived from this  software
      without  prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.avalon.excalibur.logger.log4j;
  
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.log4j.spi.LoggerRepository;
  import org.apache.avalon.framework.configuration.ConfigurationUtil;
  import org.apache.log4j.Hierarchy;
  import org.apache.log4j.Level;
  import org.apache.log4j.spi.RootCategory;
  import org.apache.log4j.xml.DOMConfigurator;
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  import org.w3c.dom.Node;
  import org.w3c.dom.NodeList;
  
  /**
   * A LoggerManager for Log4j that will configure the Log4j subsystem
   * using specified configuration.
   * <p>
   * Note that in case of logging errors Log4J will (via the
   * org.apache.log4j.helpers.LogLog class) write to System.err.
   * This can be switched off but we can not substitute our
   * own handler to log erros the way we prefer to do this. :-(
   *
   * <p>
   * So, unlike the LogKit case we have no Log4JLogger helper to
   * implement and hence a different architecture: this class
   * is not a helper but a regular subclass of Log4JAdapter.
   *
   * <p>
   * Attach PrefixDecorator and/or CachingDecorator if desired.
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   * @author <a href="http://cvs.apache.org/~atagunov">Anton Tagunov</a>
   * @version CVS $Revision: 1.1 $ $Date: 2003/06/11 10:52:10 $
   * @since 4.0
   */
  public class Log4JConfAdapter extends Log4JAdapter implements Configurable
  {
      /**
       * This constructor creates a completely independent
       * Log4J hierarchy. If you want to log to an existing
       * Log4J hierarchy please use Log4JAdapter. This class
       * always creates a new private hierarchy and configures
       * it all by itself.
       */
      public Log4JConfAdapter()
      {
          /** 
           * Copied from org.apache.log4j.LogManager.
           */
          super( new Hierarchy( new RootCategory( Level.ALL ) ) );
      }
  
      /**
       * Feed our configuration to Log4J.
       */
      public void configure( final Configuration configuration )
          throws ConfigurationException
      {
          final Element element = ConfigurationUtil.toElement( configuration );
          final Document document = element.getOwnerDocument();
          final Element newElement = document.createElement( "log4j:configuration" );
          final NodeList childNodes = element.getChildNodes();
          final int length = childNodes.getLength();
          for( int i = 0; i < length; i++ )
          {
              final Node node = childNodes.item( i );
              final Node newNode = node.cloneNode( true );
              newElement.appendChild( newNode );
          }
  
          document.appendChild( newElement );
  
          /**
           * Copied from org.apache.log4j.xml.DomConfigurator configure().
           * We want our own hierarchy to be configured, so we shall
           * be a bit more elaborate then just calling configure().
           */
          final DOMConfigurator domConfigurator = new DOMConfigurator();
          domConfigurator.doConfigure( newElement, m_hierarchy );
      }
  }
  
  
  
  1.1                  avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/logkit/ErrorHandlerAdapter.java
  
  Index: ErrorHandlerAdapter.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
      must not be used to endorse or promote products derived from this  software
      without  prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.avalon.excalibur.logger.logkit;
  
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.log.ErrorHandler;
  import org.apache.log.Priority;
  import org.apache.log.LogEvent;
  
  /**
   * This class adapts o.a.a.f.logger.Logger
   * to the LogKit ErrorHandler interface.
   *
   * @author <a href="http://cvs.apache.org/~atagunov">Anton Tagunov</a>
   * @version CVS $Revision: 1.1 $ $Date: 2003/06/11 10:52:11 $
   * @since 4.0
   */
  
  public class ErrorHandlerAdapter implements ErrorHandler
  {
      private final Logger m_reliableLogger;
  
      public ErrorHandlerAdapter( final Logger reliableLogger )
      {
         if ( reliableLogger == null )
         {
             throw new NullPointerException( "reliableLogger" );
         }
         m_reliableLogger = reliableLogger;
      }
  
      public void error( final String message, final Throwable throwable, final LogEvent event )
      {
          // let them know we're not OK
          m_reliableLogger.fatalError( message, throwable );
  
          // transmit the original error
          final Priority p = event.getPriority();
          final String nestedMessage = "nested log event: " + event.getMessage();
  
          if ( p == Priority.DEBUG )
          {
              m_reliableLogger.debug( nestedMessage, event.getThrowable() );
          }
          else if ( p == Priority.INFO )
          {
              m_reliableLogger.info( nestedMessage, event.getThrowable() );
          }
          else if ( p == Priority.WARN )
          {
              m_reliableLogger.warn( nestedMessage, event.getThrowable() );
          }
          else if ( p == Priority.ERROR )
          {
              m_reliableLogger.error( nestedMessage, event.getThrowable() );
          }
          else if ( p == Priority.FATAL_ERROR)
          {
              m_reliableLogger.fatalError( nestedMessage, event.getThrowable() );
          }
          else
          {
              /** This just plainly can't happen :-)*/
              m_reliableLogger.error( "unrecognized priority " + nestedMessage, 
                  event.getThrowable() );
          }
      }
  }
  
  
  
  1.1                  avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/logkit/LogKitAdapter.java
  
  Index: LogKitAdapter.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
      must not be used to endorse or promote products derived from this  software
      without  prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.avalon.excalibur.logger.logkit;
  
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.excalibur.logger.LoggerManager;
  import org.apache.avalon.framework.logger.LogKitLogger;
  import org.apache.log.Hierarchy;
  
  /**
   * This class sits on top of an existing LogKit Hierarchy
   * and returns logger wrapping LogKit loggers.
   *
   * Attach PrefixDecorator and/or CachingDecorator if desired.
   *
   * @author <a href="mailto:giacomo@apache.org">Giacomo Pati</a>
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
   * @author <a href="http://cvs.apache.org/~atagunov">Anton Tagunov</a>
   * @version CVS $Revision: 1.1 $ $Date: 2003/06/11 10:52:11 $
   * @since 4.0
   */
  public class LogKitAdapter extends AbstractLogEnabled implements LoggerManager
  {
      /**
       * The hierarchy that really produces loggers.
       */
      protected final Hierarchy m_hierarchy;
  
      /**
       * Initialized <code>LogKitAdapter</code> to operate
       * of a certain LogKit <code>Hierarchy</code>.
       */
      public LogKitAdapter( final Hierarchy hierarchy )
      {
          if ( hierarchy == null ) throw new NullPointerException( "hierarchy" );
          m_hierarchy = hierarchy;
      }
  
      /**
       * Return the Logger for the specified category.
       */
      public Logger getLoggerForCategory( final String categoryName )
      {
          return new LogKitLogger( m_hierarchy.getLoggerFor( categoryName ) );
      }
  
      /**
       * Return the default Logger.  This is basically the same
       * as getting the Logger for the "" category.
       */
      public Logger getDefaultLogger()
      {
          return new LogKitLogger( m_hierarchy.getRootLogger() );
      }
  }
  
  
  
  1.1                  avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/logkit/LogKitConfHelper.java
  
  Index: LogKitConfHelper.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
      must not be used to endorse or promote products derived from this  software
      without  prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.avalon.excalibur.logger.logkit;
  
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.excalibur.logger.LogTargetFactory;
  import org.apache.avalon.excalibur.logger.LogTargetFactoryManager;
  import org.apache.avalon.excalibur.logger.DefaultLogTargetFactoryManager;
  import org.apache.avalon.excalibur.logger.LogTargetFactoryManageable;
  import org.apache.avalon.excalibur.logger.LogTargetFactoryManager;
  import org.apache.avalon.excalibur.logger.DefaultLogTargetManager;
  import org.apache.avalon.excalibur.logger.LogTargetManager;
  import org.apache.avalon.excalibur.logger.util.LoggerUtil;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.container.ContainerUtil;
  import org.apache.log.LogTarget;
  import org.apache.log.Priority;
  import org.apache.log.util.Closeable;
  import java.util.Set;
  import java.util.HashSet;
  import java.util.Iterator;
  import org.apache.log.Hierarchy;
  
  /**
   * Tie this object to a LoggerManagerTee, give it the Hierachy
   * that LogKitAdapter operates upon and it will populate it
   * from the Configuration object passed via configure().
   * Note: this class assumes that this is a new Hierarchy,
   * freshly created with new Hierarchy() not populated before.
   *
   * @author <a href="mailto:giacomo@apache.org">Giacomo Pati</a>
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
   * @author <a href="http://cvs.apache.org/~atagunov">Anton Tagunov</a>
   * @version CVS $Revision: 1.1 $ $Date: 2003/06/11 10:52:11 $
   * @since 4.0
   */
  public class LogKitConfHelper extends AbstractLogEnabled implements
          Contextualizable,
          Configurable,
          Disposable
  {
      /* The hierarchy to operate upon */
      private final Hierarchy m_hierarchy;
  
      /* Creates an instance of LogKitLoggerHelper. */
      public LogKitConfHelper( final Hierarchy hierarchy )
      {
          if ( hierarchy == null ) throw new NullPointerException( "hierarchy" );
          m_hierarchy = hierarchy;
      }
  
      /** Set of log targets */
      final private Set m_targets = new HashSet();
  
      /** The context object */
      private Context m_context;
  
      /**
       * Reads a context object that will be supplied to the log target factory manager.
       *
       * @param context The context object.
       * @throws ContextException if the context is malformed
       */
      public final void contextualize( final Context context )
              throws ContextException
      {
          m_context = context;
      }
  
      /**
       * Populates the underlying <code>Hierarchy</code>.
       *
       * @param configuration  The configuration object.
       * @throws ConfigurationException if the configuration is malformed
       */
      public final void configure( final Configuration configuration )
          throws ConfigurationException
      {
          final Configuration factories = configuration.getChild( "factories" );
          final LogTargetFactoryManager targetFactoryManager = setupTargetFactoryManager( factories );
  
          final Configuration targets = configuration.getChild( "targets" );
          final LogTargetManager targetManager = setupTargetManager( targets, targetFactoryManager );
  
          final Configuration categories = configuration.getChild( "categories" );
          final Configuration[] category = categories.getChildren( "category" );
          setupLoggers( targetManager,
                        null,
                        category,
                        true,
                        categories.getAttributeAsBoolean( "additive", false ) );
      }
  
      /**
       * Setup a LogTargetFactoryManager
       *
       * @param configuration  The configuration object.
       * @throws ConfigurationException if the configuration is malformed
       */
      private final LogTargetFactoryManager setupTargetFactoryManager( 
              final Configuration configuration )
          throws ConfigurationException
      {
          final DefaultLogTargetFactoryManager targetFactoryManager = new DefaultLogTargetFactoryManager();
  
          ContainerUtil.enableLogging( targetFactoryManager, getLogger() );
  
          try
          {
              ContainerUtil.contextualize( targetFactoryManager, m_context );
          }
          catch( final ContextException ce )
          {
              throw new ConfigurationException( "cannot contextualize default factory manager", ce );
          }
  
          ContainerUtil.configure( targetFactoryManager, configuration );
  
          return targetFactoryManager;
      }
  
      /**
       * Setup a LogTargetManager
       *
       * @param configuration  The configuration object.
       * @throws ConfigurationException if the configuration is malformed
       */
      private final LogTargetManager setupTargetManager( final Configuration configuration,
              final LogTargetFactoryManager targetFactoryManager )
          throws ConfigurationException
      {
          final DefaultLogTargetManager targetManager = new DefaultLogTargetManager();
  
          ContainerUtil.enableLogging( targetManager, getLogger() );
  
          if( targetManager instanceof LogTargetFactoryManageable )
          {
              targetManager.setLogTargetFactoryManager( targetFactoryManager );
          }
  
          ContainerUtil.configure( targetManager, configuration );
  
          return targetManager;
      }
  
      /**
       * Setup Loggers
       *
       * @param categories []  The array object of configurations for categories.
       * @param root shows if we're processing the root of the configuration
       * @throws ConfigurationException if the configuration is malformed
       */
      private final void setupLoggers( final LogTargetManager targetManager,
                                       final String parentCategory,
                                       final Configuration[] categories,
                                       boolean root,
                                       final boolean defaultAdditive )
          throws ConfigurationException
      {
          boolean rootLoggerAlive = false;
  
          for( int i = 0; i < categories.length; i++ )
          {
              final String category = categories[ i ].getAttribute( "name" );
              final String loglevel = categories[ i ].getAttribute( "log-level" ).toUpperCase();
              final boolean additive = categories[ i ].
                  getAttributeAsBoolean( "additive", defaultAdditive );
  
              final Configuration[] targets = categories[ i ].getChildren( "log-target" );
              final LogTarget[] logTargets = new LogTarget[ targets.length ];
              for( int j = 0; j < targets.length; j++ )
              {
                  final String id = targets[ j ].getAttribute( "id-ref" );
                  logTargets[ j ] = targetManager.getLogTarget( id );
                  if( !m_targets.contains( logTargets[ j ] ) )
                  {
                      m_targets.add( logTargets[ j ] );
                  }
              }
  
              if( root && "".equals( category ) && logTargets.length > 0 )
              {
                  m_hierarchy.setDefaultPriority( Priority.getPriorityForName( loglevel ) );
                  m_hierarchy.setDefaultLogTargets( logTargets );
                  rootLoggerAlive = true;
              }
  
              final String fullCategory = 
                      LoggerUtil.getFullCategoryName( parentCategory, category );
  
              final org.apache.log.Logger logger = m_hierarchy.getLoggerFor( fullCategory );
  
              if( getLogger().isDebugEnabled() )
              {
                  /**
                   * We have to identify ourselves here via 'LogKitConfHelper:'
                   * because we are likely be logging directly to a bootstrap
                   * logger and this logger has no categories.
                   */
                  final String message = "LogKitConfHelper: adding logger for category '" +
                          fullCategory + "'";
                  getLogger().debug( message );
              }
              logger.setPriority( Priority.getPriorityForName( loglevel ) );
              logger.setLogTargets( logTargets );
              logger.setAdditivity( additive );
  
              final Configuration[] subCategories = categories[ i ].getChildren( "category" );
              if( null != subCategories )
              {
                  setupLoggers( targetManager, fullCategory, subCategories, false, defaultAdditive );
              }
          }
  
          if ( root && !rootLoggerAlive )
          {
              /**
               * We have to identify ourselves here via 'LogKitConfHelper:'
               * because we are likely be logging directly to a bootstrap
               * logger and this logger has no categories.
               */
              final String message = "LogKitConfHelper: " +
                      "No log targets configured for the root logger.";
  
              throw new ConfigurationException( message );
          }
      }
  
      /**
       * Closes all our LogTargets.
       */
      public void dispose()
      {
          final Iterator iterator = m_targets.iterator();
          while( iterator.hasNext() )
          {
              final LogTarget target = (LogTarget)iterator.next();
              if( target instanceof Closeable )
              {
                  ( (Closeable)target ).close();
              }
          }
      }
  }
  
  
  
  1.1                  avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/logkit/LogKitLoggerHelper.java
  
  Index: LogKitLoggerHelper.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
      must not be used to endorse or promote products derived from this  software
      without  prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.avalon.excalibur.logger.logkit;
  
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.logger.LogEnabled;
  import org.apache.log.Hierarchy;
  
  
  /**
   * Tie this object to a LoggerManagerTee, give it the Hierachy
   * that LogKitAdapter operates upon and it will substitute
   * the ErrorHandler for the Hierarchy at the enableLogging() call.
   *
   * @author <a href="http://cvs.apache.org/~atagunov">Anton Tagunov</a>
   * @version CVS $Revision: 1.1 $ $Date: 2003/06/11 10:52:11 $
   * @since 4.0
   */
  public class LogKitLoggerHelper implements LogEnabled
  {
      /* The hierarchy to operate upon */
      private final Hierarchy m_hierarchy;
  
      /* Creates an instance of LogKitLoggerHelper. */
      public LogKitLoggerHelper( final Hierarchy hierarchy )
      {
          if ( hierarchy == null ) throw new NullPointerException( "hierarchy" );
          m_hierarchy = hierarchy;
      }
  
      /* The main work - creation of a custom ErrorHandler is done here. */
      public void enableLogging( final Logger logger )
      {
           if ( logger == null ) throw new NullPointerException( "logger" );
           final ErrorHandlerAdapter errorHandler = new ErrorHandlerAdapter( logger );
           m_hierarchy.setErrorHandler( errorHandler );
      }
  }
  
  
  
  1.1                  avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/util/LoggerUtil.java
  
  Index: LoggerUtil.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
      must not be used to endorse or promote products derived from this  software
      without  prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.avalon.excalibur.logger.util;
  
  /**
   * This class implements utility methods for building LoggerManager-s.
   *
   * @author <a href="mailto:giacomo@apache.org">Giacomo Pati</a>
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   * @author <a href="mailto:proyal@apache.org">Peter Royal</a>
   * @author <a href="http://cvs.apache.org/~atagunov">Anton Tagunov</a>
   * @version CVS $Revision: 1.1 $ $Date: 2003/06/11 10:52:11 $
   * @since 4.0
   */
  public class LoggerUtil
  {
      /**
       * Generates a full category name given a prefix and category.  Either may be
       *  null.
       *
       * @param prefix Prefix or parent category.
       * @param category Child category name.
       */
      public static String getFullCategoryName( final String prefix, final String category )
      {
          if( ( null == prefix ) || ( prefix.length() == 0 ) )
          {
              if( category == null )
              {
                  return "";
              }
              else
              {
                  return category;
              }
          }
          else
          {
              if( ( null == category ) || ( category.length() == 0 ) )
              {
                  return prefix;
              }
              else
              {
                  return prefix + org.apache.log.Logger.CATEGORY_SEPARATOR + category;
              }
          }
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org