avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon/merlin/logging/logkit/test/src/test/org/apache/avalon/logging/logkit/test DefaultLoggingManagerTestCase.java
Date Tue, 27 Jan 2004 19:27:23 GMT
mcconnell    2004/01/27 11:27:23

  Modified:    merlin/logging/api/src/java/org/apache/avalon/logging/provider
                        package.html
               merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit
                        DefaultLogTargetManager.java
                        DefaultLoggingFactory.java
                        DefaultLoggingManager.java Resources.properties
                        StandardFormatter.java
               merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/factory
                        DatagramTargetFactory.java FileTargetFactory.java
                        Resources.properties SocketTargetFactory.java
                        StreamTargetFactory.java
               merlin/logging/logkit/test/conf logging.xml
               merlin/logging/logkit/test/src/test/org/apache/avalon/logging/logkit/test
                        DefaultLoggingManagerTestCase.java
  Added:       merlin/logging/api/src/java/org/apache/avalon/logging/data
                        package.html
               merlin/logging/logkit/api/src/java/org/apache/avalon/logging/logkit
                        FormatterFactory.java
               merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit
                        DefaultFormatterFactory.java
                        DefaultLogTargetFactoryManager.java
               merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/factory
                        MulticastTargetFactory.java
  Removed:     merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/factory
                        FormatterFactory.java
  Log:
  Improvements ot the log target factory construction and better handling of the formatter factory.
  
  Revision  Changes    Path
  1.1                  avalon/merlin/logging/api/src/java/org/apache/avalon/logging/data/package.html
  
  Index: package.html
  ===================================================================
  <body>
  <p>The <code>data</code> package contains the principal meta-data directives used to describe logging categories.
  </p>
  </body>
  
  
  
  1.2       +3 -3      avalon/merlin/logging/api/src/java/org/apache/avalon/logging/provider/package.html
  
  Index: package.html
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/logging/api/src/java/org/apache/avalon/logging/provider/package.html,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- package.html	24 Jan 2004 23:25:32 -0000	1.1
  +++ package.html	27 Jan 2004 19:27:22 -0000	1.2
  @@ -1,7 +1,7 @@
   <body>
  -<p>The <code>logging</code> package contains the
  -{@link org.apache.avalon.composition.logging.LoggingManager} which
  -is an interface to the initial bootstrap logging mananager that uses mata information
  +<p>The <code>provider</code> package contains the
  +{@link org.apache.avalon.logging.LoggingManager} which
  +is an interface to the initial logging mananagement system that leverages mata information
   about logging targets and catagories.
   </p>
   </body>
  
  
  
  1.1                  avalon/merlin/logging/logkit/api/src/java/org/apache/avalon/logging/logkit/FormatterFactory.java
  
  Index: FormatterFactory.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.logging.logkit;
  
  import org.apache.avalon.framework.configuration.Configuration;
  
  import org.apache.log.format.Formatter;
  
  /**
   * Factory for Formatter-s.
   */
  public interface FormatterFactory
  {
      String DEFAULT_FORMAT =
         "[%7.7{priority}] (%{category}): %{message}\\n%{throwable}";
  
     /**
      * Creation of a new formatter using a supplied configuration.
      * @param config the formatter configuration
      * @return the formatter instance
      * @exception IllegalArgumentException if the formatter type is unknown
      */
      public Formatter createFormatter( final Configuration conf );
  
     /**
      * Creation of a new formatter.
      * @param type the formatter type
      * @param pattern the formatter pattern
      * @return the formatter
      * @exception IllegalArgumentException if the formatter type is unknown
      */
      Formatter createFormatter( String type, String pattern );
  }
  
  
  
  1.2       +4 -3      avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/DefaultLogTargetManager.java
  
  Index: DefaultLogTargetManager.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/DefaultLogTargetManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultLogTargetManager.java	24 Jan 2004 23:25:33 -0000	1.1
  +++ DefaultLogTargetManager.java	27 Jan 2004 19:27:23 -0000	1.2
  @@ -53,7 +53,8 @@
       //---------------------------------------------------------------
   
       private static final Resources REZ =
  -      ResourceManager.getPackageResources( LogTargetManager.class );
  +      ResourceManager.getPackageResources( 
  +        DefaultLogTargetManager.class );
   
       //---------------------------------------------------------------
       // state
  @@ -82,9 +83,9 @@
       }
   
       //---------------------------------------------------------------
  -    // implementation
  +    // LogTargetManager
       //---------------------------------------------------------------
  -
  +    
      /**
       * Return a log target using a supplied target id.  If the 
       * supplied id is unknown a null value is returned.
  
  
  
  1.4       +107 -149  avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/DefaultLoggingFactory.java
  
  Index: DefaultLoggingFactory.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/DefaultLoggingFactory.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultLoggingFactory.java	26 Jan 2004 19:23:40 -0000	1.3
  +++ DefaultLoggingFactory.java	27 Jan 2004 19:27:23 -0000	1.4
  @@ -27,6 +27,7 @@
   import java.lang.reflect.Method ;
   
   import org.apache.avalon.framework.logger.Logger;
  +import org.apache.avalon.framework.logger.ConsoleLogger;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationException;
   import org.apache.avalon.framework.configuration.DefaultConfiguration;
  @@ -62,12 +63,24 @@
       private static final Resources REZ =
         ResourceManager.getPackageResources( DefaultLoggingFactory.class );
   
  +    private static final FormatterFactory FORMATTER = 
  +      new DefaultFormatterFactory();
  +
       //--------------------------------------------------------------------------
       // immutable state
       //--------------------------------------------------------------------------
   
       private final ClassLoader m_classloader;
       private final InitialContext m_context;
  +    
  +    //--------------------------------------------------------------------------
  +    // state
  +    //--------------------------------------------------------------------------
  +
  +    private Logger m_logger;
  +    private File m_basedir;
  +    private LogTargetFactoryManager m_factories;
  +    private LogTargetManager m_targets;
   
       //--------------------------------------------------------------------------
       // constructor
  @@ -126,28 +139,33 @@
           final LoggingCriteria criteria = getLoggingCriteria( map );
   
           //
  -        // get the logging system configuration
  +        // get the logging system configuration, base directory
  +        // and bootstrap logger and setup the primary managers
           //
   
  -        final Logger logger = criteria.getBootstrapLogger();
  -        final File basedir = criteria.getBaseDirectory();
           final Configuration config = criteria.getConfiguration();
  +        m_logger = setUpBootstrapLogger( criteria, config );
  +        m_basedir = criteria.getBaseDirectory();
  +
  +        Map factoriesMap = new HashMap();
  +        m_factories = new DefaultLogTargetFactoryManager( factoriesMap );
  +
  +        Map targetsMap = new HashMap();
  +        m_targets = new DefaultLogTargetManager( targetsMap );
   
           //
           // setup the logging target factories
           //
   
           final Configuration factoriesConfig = config.getChild( "factories" );
  -        final LogTargetFactoryManager factories = 
  -          setupTargetFactories( logger, basedir, factoriesConfig );
  +        setupTargetFactories( factoriesMap, factoriesConfig );
   
           //
           // setup the logging targets
           //
   
           final Configuration targetsConfig = config.getChild( "targets" );
  -        final Map targetsMap = setupTargets( logger, factories, targetsConfig );
  -        final LogTargetManager targets = new DefaultLogTargetManager( targetsMap );
  +        setupTargets( targetsMap, targetsConfig );
   
           //
           // setup the logging categories directive
  @@ -168,7 +186,7 @@
           //
   
           LoggingManager manager = 
  -          new DefaultLoggingManager( logger, targets, categories, internal, false );
  +          new DefaultLoggingManager( m_logger, m_targets, categories, internal, false );
   
           //
           // setup the default log target
  @@ -193,19 +211,28 @@
           }
       }
   
  +    private Logger setUpBootstrapLogger( LoggingCriteria criteria, Configuration config )
  +    {
  +        if( config.getAttribute( "debug", "false" ).equals( "true" ) )
  +        {
  +            return new ConsoleLogger( ConsoleLogger.LEVEL_DEBUG );
  +        }
  +        else
  +        {
  +            return criteria.getBootstrapLogger();
  +        }
  +    }
  +
       /**
        * Create the log target factories.
        *
        * @param config the factory configuration element.
  -     * @throws ConfigurationException if the configuration is malformed
  +     * @throws LoggingException if an error occurs in factor directive parsing
        */
  -    private LogTargetFactoryManager setupTargetFactories( 
  -      final Logger logger, File basedir, final Configuration config )
  +    private void setupTargetFactories( 
  +      final Map factories, final Configuration config )
         throws LoggingException
       {
  -        Map factories = new HashMap();
  -        LogTargetFactoryManager manager = 
  -          new StandardLogTargetFactoryManager( factories );
           Configuration[] children = config.getChildren();
           for( int i = 0; i < children.length; i++ )
           {
  @@ -216,14 +243,14 @@
                   try
                   {
                       LogTargetFactory factory =
  -                      createLogTargetFactory( manager, basedir, child );
  +                      createLogTargetFactory( child );
                       factories.put( key, factory );
                   }
                   catch( LoggingException e )
                   {
                       final String error = 
                        REZ.getString( "factory.target-factory.load.error", key );
  -                    logger.error( error, e );
  +                    m_logger.error( error, e );
                   }
               }
               else
  @@ -235,10 +262,9 @@
                       "factory.target-factory.unknown-element", 
                       name, 
                       listing );
  -                logger.error( error );
  +                m_logger.error( error );
               }
           }
  -        return manager;
       }
   
      /**
  @@ -248,12 +274,9 @@
       *    are resolved
       * @param config the log targets configuration
       */
  -    private Map setupTargets( 
  -      final Logger logger, final LogTargetFactoryManager manager, 
  -      final Configuration config )
  +    private void setupTargets( final Map targets, final Configuration config )
         throws LoggingException
       {
  -        Map targets = new HashMap();
           Configuration[] children = config.getChildren();
           for( int i = 0; i < children.length; i++ )
           {
  @@ -261,11 +284,11 @@
               try
               {
                   final String id = getTargetId( child );
  -                final LogTarget target = createLogTarget( manager, child );
  +                final LogTarget target = createLogTarget( child );
                   targets.put( id, target );
                   final String message = 
                     REZ.getString( "target.notice.add", id );
  -                logger.debug( message );
  +                m_logger.debug( message );
               }
               catch( Throwable e )
               {
  @@ -273,10 +296,9 @@
                     REZ.getString( "target.notice.fail", child.getName() );
                   final String error = 
                     "Could not load a declared log target.";
  -                logger.error( error, e );
  +                m_logger.error( error, e );
               }
           }
  -        return targets;
       }
   
      /**
  @@ -286,12 +308,11 @@
       * @return the logging target
       * @exception Exception if an error occurs during factory creation
       */ 
  -    private LogTarget createLogTarget( 
  -      final LogTargetFactoryManager manager, final Configuration config )
  +    private LogTarget createLogTarget( final Configuration config )
         throws LoggingException
       {
            final String key = getTargetFactoryKey( config );
  -         final LogTargetFactory factory = manager.getLogTargetFactory( key );
  +         final LogTargetFactory factory = m_factories.getLogTargetFactory( key );
            if( factory == null )
            {
               final String message = 
  @@ -418,110 +439,75 @@
       }
   
      /**
  -    * <p>Create a new logging target factory instance.  A logging target must 
  -    * implement one of the following constructor patterns:</p>
  -    * <ul>
  -    * <li>[InitialContext, ClassLoader, LogTargetFactoryManager, File]</li>
  -    * <li>[ClassLoader, LogTargetFactoryManager, File]</li>
  -    * <li>[LogTargetFactoryManager, File]</li>
  -    * <li>[LogTargetFactoryManager]</li>
  -    * <li>[File]</li>
  -    * <li>[]</li>
  -    * </ul>
  -    */
  -    private LogTargetFactory createLogTargetFactory( 
  -      LogTargetFactoryManager manager, File basedir, 
  -      Configuration config ) 
  +    * Create a new logging target factory instance.
  +    */
  +    private LogTargetFactory createLogTargetFactory( Configuration config ) 
         throws LoggingException
       {
           String classname = getFactoryClassname( config );
  -
           Class clazz = loadFactoryClass( classname );
  +        return buildLogTargetFactoryViaConstructor( clazz );
  +    }
   
  -        try
  +    private LogTargetFactory buildLogTargetFactoryViaConstructor( Class clazz ) 
  +      throws LoggingException
  +    {
  +        Constructor[] constructors = clazz.getConstructors();
  +        if( constructors.length < 1 ) 
           {
  -            Constructor constructor = 
  -              clazz.getConstructor( 
  -                new Class[]{ 
  -                  InitialContext.class, 
  -                  ClassLoader.class,
  -                  LogTargetFactoryManager.class,
  -                  File.class } );
  -            return createLogTargetFactory( 
  -              constructor, new Object[]{ 
  -                m_context, m_classloader, manager, basedir } );
  +            final String error = 
  +              REZ.getString( 
  +                "factory.error.no-constructor", 
  +                clazz.getName() );
  +            throw new LoggingException( error );
           }
  -        catch( NoSuchMethodException e )
  +
  +        //
  +        // log target factories only have one constructor
  +        //
  +
  +        Constructor constructor = constructors[0];
  +        Class[] classes = constructor.getParameterTypes();
  +        Object[] args = new Object[ classes.length ];
  +        for( int i=0; i<classes.length; i++ )
           {
  -            try
  +            Class c = classes[i];
  +            if( File.class.isAssignableFrom( c ) )
               {
  -                Constructor constructor = 
  -                  clazz.getConstructor( 
  -                    new Class[]{ 
  -                      ClassLoader.class,
  -                      LogTargetFactoryManager.class,
  -                      File.class } );
  -                return createLogTargetFactory( 
  -                  constructor, new Object[]{ 
  -                    m_classloader, manager, basedir } );
  +                args[i] = m_basedir;
               }
  -            catch( NoSuchMethodException ee )
  +            else if( Logger.class.isAssignableFrom( c ) )
               {
  -                try
  -                {
  -                    Constructor constructor = 
  -                      clazz.getConstructor( 
  -                        new Class[]{ 
  -                          LogTargetFactoryManager.class,
  -                          File.class } );
  -                    return createLogTargetFactory( 
  -                      constructor, new Object[]{ 
  -                        manager, basedir } );
  -                }
  -                catch( NoSuchMethodException eee )
  -                {
  -                    try
  -                    {
  -                        Constructor constructor = 
  -                          clazz.getConstructor( 
  -                            new Class[]{ 
  -                              LogTargetFactoryManager.class } );
  -                        return createLogTargetFactory( 
  -                          constructor, new Object[]{ manager } );
  -                    }
  -                    catch( NoSuchMethodException eeee )
  -                    {
  -                        try
  -                        {
  -                            Constructor constructor = 
  -                              clazz.getConstructor( 
  -                                new Class[]{ 
  -                                  File.class } );
  -                            return createLogTargetFactory( 
  -                              constructor, new Object[]{ basedir } );
  -                        }
  -                        catch( NoSuchMethodException eeeee )
  -                        {
  -                            try
  -                            {
  -                                Constructor constructor = 
  -                                  clazz.getConstructor( 
  -                                    new Class[0] );
  -                                return createLogTargetFactory( 
  -                                  constructor, new Object[0] );
  -                            }
  -                            catch( NoSuchMethodException eeeeee )
  -                            {
  -                                final String error = REZ.getString( 
  -                                  "target.error.bad-factory", 
  -                                  clazz.getName() );
  -                                throw new LoggingException( error );
  -                            }
  -                        }
  -                    }
  -                }
  +                args[i] = m_logger;
  +            }
  +            else if( LogTargetFactoryManager.class.isAssignableFrom( c ) )
  +            {
  +                args[i] = m_factories;
  +            }
  +            else if( LogTargetManager.class.isAssignableFrom( c ) )
  +            {
  +                args[i] = m_targets;
  +            }
  +            else if( FormatterFactory.class.isAssignableFrom( c ) )
  +            {
  +                args[i] = FORMATTER;
  +            }
  +            else
  +            {
  +                final String error = 
  +                  REZ.getString( 
  +                    "factory.error.unrecognized-parameter", 
  +                    c.getName(),
  +                    clazz.getName() );
  +                throw new LoggingException( error );
               }
           }
  +
  +        //
  +        // instantiate the factory
  +        //
  +
  +        return instantiateLogTargetFactory( constructor, args );
       }
   
      /**
  @@ -533,7 +519,7 @@
       * @return the factory instance
       * @exception LoggingException if an instantiation error occurs
       */
  -    private LogTargetFactory createLogTargetFactory( 
  +    private LogTargetFactory instantiateLogTargetFactory( 
         Constructor constructor, Object[] args ) 
         throws LoggingException
       {
  @@ -613,33 +599,5 @@
           final String priority = config.getAttribute( "priority", null );
           final String target = config.getAttribute( "target", null );
           return new CategoryDirective( name, priority, target );
  -    }
  -
  -    public final class StandardLogTargetFactoryManager 
  -       implements LogTargetFactoryManager
  -    {
  -        private Map m_map;
  -
  -       /**
  -        * Creation of a new log target factory manager.
  -        * @param map the initially empty set of log target factories
  -        */
  -        public StandardLogTargetFactoryManager( Map map )
  -        {
  -            m_map = map;
  -        }
  -
  -       /**
  -        * Retrieves a LogTargetFactory from a name. If
  -        * this LogTargetFactoryManager does not have the match a null
  -        * will be returned.
  -        *
  -        * @param key name of a LogTargetFactory.
  -        * @return the LogTargetFactory or null if not found.
  -        */
  -        public LogTargetFactory getLogTargetFactory( String key )
  -        {
  -             return (LogTargetFactory) m_map.get( key );
  -        }
       }
   }
  
  
  
  1.4       +3 -1      avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/DefaultLoggingManager.java
  
  Index: DefaultLoggingManager.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/DefaultLoggingManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultLoggingManager.java	26 Jan 2004 19:23:40 -0000	1.3
  +++ DefaultLoggingManager.java	27 Jan 2004 19:27:23 -0000	1.4
  @@ -64,6 +64,9 @@
       public static final Formatter FORMAT = 
          new StandardFormatter( DEFAULT_FORMAT );
   
  +    public static final Formatter CONSOLE = 
  +       new StandardFormatter( DEFAULT_FORMAT, false );
  +
       //---------------------------------------------------------------
       // immutable state
       //---------------------------------------------------------------
  @@ -141,7 +144,6 @@
   
           m_logger = getLoggerForCategory( channel );
           m_logger.debug( "logging system established" );
  -        m_logger.debug( "default logging target set to: " + target );
       }
   
       private LogTarget getDefaultLogTarget( CategoriesDirective categories )
  
  
  
  1.4       +5 -1      avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/Resources.properties,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Resources.properties	26 Jan 2004 19:23:40 -0000	1.3
  +++ Resources.properties	27 Jan 2004 19:27:23 -0000	1.4
  @@ -1,3 +1,5 @@
  +formatter.error.unknown-type=Unknown formatter type [{0}].
  +
   target.notice.add=adding log target [{0}]
   target.notice.fail=could not load a declared log target [{0}]
   
  @@ -19,9 +21,11 @@
   
   criteria.artifact.default.error=Unable to resolve cononical representation of the file [{0}].
   
  +factory.error.unrecognized-parameter=Unrecognized parameter class [{0}] declared by the log target factory [{1}] .
  +factory.error.no-constructor=No constructor declared in log target factory [{0}].
   factory.bad-criteria=Unrecognized criteria class [{0}].
   factory.target-factory.load.error=Cannot load log target factory [{0}].
  -factory.target-factory.unknown-element=Logging target factories configuration contains an unrecognized element [{0}]. [{1}]
  +factory.target-factory.unknown-element=Logging target 'factories' configuration contains an unrecognized child element [{0}]. [{1}]
   
   manager.invalid-default-target=Supplied default log target [{0}] is unknown.
   manager.error.internal=Internal error while getting logging channel for category [{0}].
  
  
  
  1.2       +7 -27     avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/StandardFormatter.java
  
  Index: StandardFormatter.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/StandardFormatter.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StandardFormatter.java	24 Jan 2004 23:25:33 -0000	1.1
  +++ StandardFormatter.java	27 Jan 2004 19:27:23 -0000	1.2
  @@ -87,26 +87,9 @@
       private static final String TYPE_CLASS_STR = "class";
       private static final String TYPE_CLASS_SHORT_STR = "short";
   
  -    /**
  -     * The constant defining the default stack depth when
  -     * none other is specified.
  -     *
  -     */
  -    public static final int DEFAULT_STACK_DEPTH = 8;
  -
  -    /**
  -     * The constant defining the default behaviour for printing
  -     * nested exceptions.
  -     *
  -     * @since 4.1.2
  -     */
  -    public static final boolean DEFAULT_PRINT_CASCADING = true;
  -
  -    //The depth to which stacktraces are printed out
  -    private final int m_stackDepth;
  +    public static final boolean DEFAULT_STACKTRACE_POLICY = true;
   
  -    //Determines if nested exceptions should be logged
  -    private final boolean m_printCascading;
  +    private final boolean m_stacktrace;
   
       /**
        * Construct the formatter with the specified pattern
  @@ -117,7 +100,7 @@
       */
       public StandardFormatter( final String pattern )
       {
  -        this( pattern, DEFAULT_STACK_DEPTH, DEFAULT_PRINT_CASCADING );
  +        this( pattern, DEFAULT_STACKTRACE_POLICY );
       }
   
       /**
  @@ -130,12 +113,10 @@
        *   false only prints out the outermost exception
        * @since 4.1.2
        */
  -    public StandardFormatter( final String pattern, final int stackDepth,
  -                            final boolean printCascading )
  +    public StandardFormatter( final String pattern, final boolean trace )
       {
           super( pattern );
  -        m_stackDepth = stackDepth;
  -        m_printCascading = printCascading;
  +        m_stacktrace = trace;
       }
   
       /**
  @@ -151,8 +132,7 @@
           {
               return "";
           }
  -        //return ExceptionUtil.printStackTrace( throwable, m_stackDepth, m_printCascading );
  -        return ExceptionHelper.packException( throwable, true );
  +        return ExceptionHelper.packException( throwable, m_stacktrace );
       }
   
       /**
  
  
  
  1.1                  avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/DefaultFormatterFactory.java
  
  Index: DefaultFormatterFactory.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.logging.logkit;
  
  import org.apache.avalon.framework.configuration.Configuration;
  
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  
  import org.apache.log.format.ExtendedPatternFormatter;
  import org.apache.log.format.Formatter;
  import org.apache.log.format.PatternFormatter;
  import org.apache.log.format.RawFormatter;
  import org.apache.log.format.SyslogFormatter;
  import org.apache.log.format.XMLFormatter;
  
  /**
   * Factory for Formatter-s.
   */
  public class DefaultFormatterFactory implements FormatterFactory
  {
      //--------------------------------------------------------------
      // static
      //--------------------------------------------------------------
  
      private static final Resources REZ =
        ResourceManager.getPackageResources( DefaultFormatterFactory.class );
      
      //--------------------------------------------------------------
      // implementation
      //--------------------------------------------------------------
  
     /**
      * Creation of a new formatter using a supplied configuration.
      * @param config the formatter configuration
      * @return the formatter instance
      * @exception IllegalArgumentException if the formatter type is unknown
      */
      public Formatter createFormatter( final Configuration config )
      {
          if( null == config ) return new StandardFormatter( DEFAULT_FORMAT );
          final String type = config.getAttribute( "type", "pattern" );
          final String format = config.getValue( DEFAULT_FORMAT );
          return createFormatter( type, format );
      }
  
     /**
      * Creation of a new formatter using a supplied configuration.
      * @param config the formatter configuration
      * @return the formatter instance
      * @exception IllegalArgumentException if the formatter type is unknown
      */
      public Formatter createFormatter( String type, String format )
      {
          if( "avalon".equals( type ) )
          {
              return new StandardFormatter( format, true );
          }
          else if( "console".equals( type ) )
          {
              return new StandardFormatter( format, false );
          }
          else if( "extended".equals( type ) )
          {
              //
              // Normally ExtendPatternFormatter would look for callers
              // of Logger.class.  But when Excalibur Logger provides a
              // facade, the user class/method is actually one-level deeper.
              // We therefore create the pattern-formatter with an
              // additional depth-offset of 1.
              //
  
              return new ExtendedPatternFormatter( format, 1 );
          }
          else if( "raw".equals( type ) )
          {
              return new RawFormatter();
          }
          else if( "xml".equals( type ) )
          {
              return new XMLFormatter();
          }
          else if( "syslog".equals( type ) )
          {
              return new SyslogFormatter();
          }
          else if( "pattern".equals( type ) )
          {
              return new PatternFormatter( format );
          }
          else
          {
              final String error = 
                REZ.getString( "formatter.error.unknown-type", type );
              throw new IllegalArgumentException( error );
          }
      }
  }
  
  
  
  1.1                  avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/DefaultLogTargetFactoryManager.java
  
  Index: DefaultLogTargetFactoryManager.java
  ===================================================================
  /* 
   * Copyright 2004 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.avalon.logging.logkit;
  
  import java.io.File;
  import java.io.IOException;
  import java.util.Map;
  import java.util.HashMap;
  
  import org.apache.avalon.logging.provider.LoggingManager;
  import org.apache.avalon.logging.provider.LoggingException;
  
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.logger.LogKitLogger;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.logging.data.CategoryDirective;
  import org.apache.avalon.logging.data.CategoriesDirective;
  
  import org.apache.log.Hierarchy;
  import org.apache.log.LogTarget;
  import org.apache.log.Priority;
  import org.apache.log.output.io.FileTarget;
  import org.apache.log.output.io.StreamTarget;
  
  /**
   * A <code>LoggerManager</code> interface declares operation supporting
   * the management of a logging hierarchy.
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   */
  class DefaultLogTargetFactoryManager implements LogTargetFactoryManager
  {
      //---------------------------------------------------------------
      // static
      //---------------------------------------------------------------
  
      private static final Resources REZ =
        ResourceManager.getPackageResources( DefaultLogTargetFactoryManager.class );
  
      //---------------------------------------------------------------
      // state
      //---------------------------------------------------------------
  
     /** 
      * Map for id to factory mapping.
      */
      private final Map m_map;
  
      //---------------------------------------------------------------
      // constructor
      //---------------------------------------------------------------
  
      /**
       * Creation of a new log target manager.
       * @param targets a map of log targets
       */
      public DefaultLogTargetFactoryManager( Map map ) throws Exception
      {
          if( null == map )
          {
              throw new NullPointerException( "map" );
          }
          m_map = map;
      }
  
      //---------------------------------------------------------------
      // LogTargetFactoryManager
      //---------------------------------------------------------------
      
     /**
      * Return a log target factory using a supplied factory key.  If the 
      * supplied key is unknown a null value is returned.
      * @param key the logging target factory key
      * @return the logging target factory
      */
      public LogTargetFactory getLogTargetFactory( final String key )
      {
          return (LogTargetFactory) m_map.get( key );
      }
  }
  
  
  
  1.3       +33 -79    avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/factory/DatagramTargetFactory.java
  
  Index: DatagramTargetFactory.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/factory/DatagramTargetFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DatagramTargetFactory.java	26 Jan 2004 17:36:16 -0000	1.2
  +++ DatagramTargetFactory.java	27 Jan 2004 19:27:23 -0000	1.3
  @@ -1,52 +1,19 @@
  -/*
  -
  - ============================================================================
  -                   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/>.
  -
  -*/
  +/* 
  + * Copyright 2004 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.avalon.logging.logkit.factory;
   
  @@ -69,6 +36,7 @@
   
   import org.apache.avalon.logging.logkit.LogTargetException;
   import org.apache.avalon.logging.logkit.LogTargetFactory;
  +import org.apache.avalon.logging.logkit.FormatterFactory;
   
   
   /**
  @@ -103,14 +71,25 @@
       private static final Resources REZ =
         ResourceManager.getPackageResources( DatagramTargetFactory.class );
   
  -    private static final String FORMAT =
  -      "%7.7{priority} %5.5{time}   "
  -      + "[%8.8{category}] (%{context}): %{message}\\n%{throwable}";
  +    //--------------------------------------------------------------
  +    // immutable state
  +    //--------------------------------------------------------------
  +
  +    private final FormatterFactory m_formatter;
   
       //--------------------------------------------------------------
       // constructor
       //--------------------------------------------------------------
   
  +    public DatagramTargetFactory( FormatterFactory formatter )
  +    {
  +        m_formatter = formatter;
  +    }
  +
  +    //--------------------------------------------------------------
  +    // LogTargetFactory
  +    //--------------------------------------------------------------
  +
       /**
        * Create a LogTarget based on a supplied configuration
        * @param conf the target coonfiguration
  @@ -149,8 +128,9 @@
               throw new LogTargetException( error, e );
           }
   
  +        Configuration formatConfig = conf.getChild( "format", false );
           final Formatter formatter = 
  -          getFormatter( conf.getChild( "format", false ) );
  +          m_formatter.createFormatter( formatConfig );
   
           try
           {
  @@ -169,32 +149,6 @@
                 REZ.getString( "datagram.error.missing-port" );
               throw new LogTargetException( error, e );
           }
  -    }
  -
  -    /**
  -     * Returns the Formatter
  -     *
  -     * @param conf Configuration for the formatter
  -     */
  -    protected Formatter getFormatter( final Configuration conf )
  -    {
  -        final String type = conf.getAttribute( "type", "pattern" );
  -        final String format = conf.getValue( FORMAT );
  -
  -        if( "extended".equals( type ) )
  -        {
  -            return new ExtendedPatternFormatter( format );
  -        }
  -        else if( "raw".equals( type ) )
  -        {
  -            return new RawFormatter();
  -        }
  -
  -        //
  -        // default formatter
  -        //
  -
  -        return new PatternFormatter( format );
       }
   }
   
  
  
  
  1.3       +26 -65    avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/factory/FileTargetFactory.java
  
  Index: FileTargetFactory.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/factory/FileTargetFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FileTargetFactory.java	26 Jan 2004 17:36:16 -0000	1.2
  +++ FileTargetFactory.java	27 Jan 2004 19:27:23 -0000	1.3
  @@ -1,52 +1,19 @@
  -/*
  -
  - ============================================================================
  -                   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/>.
  -
  -*/
  +/* 
  + * Copyright 2004 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.avalon.logging.logkit.factory;
   
  @@ -79,6 +46,7 @@
   import org.apache.log.output.io.rotate.UniqueFileStrategy;
   
   import org.apache.avalon.logging.logkit.DefaultLoggingManager;
  +import org.apache.avalon.logging.logkit.FormatterFactory;
   
   
   /**
  @@ -195,14 +163,16 @@
       //--------------------------------------------------------------
   
       private final File m_basedir;
  +    private final FormatterFactory m_formatter;
   
       //--------------------------------------------------------------
       // constructor
       //--------------------------------------------------------------
   
  -    public FileTargetFactory( File basedir )
  +    public FileTargetFactory( File basedir, FormatterFactory formatter )
       {
  -       m_basedir = basedir;
  +        m_basedir = basedir;
  +        m_formatter = formatter;
       }
   
       //--------------------------------------------------------------
  @@ -226,7 +196,7 @@
                 configuration.getChild( "rotation", false );
   
               final Configuration confFormat = 
  -              configuration.getChild( "format" );
  +              configuration.getChild( "format", false );
   
               final Configuration confAppend = 
                 configuration.getChild( "append" );
  @@ -236,7 +206,9 @@
               final LogTarget logtarget;
      
               final File file = resolveFile( filename );
  -            final Formatter formatter = getFormatter( confFormat );
  +          
  +            final Formatter formatter = 
  +              m_formatter.createFormatter( confFormat );
   
               if( null == confRotation )
               {
  @@ -438,17 +410,6 @@
                   return new UniqueFileStrategy( file, pattern, suffix );
               }
           }
  -    }
  -
  -    protected Formatter getFormatter( final Configuration conf )
  -    {
  -        if( null != conf )
  -        {
  -            final FormatterFactory formatterFactory = new FormatterFactory();
  -            return formatterFactory.createFormatter( conf );
  -        }
  -
  -        return DefaultLoggingManager.FORMAT;
       }
   }
   
  
  
  
  1.2       +2 -3      avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/factory/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/factory/Resources.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Resources.properties	26 Jan 2004 17:36:16 -0000	1.1
  +++ Resources.properties	27 Jan 2004 19:27:23 -0000	1.2
  @@ -10,12 +10,11 @@
   file.error.config=File target configuration error.
   file.error.internal=Internal error while attempting to construct file log target.
   
  -formatter.error.unknown-type=Unknown formatter type [{0}].
  -
   socket.error.missing-address=Missing 'address' attribute is supplied socket target configuration.
   socket.error.unknown-host=Socket target references an unknown host.
   socket.error.missing-host=Socket target does not contain required 'hostname' attribute.
   socket.error.missing-port=Socket target does not contain required 'port' attribute.
   socket.error.internal=Internal error while attempting to construct socket target.
   
  -
  +multicast.error.unknown-id=Multicast targetref references an unknown log target id [{0}].
  +multicast.error.missing-id=Multicast targetref 'id' attribute is missing.
  
  
  
  1.3       +17 -49    avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/factory/SocketTargetFactory.java
  
  Index: SocketTargetFactory.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/factory/SocketTargetFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SocketTargetFactory.java	26 Jan 2004 17:36:16 -0000	1.2
  +++ SocketTargetFactory.java	27 Jan 2004 19:27:23 -0000	1.3
  @@ -1,52 +1,20 @@
  -/*
  -
  - ============================================================================
  -                   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/>.
  +/* 
  + * Copyright 2004 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.avalon.logging.logkit.factory;
   
   import java.io.IOException;
  @@ -96,7 +64,7 @@
         ResourceManager.getPackageResources( SocketTargetFactory.class );
   
       //--------------------------------------------------------------
  -    // TargetFactory
  +    // LogTargetFactory
       //--------------------------------------------------------------
   
       /**
  
  
  
  1.2       +44 -65    avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/factory/StreamTargetFactory.java
  
  Index: StreamTargetFactory.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/factory/StreamTargetFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StreamTargetFactory.java	24 Jan 2004 23:25:33 -0000	1.1
  +++ StreamTargetFactory.java	27 Jan 2004 19:27:23 -0000	1.2
  @@ -1,52 +1,19 @@
  -/*
  -
  - ============================================================================
  -                   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/>.
  -
  -*/
  +/* 
  + * Copyright 2004 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.avalon.logging.logkit.factory;
   
  @@ -56,6 +23,7 @@
   import org.apache.avalon.framework.configuration.ConfigurationException;
   
   import org.apache.avalon.logging.logkit.LogTargetFactory;
  +import org.apache.avalon.logging.logkit.FormatterFactory;
   
   import org.apache.log.LogTarget;
   import org.apache.log.format.Formatter;
  @@ -68,7 +36,7 @@
    * configuration syntax:
    * <pre>
    * &lt;stream id="foo"&gt;
  - *  &lt;stream&gt;<i>stream-context-name</i>&lt;/stream&gt;
  + *  &lt;name&gt;<i>stream-context-name</i>&lt;/name&gt;
    *  &lt;format type="<i>raw|pattern|extended</i>"&gt;<i>pattern to be used if needed</i>&lt;/format&gt;
    * &lt;/stream&gt;
    * </pre>
  @@ -86,6 +54,25 @@
    */
   public class StreamTargetFactory implements LogTargetFactory
   {
  +    //--------------------------------------------------------------
  +    // immutable state
  +    //--------------------------------------------------------------
  +
  +    private final FormatterFactory m_formatter;
  +
  +    //--------------------------------------------------------------
  +    // constructor
  +    //--------------------------------------------------------------
  +
  +    public StreamTargetFactory( FormatterFactory formatter )
  +    {
  +        m_formatter = formatter;
  +    }
  +
  +    //--------------------------------------------------------------
  +    // LogTargetFactory
  +    //--------------------------------------------------------------
  +
       /**
        * Create a LogTarget based on a Configuration
        */
  @@ -93,7 +80,8 @@
       {
           OutputStream stream;
   
  -        final Configuration streamConfig = configuration.getChild( "stream", false );
  +        final Configuration streamConfig = 
  +          configuration.getChild( "name", false );
           if( null == streamConfig )
           {
               stream = System.out;
  @@ -111,20 +99,11 @@
               }
           }
   
  -        final Configuration formatterConf = configuration.getChild( "format" );
  -        final Formatter formatter = getFormatter( formatterConf );
  -        return new StreamTarget( stream, formatter );
  -    }
  +        Configuration formatConfig = configuration.getChild( "format", false );
  +        final Formatter formatter = 
  +          m_formatter.createFormatter( formatConfig );
   
  -    protected Formatter getFormatter( final Configuration conf )
  -    {
  -        Formatter formatter = null;
  -        if( null != conf )
  -        {
  -            final FormatterFactory formatterFactory = new FormatterFactory();
  -            formatter = formatterFactory.createFormatter( conf );
  -        }
  -        return formatter;
  +        return new StreamTarget( stream, formatter );
       }
   }
   
  
  
  
  1.1                  avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/factory/MulticastTargetFactory.java
  
  Index: MulticastTargetFactory.java
  ===================================================================
  /* 
   * Copyright 2004 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.avalon.logging.logkit.factory;
  
  import java.io.IOException;
  import java.net.InetAddress;
  import java.net.UnknownHostException;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  
  import org.apache.log.LogTarget;
  import org.apache.log.LogEvent;
  import org.apache.log.format.ExtendedPatternFormatter;
  import org.apache.log.format.Formatter;
  import org.apache.log.format.PatternFormatter;
  import org.apache.log.format.RawFormatter;
  import org.apache.log.output.net.DatagramOutputTarget;
  
  import org.apache.avalon.logging.logkit.LogTargetException;
  import org.apache.avalon.logging.logkit.LogTargetFactory;
  import org.apache.avalon.logging.logkit.LogTargetManager;
  
  
  /**
   *
   */
  public class MulticastTargetFactory implements LogTargetFactory
  {
      //--------------------------------------------------------------
      // static
      //--------------------------------------------------------------
  
      private static final Resources REZ =
        ResourceManager.getPackageResources( MulticastTargetFactory.class );
  
      //--------------------------------------------------------------
      // immutable state
      //--------------------------------------------------------------
  
      private final LogTargetManager m_manager;
  
      //--------------------------------------------------------------
      // constructor
      //--------------------------------------------------------------
  
      public MulticastTargetFactory( LogTargetManager manager )
      {
          m_manager = manager;
      }
  
      //--------------------------------------------------------------
      // LogTargetFactory
      //--------------------------------------------------------------
  
      /**
       * Create a LogTarget based on a supplied configuration
       * @param conf the target coonfiguration
       * @return the malticast target
       * @exception LogTargetException if a target creation error occurs
       */
      public LogTarget createTarget( final Configuration config )
          throws LogTargetException
      {
          Configuration[] references = config.getChildren( "targetref" );
          LogTarget[] targets = new LogTarget[ references.length ];
          for( int i=0; i<references.length; i++ )
          {
              Configuration ref = references[i];
              final String id = ref.getAttribute( "id", null );
              if( null == id ) 
              {
                  final String error = 
                    REZ.getString( "multicast.error.missing-id" );
                  throw new LogTargetException( error );
              }
              LogTarget target = m_manager.getLogTarget( id );
              if( null == target ) 
              {
                  final String error = 
                    REZ.getString( "multicast.error.unknown-id", id );
                  throw new LogTargetException( error );
              }
              targets[i] = target;
          }
          return new MulticastLogTarget( targets );
      }
  
      public class MulticastLogTarget implements LogTarget
      {
          private final LogTarget[] m_targets;
  
          public MulticastLogTarget( LogTarget[] targets )
          {
              m_targets = targets;
          }
  
          public void processEvent( LogEvent event )
          {
              for( int i=0; i<m_targets.length; i++ )
              {
                  m_targets[i].processEvent( event );
              }
          }
      }
  }
  
  
  
  
  1.3       +18 -4     avalon/merlin/logging/logkit/test/conf/logging.xml
  
  Index: logging.xml
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/logging/logkit/test/conf/logging.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- logging.xml	26 Jan 2004 17:36:16 -0000	1.2
  +++ logging.xml	27 Jan 2004 19:27:23 -0000	1.3
  @@ -1,6 +1,6 @@
   <?xml version="1.0" encoding="ISO-8859-1"?>
   
  -<logging>
  +<logging debug="false">
   
     <!--
     Declaration of the log target factories.
  @@ -9,6 +9,10 @@
     <factories>
       <factory type="file" 
         class="org.apache.avalon.logging.logkit.factory.FileTargetFactory"/>
  +    <factory type="stream" 
  +      class="org.apache.avalon.logging.logkit.factory.StreamTargetFactory"/>
  +    <factory type="multicast" 
  +      class="org.apache.avalon.logging.logkit.factory.MulticastTargetFactory"/>
     </factories>
   
     <!--
  @@ -16,6 +20,10 @@
     -->
   
     <targets>
  +    <stream id="standard">
  +       <name>System.out</name>
  +       <format type="console"/>
  +    </stream>
       <file id="simple">
         <filename>simple.log</filename>
         <append>true</append>
  @@ -23,16 +31,22 @@
           <size>100k</size>
         </rotation>
       </file>
  +    <multicast id="multicast">
  +      <targetref id="standard"/>
  +      <targetref id="simple"/>
  +    </multicast>
     </targets>
   
     <!--
     Declaration of the initial logging categories.
     -->
   
  -  <categories priority="info" target="simple">
  +  <categories priority="info" target="multicast">
       <categories name="kernel">
  -      <category name="logger" priority="debug"/>
  -      <category name="roger-ramjet" priority="error"/>
  +      <categories name="logger" priority="warn">
  +        <category name="test" priority="fatal_error"/>
  +      </categories>
  +      <category name="roger-ramjet" priority="debug" target="simple"/>
       </categories>
     </categories>
   
  
  
  
  1.4       +71 -33    avalon/merlin/logging/logkit/test/src/test/org/apache/avalon/logging/logkit/test/DefaultLoggingManagerTestCase.java
  
  Index: DefaultLoggingManagerTestCase.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/logging/logkit/test/src/test/org/apache/avalon/logging/logkit/test/DefaultLoggingManagerTestCase.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultLoggingManagerTestCase.java	26 Jan 2004 17:36:16 -0000	1.3
  +++ DefaultLoggingManagerTestCase.java	27 Jan 2004 19:27:23 -0000	1.4
  @@ -23,6 +23,11 @@
   
   import junit.framework.TestCase;
   
  +import org.apache.avalon.framework.logger.Logger;
  +
  +import org.apache.avalon.logging.provider.LoggingManager;
  +import org.apache.avalon.logging.provider.LoggingException;
  +
   import org.apache.avalon.repository.Artifact;
   import org.apache.avalon.repository.provider.Factory;
   import org.apache.avalon.repository.provider.InitialContext;
  @@ -42,7 +47,16 @@
    */
   public class DefaultLoggingManagerTestCase extends TestCase
   {
  +    //-------------------------------------------------------------------
  +    // state
  +    //-------------------------------------------------------------------
  +
       InitialContext m_context;
  +    LoggingManager m_manager;
  +
  +    //-------------------------------------------------------------------
  +    // constructor
  +    //-------------------------------------------------------------------
   
       /**
        * Constructor for DefaultInitialContextTest.
  @@ -53,45 +67,69 @@
           super( name );
       }
   
  +    //-------------------------------------------------------------------
  +    // utilities
  +    //-------------------------------------------------------------------
  +
       protected void setUp() throws Exception
       {
  -        m_context = 
  -          new DefaultInitialContext( 
  -            getMavenRepositoryDirectory() );
  +        m_manager = LoggingManagerHelper.setUpLoggingManager( "logging.xml" );
  +    }
  +
  +    public void testKernelLogging() throws Exception
  +    {
  +        Logger logger = m_manager.getLoggerForCategory( "kernel.logger" );
  +
  +        logger.debug( "this is a debug message from the kernel" );
  +        logger.info( "this is a info message from the kernel" );
  +        logger.warn( "this is a warning message from the kernel" );
  +        logger.error( 
  +          "this is an error message from the kernel", 
  +          new LoggingException( 
  +            "woops", 
  +            new LoggingException( 
  +              "my fault", 
  +              new LoggingException( "bad attitude" ) ) ) );
  +        logger.fatalError( "this is a fatal message from the kernel" );
       }
   
  -    public void testLoggingFactoryBootstrap() throws Exception
  +    public void testKernelTestLogging() throws Exception
       {
  -        //
  -        // FIX ME - remove hard reference (get from a property)
  -        //
  -
  -        Artifact artifact = Artifact.createArtifact( 
  -          "avalon-logging", "avalon-logkit-impl", "1.0-SNAPSHOT" );
  -
  -        Builder builder = m_context.newBuilder( artifact );
  -        Factory factory = builder.getFactory();
  -        Map criteria = factory.createDefaultCriteria();
  -
  -        //
  -        // customize the criteria
  -        //
  -
  -        File basedir = getBaseDir();
  -        File file = new File( basedir, "conf/logging.xml" );
  -        File target = new File( basedir, "target" );
  -
  -        criteria.put( "avalon.logging.bootstrap", "debug" );
  -        criteria.put( "avalon.logging.configuration", file );
  -        criteria.put( "avalon.logging.basedir", target );
  -
  -        //
  -        // create the logging manager
  -        //
  +        Logger logger = m_manager.getLoggerForCategory( "kernel.logger.test" );
   
  -        Object manager = factory.create( criteria );
  -        System.out.println( "logging manager: " + manager );
  +        logger.debug( "this is a debug message from test" );
  +        logger.info( "this is a info message from test" );
  +        logger.warn( "this is a warning message from test" );
  +        logger.error( 
  +          "this is an error message from test", 
  +          new LoggingException( 
  +            "woops", 
  +            new LoggingException( 
  +              "my fault", 
  +              new LoggingException( "bad attitude" ) ) ) );
  +        logger.fatalError( "this is a fatal message from test" );
       }
  +
  +    public void testRogerRamjetLogging() throws Exception
  +    {
  +        Logger logger = m_manager.getLoggerForCategory( "kernel.roger-ramjet" );
  +
  +        logger.debug( "this is a debug message from roger ramjet" );
  +        logger.info( "this is a info message from roger ramjet" );
  +        logger.warn( "this is a warning message from roger ramjet" );
  +        logger.error( 
  +          "this is an error message from roger ramjet", 
  +          new LoggingException( 
  +            "woops", 
  +            new LoggingException( 
  +              "my fault", 
  +              new LoggingException( "bad attitude" ) ) ) );
  +        logger.fatalError( "this is a fatal message from roger ramjet" );
  +    }
  +
  +    //-------------------------------------------------------------------
  +    // utilities
  +    //-------------------------------------------------------------------
   
       private static File getMavenRepositoryDirectory()
       {
  
  
  

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


Mime
View raw message