avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon/logging/spi/src/java/org/apache/avalon/logging/provider LoggingCriteria.java ConfigurationParameter.java ConsoleLogger.java LoggerParameter.java LoggingCriteria.properties
Date Mon, 01 Mar 2004 13:39:28 GMT
mcconnell    2004/03/01 05:39:28

  Modified:    logging/api project.xml
               logging/log4j project.xml
               logging/log4j/src/java/org/apache/avalon/logging/log4j
                        Log4JLoggingFactory.java
               logging/logkit/impl project.xml
               logging/logkit/impl/src/java/org/apache/avalon/logging/logkit
                        DefaultLoggingFactory.java
               logging/spi/src/java/org/apache/avalon/logging/provider
                        LoggingCriteria.java
  Added:       logging/impl .cvsignore maven.xml project.xml
               logging/impl/src/java/org/apache/avalon/logging/impl
                        ConfigurationParameter.java ConsoleLogger.java
                        DefaultLoggingCriteria.java
                        DefaultLoggingCriteria.properties
                        LoggerParameter.java LoggingException.java
                        package.html
  Removed:     logging/spi/src/java/org/apache/avalon/logging/provider
                        ConfigurationParameter.java ConsoleLogger.java
                        LoggerParameter.java LoggingCriteria.properties
  Log:
  Move implementation classes out of the SPI and into a common impl.
  
  Revision  Changes    Path
  1.4       +0 -13     avalon/logging/api/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/avalon/logging/api/project.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- project.xml	24 Feb 2004 21:19:53 -0000	1.3
  +++ project.xml	1 Mar 2004 13:39:28 -0000	1.4
  @@ -17,17 +17,4 @@
   Meta data for logging category directives.
     </description>
     
  -  <dependencies>
  -    <dependency>
  -      <groupId>avalon-framework</groupId>
  -      <artifactId>avalon-framework-api</artifactId>
  -      <version>4.1.5</version>
  -    </dependency>
  -    <dependency>
  -      <groupId>avalon-repository</groupId>
  -      <artifactId>avalon-repository-api</artifactId>
  -      <version>2.0-SNAPSHOT</version>
  -    </dependency>
  -  </dependencies>
  -
   </project>
  
  
  
  1.1                  avalon/logging/impl/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  maven.log
  velocity.log
  build.properties
  target
  .classpath
  .project
  
  
  
  1.1                  avalon/logging/impl/maven.xml
  
  Index: maven.xml
  ===================================================================
  <project default="jar:install">
  </project>
  
  
  
  1.1                  avalon/logging/impl/project.xml
  
  Index: project.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1"?>
  
  <project>
  
    <extend>${basedir}/../project.xml</extend>
  
    <groupId>avalon-logging</groupId>
    <id>avalon-logging-impl</id>
    <name>Avalon Logging Common Implementation</name>
    <package>org.apache.avalon.logging.provider</package>
    <currentVersion>1.0-SNAPSHOT</currentVersion>
  
    <inceptionYear>2002</inceptionYear>
    <shortDescription>Avalon Logging SPCommon Implementation</shortDescription>
  
    <description>
  Service provider API.
    </description>
    
    <dependencies>
      <dependency>
        <groupId>avalon-framework</groupId>
        <artifactId>avalon-framework-api</artifactId>
        <version>4.1.5</version>
      </dependency>
      <dependency>
        <groupId>avalon-repository</groupId>
        <artifactId>avalon-repository-api</artifactId>
        <version>2.0-SNAPSHOT</version>
      </dependency>
      <dependency>
        <groupId>avalon-repository</groupId>
        <artifactId>avalon-repository-spi</artifactId>
        <version>2.0-SNAPSHOT</version>
      </dependency>
      <!--
      <dependency>
        <groupId>avalon-repository</groupId>
        <artifactId>avalon-repository-main</artifactId>
        <version>2.0-SNAPSHOT</version>
      </dependency>
      -->
      <dependency>
        <groupId>avalon-logging</groupId>
        <artifactId>avalon-logging-api</artifactId>
        <version>1.0-SNAPSHOT</version>
      </dependency>
      <dependency>
        <groupId>avalon-logging</groupId>
        <artifactId>avalon-logging-spi</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>
  
  </project>
  
  
  
  1.1                  avalon/logging/impl/src/java/org/apache/avalon/logging/impl/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.impl;
  
  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/impl/src/java/org/apache/avalon/logging/impl/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.impl;
  
  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/03/01 13:39:28 $
   */
  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/impl/src/java/org/apache/avalon/logging/impl/DefaultLoggingCriteria.java
  
  Index: DefaultLoggingCriteria.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.impl;
  
  import java.io.File;
  import java.net.URL;
  import java.io.IOException;
  import java.util.Properties;
  
  import org.apache.avalon.framework.logger.Logger;
  
  import org.apache.avalon.logging.provider.LoggingCriteria;
  import org.apache.avalon.logging.provider.LoggingException;
  import org.apache.avalon.logging.provider.LoggingRuntimeException;
  
  import org.apache.avalon.repository.Artifact;
  import org.apache.avalon.repository.ArtifactHandler;
  import org.apache.avalon.repository.provider.InitialContext;
  
  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.
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   * @version $Revision: 1.1 $
   */
  public class DefaultLoggingCriteria extends Criteria implements LoggingCriteria
  {
      //--------------------------------------------------------------
      // 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( DefaultLoggingCriteria.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
      //--------------------------------------------------------------
  
     /**
      * Creation of a new default logging criteria.
      * @param context the initial repository context
      */
      public DefaultLoggingCriteria( 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 debug enabled policy
      * @param mode TRUE to enabled debug mode else FALSE
      */
      public void setDebugEnabled( boolean mode )
      {
          put( LOGGING_DEBUG_KEY, new Boolean( mode ) );
      }
  
     /**
      * Set the bootstrap logging channel
      * @param logger the boootstrap logging channel
      */
      public void setBootstrapLogger( Logger logger )
      {
          put( LOGGING_BOOTSTRAP_KEY, logger );
      }
  
     /**
      * Set the base directory.
      * @param dir the base directory
      */
      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
      */
      public Logger getBootstrapLogger()
      {
          return (Logger) get( LOGGING_BOOTSTRAP_KEY );
      }
  
     /**
      * Returns the base directory for logging resources.
      * @return the base directory
      */
      public File getBaseDirectory()
      {
          return (File) get( LOGGING_BASEDIR_KEY );
      }
  
     /**
      * Returns debug policy.  If TRUE all logging channels will be 
      * set to debug level.
      *
      * @return the debug policy
      */
      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/impl/src/java/org/apache/avalon/logging/impl/DefaultLoggingCriteria.properties
  
  Index: DefaultLoggingCriteria.properties
  ===================================================================
  #
  # Default static properties for the logkit logging criteria.
  # (no properties defined at this time)
  #
  
  
  1.1                  avalon/logging/impl/src/java/org/apache/avalon/logging/impl/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.impl;
  
  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/impl/src/java/org/apache/avalon/logging/impl/LoggingException.java
  
  Index: LoggingException.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.impl;
  
  import org.apache.avalon.framework.CascadingException;
  
  /**
   * Exception to indicate that there was a logging management related error.
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   * @version $Revision: 1.1 $ $Date: 2004/03/01 13:39:28 $
   */
  public class LoggingException
          extends CascadingException
  {
  
      /**
       * Construct a new <code>LoggingException</code> instance.
       *
       * @param message The detail message for this exception.
       */
      public LoggingException( final String message )
      {
          this( message, null );
      }
  
      /**
       * Construct a new <code>LoggingException</code> instance.
       *
       * @param message The detail message for this exception.
       * @param throwable the root cause of the exception
       */
      public LoggingException( final String message, final Throwable throwable )
      {
          super( message, throwable );
      }
  }
  
  
  
  
  1.1                  avalon/logging/impl/src/java/org/apache/avalon/logging/impl/package.html
  
  Index: package.html
  ===================================================================
  <body>
  <p>The <code>provider</code> package contains the
  {@link org.apache.avalon.logging.provider.LoggingManager} which
  is an interface to the initial logging management system that leverages meta 
  information about logging targets and catagories.
  </p>
  </body>
  
  
  
  1.4       +5 -0      avalon/logging/log4j/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/avalon/logging/log4j/project.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- project.xml	27 Feb 2004 22:39:35 -0000	1.3
  +++ project.xml	1 Mar 2004 13:39:28 -0000	1.4
  @@ -33,6 +33,11 @@
         <artifactId>avalon-logging-spi</artifactId>
         <version>1.0-SNAPSHOT</version>
       </dependency>
  +    <dependency>
  +      <groupId>avalon-logging</groupId>
  +      <artifactId>avalon-logging-impl</artifactId>
  +      <version>1.0-SNAPSHOT</version>
  +    </dependency>
   
       <dependency>
         <groupId>avalon-framework</groupId>
  
  
  
  1.8       +3 -2      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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Log4JLoggingFactory.java	29 Feb 2004 22:32:41 -0000	1.7
  +++ Log4JLoggingFactory.java	1 Mar 2004 13:39:28 -0000	1.8
  @@ -32,6 +32,7 @@
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.ConfigurationUtil;
   
  +import org.apache.avalon.logging.impl.DefaultLoggingCriteria;
   import org.apache.avalon.logging.provider.LoggingCriteria;
   import org.apache.avalon.logging.provider.LoggingFactory;
   import org.apache.avalon.logging.provider.LoggingManager;
  @@ -83,7 +84,7 @@
       */
       public LoggingCriteria createDefaultLoggingCriteria()
       {
  -        return new LoggingCriteria( m_Context );
  +        return new DefaultLoggingCriteria( m_Context );
       }
   
      /**
  
  
  
  1.6       +5 -0      avalon/logging/logkit/impl/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/avalon/logging/logkit/impl/project.xml,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- project.xml	27 Feb 2004 22:39:35 -0000	1.5
  +++ project.xml	1 Mar 2004 13:39:28 -0000	1.6
  @@ -35,6 +35,11 @@
       </dependency>
       <dependency>
         <groupId>avalon-logging</groupId>
  +      <artifactId>avalon-logging-impl</artifactId>
  +      <version>1.0-SNAPSHOT</version>
  +    </dependency>
  +    <dependency>
  +      <groupId>avalon-logging</groupId>
         <artifactId>avalon-logkit-api</artifactId>
         <version>1.0-SNAPSHOT</version>
       </dependency>
  
  
  
  1.6       +5 -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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DefaultLoggingFactory.java	29 Feb 2004 22:32:41 -0000	1.5
  +++ DefaultLoggingFactory.java	1 Mar 2004 13:39:28 -0000	1.6
  @@ -34,13 +34,14 @@
   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.impl.ConsoleLogger;
  +import org.apache.avalon.logging.impl.DefaultLoggingCriteria;
  +import org.apache.avalon.logging.data.CategoriesDirective;
  +import org.apache.avalon.logging.data.CategoryDirective;
   import org.apache.avalon.logging.provider.LoggingCriteria;
   import org.apache.avalon.logging.provider.LoggingFactory;
   import org.apache.avalon.logging.provider.LoggingException;
   import org.apache.avalon.logging.provider.LoggingManager;
  -import org.apache.avalon.logging.data.CategoriesDirective;
  -import org.apache.avalon.logging.data.CategoryDirective;
   import org.apache.avalon.logging.logkit.factory.FileTargetFactory;
   import org.apache.avalon.logging.logkit.factory.StreamTargetFactory;
   import org.apache.avalon.logging.logkit.factory.MulticastTargetFactory;
  @@ -116,7 +117,7 @@
       */
       public LoggingCriteria createDefaultLoggingCriteria()
       {
  -        return new LoggingCriteria( m_context );
  +        return new DefaultLoggingCriteria( m_context );
       }
   
      /**
  
  
  
  1.3       +24 -191   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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- LoggingCriteria.java	29 Feb 2004 22:32:41 -0000	1.2
  +++ LoggingCriteria.java	1 Mar 2004 13:39:28 -0000	1.3
  @@ -19,35 +19,19 @@
   
   import java.io.File;
   import java.net.URL;
  -import java.io.IOException;
  -import java.util.Properties;
  +import java.util.Map;
   
   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.
  + * LoggingCriteria is convinience interface that extends Map with 
  + * a set of operations that enable easy manipulation of the logging
  + * system parameters.
    *
    * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
    * @version $Revision$
    */
  -public class LoggingCriteria extends Criteria 
  +public interface LoggingCriteria extends Map 
   {
       //--------------------------------------------------------------
       // criteria keys
  @@ -56,13 +40,13 @@
      /**
       * The logging configuration key.
       */
  -    public static String LOGGING_CONFIGURATION_KEY = 
  +    String LOGGING_CONFIGURATION_KEY = 
         "avalon.logging.configuration";
   
      /**
       * The logging system bootstrap logger key.
       */
  -    public static String LOGGING_BOOTSTRAP_KEY = 
  +    String LOGGING_BOOTSTRAP_KEY = 
         "avalon.logging.bootstrap";
   
      /**
  @@ -71,7 +55,7 @@
       * logging file should be created in the directory 
       * assigned to this key.
       */
  -    public static String LOGGING_BASEDIR_KEY = 
  +    String LOGGING_BASEDIR_KEY = 
         "avalon.logging.basedir";
   
      /**
  @@ -79,172 +63,50 @@
       * Logging subsystems that supports changes on-the-fly, will
       * be passed this argument.
       */
  -    public static String LOGGING_INTERVAL_KEY = 
  +    String LOGGING_INTERVAL_KEY = 
         "avalon.logging.update";
   
      /**
       * Debug mode.
       */
  -    public static String LOGGING_DEBUG_KEY = 
  +    String LOGGING_DEBUG_KEY = 
         "avalon.logging.debug";
   
  -    //--------------------------------------------------------------
  -    // 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
  -    //--------------------------------------------------------------
  -
  -   /**
  -    * Creation of a new default logging criteria.
  -    * @param context the initial repository context
  -    */
  -    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 debug enabled policy
       * @param mode TRUE to enabled debug mode else FALSE
       */
  -    public void setDebugEnabled( boolean mode )
  -    {
  -        put( LOGGING_DEBUG_KEY, new Boolean( mode ) );
  -    }
  +    void setDebugEnabled( boolean mode );
   
      /**
       * Set the bootstrap logging channel
       * @param logger the boootstrap logging channel
       */
  -    public void setBootstrapLogger( Logger logger )
  -    {
  -        put( LOGGING_BOOTSTRAP_KEY, logger );
  -    }
  +    void setBootstrapLogger( Logger logger );
   
      /**
       * Set the base directory.
       * @param dir the base directory
       */
  -    public void setBaseDirectory( File dir )
  -    {
  -        put( LOGGING_BASEDIR_KEY, dir );
  -    }
  +    void setBaseDirectory( File dir );
   
      /**
       * Set the configuration URL.
       * @param url the configuration URL
       */
  -    public void setLoggingConfiguration( URL url )
  -    {
  -        put( LOGGING_CONFIGURATION_KEY, url );
  -    }
  +    void setLoggingConfiguration( URL url );
   
      /**
       * Get the bootstrap logging channel
       * @return the boootstrap logging channel
       */
  -    public Logger getBootstrapLogger()
  -    {
  -        return (Logger) get( LOGGING_BOOTSTRAP_KEY );
  -    }
  +    Logger getBootstrapLogger();
   
      /**
       * Returns the base directory for logging resources.
       * @return the base directory
       */
  -    public File getBaseDirectory()
  -    {
  -        return (File) get( LOGGING_BASEDIR_KEY );
  -    }
  +    File getBaseDirectory();
   
      /**
       * Returns debug policy.  If TRUE all logging channels will be 
  @@ -252,46 +114,17 @@
       *
       * @return the debug policy
       */
  -    public boolean isDebugEnabled()
  -    {
  -        Boolean value = (Boolean) get( LOGGING_DEBUG_KEY );
  -        if( null != value ) 
  -            return value.booleanValue();
  -        return false;
  -    }
  +    boolean isDebugEnabled();
   
      /**
       * 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;
  -    }
  +    URL getLoggingConfiguration();
  +
  +   /** 
  +    * Returns the logging configuration update interval.
  +    */
  +    long getUpdateInterval();
       
  -    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 );
  -        }
  -    }
   }
  
  
  

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


Mime
View raw message