You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by ni...@apache.org on 2004/02/29 23:32:42 UTC

cvs commit: avalon/logging/test/src/test/org/apache/avalon/logging/log4j/test AlternateLoggingManagerTestCase.java DefaultLoggingManagerTestCase.java

niclas      2004/02/29 14:32:42

  Modified:    logging/log4j/src/java/org/apache/avalon/logging/log4j
                        Log4JLoggingFactory.java
               logging/logkit/impl/src/java/org/apache/avalon/logging/logkit
                        DefaultLogTargetFactoryBuilder.java
                        DefaultLoggingFactory.java
               logging/site/xdocs/impl/log4j index.xml
               logging/site/xdocs/spec index.xml
               logging/spi project.xml
               logging/spi/src/java/org/apache/avalon/logging/provider
                        LoggingCriteria.java
               logging/test project.xml
               logging/test/src/test/org/apache/avalon/logging/log4j/test
                        AlternateLoggingManagerTestCase.java
                        DefaultLoggingManagerTestCase.java
  Added:       logging/logkit/impl/src/java/org/apache/avalon/logging/logkit
                        default-logging.xml
               logging/spi/src/java/org/apache/avalon/logging/provider
                        ConfigurationParameter.java ConsoleLogger.java
                        LoggerParameter.java LoggingCriteria.properties
  Removed:     logging/log4j/src/java/org/apache/avalon/logging/log4j
                        ConfigurationParameter.java
                        DefaultLoggingCriteria.java LoggerParameter.java
               logging/logkit/impl/src/java/org/apache/avalon/logging/logkit
                        ConfigurationParameter.java
                        DefaultLoggingCriteria.java
                        DefaultLoggingCriteria.properties
                        LoggerParameter.java
               logging/test/conf/log4j logging.xml logging2.xml
  Log:
  Small restructure to support the repository driven log system loading.
  
  Revision  Changes    Path
  1.7       +54 -62    avalon/logging/log4j/src/java/org/apache/avalon/logging/log4j/Log4JLoggingFactory.java
  
  Index: Log4JLoggingFactory.java
  ===================================================================
  RCS file: /home/cvs/avalon/logging/log4j/src/java/org/apache/avalon/logging/log4j/Log4JLoggingFactory.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Log4JLoggingFactory.java	29 Feb 2004 14:10:25 -0000	1.6
  +++ Log4JLoggingFactory.java	29 Feb 2004 22:32:41 -0000	1.7
  @@ -55,7 +55,7 @@
       implements LoggingFactory
   {
       private static final Resources REZ =
  -      ResourceManager.getPackageResources( DefaultLoggingCriteria.class );
  +      ResourceManager.getPackageResources( Log4JLoggingFactory.class );
       
       private final ClassLoader    m_Classloader;
       private final InitialContext m_Context;
  @@ -83,7 +83,7 @@
       */
       public LoggingCriteria createDefaultLoggingCriteria()
       {
  -        return new DefaultLoggingCriteria( m_Context );
  +        return new LoggingCriteria( m_Context );
       }
   
      /**
  @@ -141,97 +141,89 @@
           {
               throw new NullPointerException( "criteriaMap" );
           }
  -
  -        final LoggingCriteria criteria = getLoggingCriteria( criteriaMap );
  +        LoggingCriteria criteria = getLoggingCriteria( criteriaMap );
           m_BaseDirectory = criteria.getBaseDirectory();
  -
  -        final Configuration config = criteria.getConfiguration();
  -        Configuration srcConf = config.getChild( "src", false );
  -        if( srcConf != null )
  -        {
  -            Configuration updateConf = config.getChild( "update" );
  -            String src = srcConf.getValue();
  -            src = resolveSource( src );
  -            System.out.println( src );
  -            long updateInterval = updateConf.getValueAsLong( 0 );
  -            if( updateInterval > 0 )
  -            {
  -                configureWithWatch( src, updateInterval );
  -            }
  -            else
  -            {
  -                configureWithOutWatch( src );
  -            }
  +        
  +        String cwd = System.getProperty( "user.dir" );
  +        try
  +        {
  +            System.setProperty( "user.dir", m_BaseDirectory.getAbsolutePath() );
  +            URL conf = criteria.getLoggingConfiguration();
  +            long updateInterval = criteria.getUpdateInterval();
  +            configure( conf, updateInterval );
  +            return new LoggingManagerImpl();
  +        } finally
  +        {
  +            System.setProperty( "user.dir", cwd );
           }
  -        else
  +    }
  +
  +    private void configure( URL url, long interval )
  +    {
  +        String src = url.toExternalForm();
  +        if( src.startsWith( "file:" ) )
           {
  -            Configuration log4jNode = config.getChild( "configuration" );
  -            Element node = ConfigurationUtil.toElement( log4jNode );
  -            DOMConfigurator.configure( node );
  +            src = src.substring( 5 );
  +            while( src.startsWith( "/" ) )
  +                src = src.substring( 1 );
  +            configureFile( src, interval );
           }
  -        return new LoggingManagerImpl();
  +        configureURL( url );
       }
       
  -    private void configureWithWatch( String src, long interval )
  +    private void configureFile( String src, long interval )
       {
  -        if( src.endsWith( ".xml" ) )
  +        if( interval > 0 )
           {
  -            DOMConfigurator.configureAndWatch( src, interval );
  +            if( src.endsWith( ".xml" ) )
  +            {
  +                DOMConfigurator.configureAndWatch( src, interval );
  +            }
  +            else
  +            {
  +                PropertyConfigurator.configureAndWatch( src, interval );
  +            }
           }
           else
           {
  -            PropertyConfigurator.configureAndWatch( src, interval );
  +            if( src.endsWith( ".xml" ) )
  +            {
  +                DOMConfigurator.configureAndWatch( src );
  +            }
  +            else
  +            {
  +                PropertyConfigurator.configureAndWatch( src );
  +            }
           }
       }
       
  -    private void configureWithOutWatch( String src )
  +    private void configureURL( URL url )
       {
  +        String src = url.toExternalForm();
  +        
           if( src.endsWith( ".xml" ) )
           {
  -            DOMConfigurator.configure( src );
  +            DOMConfigurator.configure( url );
           }
           else
           {
  -            PropertyConfigurator.configure( src );
  +            PropertyConfigurator.configure( url );
           }
       }
   
  -    private String resolveSource( String src )
  -    {
  -        try
  -        {
  -            URL url = new URL( src );
  -            if( url.getProtocol().equals( "file" ) )
  -                return resolveToBaseDir( src );
  -            return src;
  -        } catch( MalformedURLException e )
  -        {
  -            return resolveToBaseDir( src );
  -        }
  -    }
  -    
  -    private String resolveToBaseDir( String src )
  +    private LoggingCriteria getLoggingCriteria( Map criteriaMap )
       {
  -        if( src.startsWith( "/" ) )
  -            return src;
  -        File f = new File( m_BaseDirectory, src );
  -        return f.getAbsolutePath();
  -    }
  -    
  -    private LoggingCriteria getLoggingCriteria( Map map )
  -    {
  -        if( map instanceof LoggingCriteria )
  +        if( criteriaMap instanceof LoggingCriteria )
           {
  -            return (LoggingCriteria) map;
  +            return (LoggingCriteria) criteriaMap;
           }
           else
           {
               final String error = 
                 REZ.getString( 
                   "factory.bad-criteria", 
  -                map.getClass().getName() );
  +                criteriaMap.getClass().getName() );
               throw new IllegalArgumentException( error );
           }
       }
  -
   }
  
  
  
  1.2       +1 -7      avalon/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/DefaultLogTargetFactoryBuilder.java
  
  Index: DefaultLogTargetFactoryBuilder.java
  ===================================================================
  RCS file: /home/cvs/avalon/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/DefaultLogTargetFactoryBuilder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultLogTargetFactoryBuilder.java	4 Feb 2004 20:49:06 -0000	1.1
  +++ DefaultLogTargetFactoryBuilder.java	29 Feb 2004 22:32:41 -0000	1.2
  @@ -27,11 +27,6 @@
   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;
  -import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
   
   import org.apache.avalon.logging.provider.LoggingCriteria;
   import org.apache.avalon.logging.provider.LoggingException;
  @@ -48,7 +43,6 @@
   
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
  -import org.apache.excalibur.configuration.ConfigurationUtil;
   
   import org.apache.log.LogTarget;
   import org.apache.log.output.io.StreamTarget;
  @@ -218,4 +212,4 @@
               throw new LoggingException( error, e );
           }
       }
  -}
  \ No newline at end of file
  +}
  
  
  
  1.5       +23 -4     avalon/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/DefaultLoggingFactory.java
  
  Index: DefaultLoggingFactory.java
  ===================================================================
  RCS file: /home/cvs/avalon/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/DefaultLoggingFactory.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultLoggingFactory.java	27 Feb 2004 22:39:35 -0000	1.4
  +++ DefaultLoggingFactory.java	29 Feb 2004 22:32:41 -0000	1.5
  @@ -18,6 +18,8 @@
   package org.apache.avalon.logging.logkit;
   
   import java.io.File;
  +import java.io.InputStream;
  +import java.net.URL;
   import java.util.Map;
   import java.util.HashMap;
   import java.util.ArrayList;
  @@ -27,12 +29,12 @@
   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;
   import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
   
  +import org.apache.avalon.logging.provider.ConsoleLogger;
   import org.apache.avalon.logging.provider.LoggingCriteria;
   import org.apache.avalon.logging.provider.LoggingFactory;
   import org.apache.avalon.logging.provider.LoggingException;
  @@ -114,7 +116,7 @@
       */
       public LoggingCriteria createDefaultLoggingCriteria()
       {
  -        return new DefaultLoggingCriteria( m_context );
  +        return new LoggingCriteria( m_context );
       }
   
      /**
  @@ -184,7 +186,24 @@
           // and bootstrap logger and setup the primary managers
           //
   
  -        final Configuration config = criteria.getConfiguration();
  +        DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
  +        
  +        URL configURL = criteria.getLoggingConfiguration();
  +        Configuration config;
  +        if( configURL != null )
  +        {
  +            config = builder.build( configURL.toExternalForm() );
  +        }
  +        else
  +        {
  +            InputStream defaultConf = 
  +              getClass().getClassLoader().
  +                getResourceAsStream( 
  +                  "org/apache/avalon/logging/logkit/default-logging.xml" 
  +                );
  +            config = builder.build( defaultConf );
  +        }
  +        
           m_logger = setUpBootstrapLogger( criteria, config );
           m_basedir = criteria.getBaseDirectory();
   
  @@ -463,4 +482,4 @@
           final String target = config.getAttribute( "target", null );
           return new CategoryDirective( name, priority, target );
       }
  -}
  \ No newline at end of file
  +}
  
  
  
  1.1                  avalon/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/default-logging.xml
  
  Index: default-logging.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  <logging>
  
    <categories priority="info">
      <categories name="kernel">
          <category name="logger" priority="warn"/>
      </categories>
    </categories>
    <logger name="kernel.logger"/>
    
  </logging>
  
  
  
  
  1.5       +21 -85    avalon/logging/site/xdocs/impl/log4j/index.xml
  
  Index: index.xml
  ===================================================================
  RCS file: /home/cvs/avalon/logging/site/xdocs/impl/log4j/index.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- index.xml	29 Feb 2004 14:03:22 -0000	1.4
  +++ index.xml	29 Feb 2004 22:32:41 -0000	1.5
  @@ -32,95 +32,31 @@
             method call (non reflected) for the log output methods.
           </p>
           <p>
  -          Instead of mixing in the Log4J configuration into the rest
  -          of Avalon configuration files, they remain external and
  -          are instead referenced. Both XML and Properties files are
  -          supported, and by giving an optional <strong>update</strong>
  -          element, the configureAndWatch() method will be used.
  +          The Log4J subsystem is loaded external to the avalon/logging package,
  +          and how this is done for the container you use, can be found in each
  +          containers documentation.
           </p>
           <p>
  -          <strong>NOTE! </strong> &quot;Base Directory&quot;
  -          (property &quot;avalon.logging.basedir&quot;) is NOT SUPPORTED
  -          inside any Log4J configuration files, and
  -          all relative filenames inside the Log4J configuration will
  -          relative to <strong>user.dir</strong> (current directory).
  +          The Artifact URL is; <strong><code>artifact://avalon-logging/avalon-log4j-impl#VERSION</code></strong>
  +        </p>
  +        <p>
  +          where VERSION is the version requested version of the avalon/logging Log4J
  +          <strong>adapter</strong> and NOT the Log4J version.
  +        </p>
  +        <p>
  +          It is also likely that the container will need to load the Log4J artifact
  +          as well. Again, this is container specific, but the Log4J artifact URL
  +          is; <strong><code>artifact://log4j/log4j#VERSION</code></strong>
  +        </p>
  +        <p>
  +          where VERSION in this case identifies the Log4J version to be used.
           </p>
         </subsection>
  -      <subsection name="XML Specification">
  -        <table>
  -          <tr><th>Nested Element</th><th>Description</th></tr>
  -          <tr>
  -            <td>src</td>
  -            <td>
  -              The filename or URL of the Log4J configuration file. This
  -              file can either be an XML or a Properties configuration file,
  -              but MUST end with <strong>&quot;.xml&quot;</strong> if it is
  -              the former. A relative filename will resolve relative to 
  -              <strong>Base Directory</strong> (property &quot;avalon.logging.basedir&quot;).
  -            </td>
  -          </tr>
  -          <tr>
  -            <td>update</td>
  -            <td>
  -              The Update Interval. For files, unlike URLs, it is 
  -              possible for Log4J to check for the file being modified
  -              externally, and if so reload the configuration. If this
  -              element is specified and has a positive value, this
  -              FileWatch feature of Log4J will be used. The time is
  -              specified in milliseconds.
  -            </td>
  -          </tr>
  -          <tr>
  -            <td>configuration</td>
  -            <td>
  -              If you don't specify a &lt;src&gt; element, you MUST specifiy the
  -              complete Log4J configuration in this element. That mean that this
  -              &lt;configuration&gt; element corresponds to the root node of a
  -              Log4J configuration. See below for an example.
  -            </td>
  -          </tr>
  -        </table>
  -      </subsection>
  -      <subsection name="Example - External Reference">
  -<source><![CDATA[
  -    <logging>
  -      <src>conf/log4j.xml</src>
  -      <!-- Check for Update once every minute. -->
  -      <update>60000</update>
  -    </logging>
  -]]></source>
  -      </subsection>
  -      <subsection name="Example - Embedded Configuration">
  -<source><![CDATA[
  -<logging>
  -  <configuration>
  -    <appender name="FILE" class="org.apache.log4j.FileAppender">
  -      <param name="BufferedIO" value="true" />
  -      <param name="File" value="application.log" />
  -
  -      <layout class="org.apache.log4j.PatternLayout">
  -        <param name="ConversionPattern" value="%t %-5p %c{2} - %m%n"/>
  -      </layout>
  -    </appender>
  -
  -    <appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
  -      <layout class="org.apache.log4j.PatternLayout">
  -        <param name="ConversionPattern" value="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
  -      </layout>
  -    </appender>
  -
  -    <category name="org.apache.avalon.merlin.activation">
  -      <priority value="debug"/>
  -      <appender-ref ref="STDOUT"/>
  -    </category>
  -
  -    <root>
  -      <priority value="error"/>
  -      <appender-ref ref="FILE"/>
  -    </root>
  -  </configuration>
  -</logging>
  -]]></source>
  +      <subsection name="Properties">
  +       <p>
  +         See the <a href="../../spec/index.html">Specification</a> for full 
  +         description of the standard properties.
  +       </p>
         </subsection>
       </section>
     </body>
  
  
  
  1.2       +10 -0     avalon/logging/site/xdocs/spec/index.xml
  
  Index: index.xml
  ===================================================================
  RCS file: /home/cvs/avalon/logging/site/xdocs/spec/index.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- index.xml	21 Feb 2004 10:21:46 -0000	1.1
  +++ index.xml	29 Feb 2004 22:32:41 -0000	1.2
  @@ -86,6 +86,16 @@
               <td>false</td>
               <td>Debug flag used to override all logging channels to debug priority.</td>
             </tr>
  +          <tr>
  +            <td>avalon.logging.update</td>
  +            <td>0</td>
  +            <td>
  +              If the value is larger than zero, the <strong>update</strong> is
  +              how many millisecond between re-configuring the logging system. Not
  +              all logging system will support this property, in which case it is
  +              completely ignored.
  +            </td>
  +          </tr>
           </table>
         </subsection>
       </section>
  
  
  
  1.2       +23 -0     avalon/logging/spi/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/avalon/logging/spi/project.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- project.xml	27 Feb 2004 22:39:35 -0000	1.1
  +++ project.xml	29 Feb 2004 22:32:41 -0000	1.2
  @@ -30,6 +30,11 @@
       </dependency>
       <dependency>
         <groupId>avalon-repository</groupId>
  +      <artifactId>avalon-repository-main</artifactId>
  +      <version>2.0-SNAPSHOT</version>
  +    </dependency>
  +    <dependency>
  +      <groupId>avalon-repository</groupId>
         <artifactId>avalon-repository-spi</artifactId>
         <version>2.0-SNAPSHOT</version>
       </dependency>
  @@ -37,6 +42,24 @@
         <groupId>avalon-logging</groupId>
         <artifactId>avalon-logging-api</artifactId>
         <version>1.0-SNAPSHOT</version>
  +    </dependency>
  +    <dependency>
  +      <groupId>avalon-util</groupId>
  +      <artifactId>avalon-util-criteria</artifactId>
  +      <version>1.1-SNAPSHOT</version>
  +    </dependency>
  +    <dependency>
  +      <id>excalibur-i18n</id>
  +      <version>1.1</version>
  +    </dependency>
  +    <dependency>
  +      <id>excalibur-configuration</id>
  +      <version>1.1</version>
  +    </dependency>
  +    <dependency>
  +      <groupId>avalon-util</groupId>
  +      <artifactId>avalon-util-defaults</artifactId>
  +      <version>1.2-SNAPSHOT</version>
       </dependency>
     </dependencies>
   
  
  
  
  1.2       +209 -45   avalon/logging/spi/src/java/org/apache/avalon/logging/provider/LoggingCriteria.java
  
  Index: LoggingCriteria.java
  ===================================================================
  RCS file: /home/cvs/avalon/logging/spi/src/java/org/apache/avalon/logging/provider/LoggingCriteria.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LoggingCriteria.java	27 Feb 2004 22:39:35 -0000	1.1
  +++ LoggingCriteria.java	29 Feb 2004 22:32:41 -0000	1.2
  @@ -18,13 +18,28 @@
   package org.apache.avalon.logging.provider;
   
   import java.io.File;
  +import java.net.URL;
   import java.io.IOException;
  -import java.util.Map;
  +import java.util.Properties;
   
  -import org.apache.avalon.repository.Artifact;
  -import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.logger.Logger;
   
  +import org.apache.avalon.repository.Artifact;
  +import org.apache.avalon.repository.ArtifactHandler;
  +import org.apache.avalon.repository.provider.InitialContext;
  +import org.apache.avalon.repository.main.DefaultBuilder;
  +
  +import org.apache.avalon.util.criteria.CriteriaException;
  +import org.apache.avalon.util.criteria.Criteria;
  +import org.apache.avalon.util.criteria.Parameter;
  +import org.apache.avalon.util.defaults.Defaults;
  +import org.apache.avalon.util.defaults.DefaultsBuilder;
  +
  +import org.apache.avalon.excalibur.i18n.ResourceManager;
  +import org.apache.avalon.excalibur.i18n.Resources;
  +
  +
  +
   /**
    * DefaultLoggingCriteria is a class holding the values supplied by a user 
    * for application to a LoggingManager factory.
  @@ -32,7 +47,7 @@
    * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
    * @version $Revision$
    */
  -public interface LoggingCriteria extends Map
  +public class LoggingCriteria extends Criteria 
   {
       //--------------------------------------------------------------
       // criteria keys
  @@ -41,13 +56,13 @@
      /**
       * The logging configuration key.
       */
  -    String LOGGING_CONFIGURATION_KEY = 
  +    public static String LOGGING_CONFIGURATION_KEY = 
         "avalon.logging.configuration";
   
      /**
       * The logging system bootstrap logger key.
       */
  -    String LOGGING_BOOTSTRAP_KEY = 
  +    public static String LOGGING_BOOTSTRAP_KEY = 
         "avalon.logging.bootstrap";
   
      /**
  @@ -56,78 +71,227 @@
       * logging file should be created in the directory 
       * assigned to this key.
       */
  -    String LOGGING_BASEDIR_KEY = 
  +    public static String LOGGING_BASEDIR_KEY = 
         "avalon.logging.basedir";
   
      /**
  +    * Update Interval.
  +    * Logging subsystems that supports changes on-the-fly, will
  +    * be passed this argument.
  +    */
  +    public static String LOGGING_INTERVAL_KEY = 
  +      "avalon.logging.update";
  +
  +   /**
       * Debug mode.
       */
  -    String LOGGING_DEBUG_KEY = 
  +    public static String LOGGING_DEBUG_KEY = 
         "avalon.logging.debug";
   
       //--------------------------------------------------------------
  -    // operations
  +    // static
  +    //--------------------------------------------------------------
  +
  +    private static final String[] KEYS = 
  +      new String[]{
  +        LOGGING_CONFIGURATION_KEY,
  +        LOGGING_BASEDIR_KEY,
  +        LOGGING_DEBUG_KEY,
  +        LOGGING_BOOTSTRAP_KEY,
  +        LOGGING_INTERVAL_KEY };
  +
  +    private static final String DEFAULTS = "/avalon.logging.properties";
  +
  +    private static final Resources REZ =
  +      ResourceManager.getPackageResources( LoggingCriteria.class );
  +
  +   /**
  +    * The factory parameters template.
  +    * @return the set of parameters constraining the criteria
  +    */
  +    private static Parameter[] buildParameters( InitialContext context ) 
  +    {
  +        return new Parameter[] {
  +            new ConfigurationParameter( 
  +              LOGGING_CONFIGURATION_KEY ),
  +            new Parameter( 
  +              LOGGING_BASEDIR_KEY, 
  +              File.class, 
  +              context.getInitialWorkingDirectory() ),
  +            new Parameter( 
  +              LOGGING_DEBUG_KEY, 
  +              Boolean.class, 
  +              new Boolean( false ) ),
  +            new LoggerParameter( 
  +              LOGGING_BOOTSTRAP_KEY, 
  +              new ConsoleLogger( ConsoleLogger.LEVEL_WARN ) ),
  +            new Parameter( 
  +              LOGGING_INTERVAL_KEY, 
  +              Long.class, 
  +              new Long( -1 ) )
  +        };
  +    }
  +
  +    //--------------------------------------------------------------
  +    // immutable state
  +    //--------------------------------------------------------------
  +
  +    private final InitialContext m_context;
  +
  +    //--------------------------------------------------------------
  +    // constructor
       //--------------------------------------------------------------
   
      /**
  -    * Set the bootstrap logging channel.  The supplied logging
  -    * channel is the logging channel used during the establishment of 
  -    * the logging system. The channel is typically a console logger 
  -    * set to warn or error priority.
  -    *
  -    * @param logger the boootstrap logging channel
  +    * Creation of a new default logging criteria.
  +    * @param context the initial repository context
       */
  -    void setBootstrapLogger( Logger logger );
  +    public LoggingCriteria( InitialContext context )
  +    {
  +        super( buildParameters( context ) );
  +        m_context = context;
  +
  +        try
  +        {
  +            //
  +            // get the properties declared relative to the application
  +            //
  +
  +            final String key = context.getApplicationKey();
  +            final File work = context.getInitialWorkingDirectory();
  +            DefaultsBuilder builder = new DefaultsBuilder( key, work );
  +            Properties defaults = 
  +              Defaults.getStaticProperties( LoggingCriteria.class );
  +
  +            final String[] keys = super.getKeys();
  +            Properties properties = 
  +              builder.getConsolidatedProperties( defaults, keys );
  +
  +            //
  +            // apply any non-null properties to the criteria
  +            //
  +
  +            for( int i=0; i<keys.length; i++ )
  +            {
  +                final String propertyKey = keys[i];
  +                final String value = properties.getProperty( propertyKey );
  +                if( null != value )
  +                {
  +                    put( propertyKey, value );
  +                }
  +            }
  +        }
  +        catch ( IOException e )
  +        {
  +            throw new LoggingRuntimeException( 
  +             "Failed to load implementation default resources.", e );
  +        }
  +    }
  +
  +    //--------------------------------------------------------------
  +    // LoggingCriteria
  +    //--------------------------------------------------------------
   
      /**
  -    * Set the base directory for logging resources.  The directory 
  -    * serves as the anchor directory for the resolution of filenames
  -    * related to file targets established by the logging system.
  -    *
  -    * @param dir the base directory
  +    * Set the debug enabled policy
  +    * @param mode TRUE to enabled debug mode else FALSE
       */
  -    void setBaseDirectory( File dir );
  +    public void setDebugEnabled( boolean mode )
  +    {
  +        put( LOGGING_DEBUG_KEY, new Boolean( mode ) );
  +    }
   
      /**
  -    * Set the logging system configuration.  If not set, an 
  -    * implementation of the logging system is required to establish
  -    * a console logging solution as a default logging target.
  -    *
  -    * @param config the configuration
  +    * Set the bootstrap logging channel
  +    * @param logger the boootstrap logging channel
       */
  -    void setConfiguration( Configuration config );
  +    public void setBootstrapLogger( Logger logger )
  +    {
  +        put( LOGGING_BOOTSTRAP_KEY, logger );
  +    }
   
      /**
  -    * Set the debug enabled policy.  Used to override the all logging
  -    * channel priotities to DEBUG level.  Useful when debuging applications.
  -    * @param mode TRUE to enabled debug mode else FALSE
  +    * Set the base directory.
  +    * @param dir the base directory
       */
  -    void setDebugEnabled( boolean mode );
  +    public void setBaseDirectory( File dir )
  +    {
  +        put( LOGGING_BASEDIR_KEY, dir );
  +    }
  +
  +   /**
  +    * Set the configuration URL.
  +    * @param url the configuration URL
  +    */
  +    public void setLoggingConfiguration( URL url )
  +    {
  +        put( LOGGING_CONFIGURATION_KEY, url );
  +    }
   
      /**
       * Get the bootstrap logging channel
       * @return the boootstrap logging channel
       */
  -    Logger getBootstrapLogger();
  +    public Logger getBootstrapLogger()
  +    {
  +        return (Logger) get( LOGGING_BOOTSTRAP_KEY );
  +    }
   
      /**
  -    * Return the base directory for logging resources.
  +    * Returns the base directory for logging resources.
       * @return the base directory
       */
  -    File getBaseDirectory();
  +    public File getBaseDirectory()
  +    {
  +        return (File) get( LOGGING_BASEDIR_KEY );
  +    }
   
      /**
  -    * Return the logging system configuration
  -    * @return the configuration
  -    */
  -    Configuration getConfiguration();
  -
  -   /**
  -    * Return debug policy.  If TRUE all logging channels will be 
  +    * Returns debug policy.  If TRUE all logging channels will be 
       * set to debug level.
       *
       * @return the debug policy
       */
  -    public boolean isDebugEnabled();
  -
  +    public boolean isDebugEnabled()
  +    {
  +        Boolean value = (Boolean) get( LOGGING_DEBUG_KEY );
  +        if( null != value ) 
  +            return value.booleanValue();
  +        return false;
  +    }
  +
  +   /**
  +    * Returns an external logging system configuration file
  +    * @return the configuration file (possibly null)
  +    */
  +    public URL getLoggingConfiguration()
  +    {
  +        return (URL) get( LOGGING_CONFIGURATION_KEY );
  +    }
  +
  +    /** Returns the logging configuration update interval.
  +     */
  +    public long getUpdateInterval()
  +    {
  +        Long value = (Long) get( LOGGING_INTERVAL_KEY );
  +        if( null != value ) 
  +            return value.longValue();
  +        return -1;
  +    }
  +    
  +    private static File getCanonicalForm( File file )
  +    {
  +        try
  +        {
  +            return file.getCanonicalFile();
  +        }
  +        catch( Throwable e )
  +        {
  +            final String error = 
  +              REZ.getString( 
  +                "criteria.artifact.cononical.error", 
  +                file.toString() );
  +            throw new LoggingRuntimeException( error, e );
  +        }
  +    }
   }
  
  
  
  1.1                  avalon/logging/spi/src/java/org/apache/avalon/logging/provider/ConfigurationParameter.java
  
  Index: ConfigurationParameter.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.provider;
  
  import java.io.File;
  import java.net.URL;
  import java.lang.reflect.Constructor;
  import java.util.ArrayList;
  import java.util.StringTokenizer;
  
  import org.apache.avalon.util.criteria.Parameter;
  import org.apache.avalon.util.criteria.CriteriaException;
  
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  
  /**
   * A parameter descriptor that supports transformation of a 
   * a string url to an URL instance.
   * 
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   * @version $Revision: 1.1 $
   */
  public class ConfigurationParameter extends Parameter
  {
      //--------------------------------------------------------------
      // static
      //--------------------------------------------------------------
  
      private static final Resources REZ =
        ResourceManager.getPackageResources( ConfigurationParameter.class );
  
      //--------------------------------------------------------------
      // constructors
      //--------------------------------------------------------------
  
     /**
      * Transform a string to a string array.
      * @param key the parameter key
      * @param defaults the default string array
      */
      public ConfigurationParameter( final String key ) 
      {
          super( key, URL.class );
      }
  
     /**
      * Resolve a supplied string to a configuration
      * @param value the value to resolve
      * @exception CriteriaException if an error occurs
      */
      public Object resolve( Object value ) 
        throws CriteriaException
      {
          if( value == null ) 
              return null;
          if( value instanceof URL )
          {
              return value;
          }
          if( value instanceof String )
          {
              return resolve( super.resolve( URL.class, value ) );
          }
          else if( value instanceof File )
          {
              File file = (File) value;
              if( ! file.exists() )
              {
                  final String error = 
                    REZ.getString( 
                      "parameter.configuration.fnf.error", 
                      file.toString() );
                  throw new CriteriaException( error );
              }
  
              try
              {
                  return file.toURL();
              }
              catch( Throwable e )
              {
                  final String error = 
                    REZ.getString( 
                      "parameter.configuration.file.error", 
                      file.toString() );
                  throw new CriteriaException( error );
              }
          }
          else
          {
              final String error = 
                REZ.getString( 
                  "parameter.unknown", 
                  value.getClass().getName(), URL.class.getName() );
              throw new CriteriaException( error );
          }
      }
  }
  
  
  
  1.1                  avalon/logging/spi/src/java/org/apache/avalon/logging/provider/ConsoleLogger.java
  
  Index: ConsoleLogger.java
  ===================================================================
  /*
   * Copyright 1997-2004 The Apache Software Foundation
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *     http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.avalon.logging.provider;
  
  import org.apache.avalon.framework.logger.Logger;
  
  /**
   * Logger sending everything to the standard output streams.
   * This is mainly for the cases when you have a utility that
   * does not have a logger to supply.
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   * @version CVS $Revision: 1.1 $ $Date: 2004/02/29 22:32:41 $
   */
  public final class ConsoleLogger
      implements Logger
  {
      /** Typecode for debugging messages. */
      public static final int LEVEL_DEBUG = 0;
  
      /** Typecode for informational messages. */
      public static final int LEVEL_INFO = 1;
  
      /** Typecode for warning messages. */
      public static final int LEVEL_WARN = 2;
  
      /** Typecode for error messages. */
      public static final int LEVEL_ERROR = 3;
  
      /** Typecode for fatal error messages. */
      public static final int LEVEL_FATAL = 4;
  
      /** Typecode for disabled log levels. */
      public static final int LEVEL_DISABLED = 5;
  
      private final int m_logLevel;
  
      /**
       * Creates a new ConsoleLogger with the priority set to DEBUG.
       */
      public ConsoleLogger()
      {
          this( LEVEL_DEBUG );
      }
  
      /**
       * Creates a new ConsoleLogger.
       * @param logLevel log level typecode
       */
      public ConsoleLogger( final int logLevel )
      {
          m_logLevel = logLevel;
      }
  
      /**
       * Logs a debugging message.
       *
       * @param message a <code>String</code> value
       */
      public void debug( final String message )
      {
          debug( message, null );
      }
  
      /**
       * Logs a debugging message and an exception.
       *
       * @param message a <code>String</code> value
       * @param throwable a <code>Throwable</code> value
       */
      public void debug( final String message, final Throwable throwable )
      {
          if( m_logLevel <= LEVEL_DEBUG )
          {
              System.out.print( "[DEBUG] " );
              System.out.println( message );
  
              if( null != throwable )
              {
                  throwable.printStackTrace( System.out );
              }
          }
      }
  
      /**
       * Returns <code>true</code> if debug-level logging is enabled, false otherwise.
       *
       * @return <code>true</code> if debug-level logging
       */
      public boolean isDebugEnabled()
      {
          return m_logLevel <= LEVEL_DEBUG;
      }
  
      /**
       * Logs an informational message.
       *
       * @param message a <code>String</code> value
       */
      public void info( final String message )
      {
          info( message, null );
      }
  
      /**
       * Logs an informational message and an exception.
       *
       * @param message a <code>String</code> value
       * @param throwable a <code>Throwable</code> value
       */
      public void info( final String message, final Throwable throwable )
      {
          if( m_logLevel <= LEVEL_INFO )
          {
              System.out.print( "[INFO] " );
              System.out.println( message );
  
              if( null != throwable )
              {
                  throwable.printStackTrace( System.out );
              }
          }
      }
  
      /**
       * Returns <code>true</code> if info-level logging is enabled, false otherwise.
       *
       * @return <code>true</code> if info-level logging is enabled
       */
      public boolean isInfoEnabled()
      {
          return m_logLevel <= LEVEL_INFO;
      }
  
      /**
       * Logs a warning message.
       *
       * @param message a <code>String</code> value
       */
      public void warn( final String message )
      {
          warn( message, null );
      }
  
      /**
       * Logs a warning message and an exception.
       *
       * @param message a <code>String</code> value
       * @param throwable a <code>Throwable</code> value
       */
      public void warn( final String message, final Throwable throwable )
      {
          if( m_logLevel <= LEVEL_WARN )
          {
              System.out.print( "[WARNING] " );
              System.out.println( message );
  
              if( null != throwable )
              {
                  throwable.printStackTrace( System.out );
              }
          }
      }
  
      /**
       * Returns <code>true</code> if warn-level logging is enabled, false otherwise.
       *
       * @return <code>true</code> if warn-level logging is enabled
       */
      public boolean isWarnEnabled()
      {
          return m_logLevel <= LEVEL_WARN;
      }
  
      /**
       * Logs an error message.
       *
       * @param message a <code>String</code> value
       */
      public void error( final String message )
      {
          error( message, null );
      }
  
      /**
       * Logs an error message and an exception.
       *
       * @param message a <code>String</code> value
       * @param throwable a <code>Throwable</code> value
       */
      public void error( final String message, final Throwable throwable )
      {
          if( m_logLevel <= LEVEL_ERROR )
          {
              System.out.print( "[ERROR] " );
              System.out.println( message );
  
              if( null != throwable )
              {
                  throwable.printStackTrace( System.out );
              }
          }
      }
  
      /**
       * Returns <code>true</code> if error-level logging is enabled, false otherwise.
       *
       * @return <code>true</code> if error-level logging is enabled
       */
      public boolean isErrorEnabled()
      {
          return m_logLevel <= LEVEL_ERROR;
      }
  
      /**
       * Logs a fatal error message.
       *
       * @param message a <code>String</code> value
       */
      public void fatalError( final String message )
      {
          fatalError( message, null );
      }
  
      /**
       * Logs a fatal error message and an exception.
       *
       * @param message a <code>String</code> value
       * @param throwable a <code>Throwable</code> value
       */
      public void fatalError( final String message, final Throwable throwable )
      {
          if( m_logLevel <= LEVEL_FATAL )
          {
              System.out.print( "[FATAL ERROR] " );
              System.out.println( message );
  
              if( null != throwable )
              {
                  throwable.printStackTrace( System.out );
              }
          }
      }
  
      /**
       * Returns <code>true</code> if fatal-level logging is enabled, false otherwise.
       *
       * @return <code>true</code> if fatal-level logging is enabled
       */
      public boolean isFatalErrorEnabled()
      {
          return m_logLevel <= LEVEL_FATAL;
      }
  
      /**
       * Just returns this logger (<code>ConsoleLogger</code> is not hierarchical).
       *
       * @param name ignored
       * @return this logger
       */
      public Logger getChildLogger( final String name )
      {
          return this;
      }
  }
  
  
  
  1.1                  avalon/logging/spi/src/java/org/apache/avalon/logging/provider/LoggerParameter.java
  
  Index: LoggerParameter.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.provider;
  
  import java.io.File;
  import java.net.URL;
  import java.lang.reflect.Constructor;
  import java.util.ArrayList;
  import java.util.StringTokenizer;
  
  import org.apache.avalon.framework.logger.Logger;
  
  import org.apache.avalon.util.criteria.Parameter;
  import org.apache.avalon.util.criteria.CriteriaException;
  
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  
  /**
   * A parameter descriptor that supports transformation of a 
   * a string to a Logger instance.
   * 
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   * @version $Revision: 1.1 $
   */
  public class LoggerParameter extends Parameter
  {
      //--------------------------------------------------------------
      // static
      //--------------------------------------------------------------
  
      private static final Resources REZ =
        ResourceManager.getPackageResources( LoggerParameter.class );
  
      private static final int PRIORITY = ConsoleLogger.LEVEL_WARN;
  
      //--------------------------------------------------------------
      // constructors
      //--------------------------------------------------------------
  
     /**
      * Creation of a new logger parameter.  The parameter support
      * convertion of strings in the form "debug", "info", "warn", 
      * "error", "fatal" and "none" to an equivalent logger.
      *
      * @param key the parameter key
      * @param logger the default logger
      */
      public LoggerParameter( final String key, final Logger logger )
      {
          super( key, Logger.class, logger );
      }
  
     /**
      * Resolve a supplied string to a configuration
      * @param value the value to resolve
      * @exception CriteriaException if an error occurs
      */
      public Object resolve( Object value ) 
        throws CriteriaException
      {
          if( value == null )
          {
              return new ConsoleLogger( PRIORITY );
          }
          if( value instanceof Logger )
          {
              return value;
          }
          if( value instanceof String )
          {
              String priority = ((String)value).toLowerCase();
              if( priority.equals( "debug" ) )
              {
                  return new ConsoleLogger( ConsoleLogger.LEVEL_DEBUG );
              }
              else if( priority.equals( "info" ) )
              {
                  return new ConsoleLogger( ConsoleLogger.LEVEL_INFO );
              }
              else if( priority.equals( "warn" ) )
              {
                  return new ConsoleLogger( ConsoleLogger.LEVEL_WARN );
              }
              else if( priority.equals( "error" ) )
              {
                  return new ConsoleLogger( ConsoleLogger.LEVEL_ERROR );
              }
              else if( priority.equals( "fatal" ) )
              {
                  return new ConsoleLogger( ConsoleLogger.LEVEL_FATAL );
              }
              else if( priority.equals( "none" ) )
              {
                  return new ConsoleLogger( ConsoleLogger.LEVEL_DISABLED );
              }
          }
          final String error = 
            REZ.getString( 
              "parameter.unknown", 
              value.getClass().getName(), Logger.class.getName() );
          throw new CriteriaException( error );
      }
  }
  
  
  
  1.1                  avalon/logging/spi/src/java/org/apache/avalon/logging/provider/LoggingCriteria.properties
  
  Index: LoggingCriteria.properties
  ===================================================================
  #
  # Default static properties for the logkit logging criteria.
  # (no properties defined at this time)
  #
  
  
  1.3       +4 -0      avalon/logging/test/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/avalon/logging/test/project.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- project.xml	27 Feb 2004 22:39:35 -0000	1.2
  +++ project.xml	29 Feb 2004 22:32:42 -0000	1.3
  @@ -39,5 +39,9 @@
         <artifactId>avalon-logging-spi</artifactId>
         <version>1.0-SNAPSHOT</version>
       </dependency>
  +    <dependency>
  +      <id>excalibur-i18n</id>
  +      <version>1.1</version>
  +    </dependency>
     </dependencies>
   </project>
  
  
  
  1.2       +1 -1      avalon/logging/test/src/test/org/apache/avalon/logging/log4j/test/AlternateLoggingManagerTestCase.java
  
  Index: AlternateLoggingManagerTestCase.java
  ===================================================================
  RCS file: /home/cvs/avalon/logging/test/src/test/org/apache/avalon/logging/log4j/test/AlternateLoggingManagerTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AlternateLoggingManagerTestCase.java	29 Feb 2004 14:31:28 -0000	1.1
  +++ AlternateLoggingManagerTestCase.java	29 Feb 2004 22:32:42 -0000	1.2
  @@ -74,7 +74,7 @@
       {
           m_manager = 
             LoggingManagerHelper.setUpLoggingManager( 
  -            "avalon-log4j-impl", "log4j/logging2.xml" );
  +            "avalon-log4j-impl", "log4j/log4j.properties" );
       }
   
       public void testKernelLogging() throws Exception
  
  
  
  1.3       +2 -2      avalon/logging/test/src/test/org/apache/avalon/logging/log4j/test/DefaultLoggingManagerTestCase.java
  
  Index: DefaultLoggingManagerTestCase.java
  ===================================================================
  RCS file: /home/cvs/avalon/logging/test/src/test/org/apache/avalon/logging/log4j/test/DefaultLoggingManagerTestCase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultLoggingManagerTestCase.java	27 Feb 2004 22:39:35 -0000	1.2
  +++ DefaultLoggingManagerTestCase.java	29 Feb 2004 22:32:42 -0000	1.3
  @@ -74,7 +74,7 @@
       {
           m_manager = 
             LoggingManagerHelper.setUpLoggingManager( 
  -            "avalon-log4j-impl", "log4j/logging.xml" );
  +            "avalon-log4j-impl", "log4j/log4j.xml" );
       }
   
       public void testKernelLogging() throws Exception
  
  
  

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