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/24 22:37:38 UTC

cvs commit: avalon/logging/log4j/test maven.xml project.xml

niclas      2004/02/24 13:37:38

  Added:       logging/log4j maven.xml project.properties project.xml
               logging/log4j/src/java/org/apache/avalon/logging/log4j
                        ConfigurationParameter.java
                        DefaultLoggingCriteria.java Log4JLogger.java
                        Log4JLoggingFactory.java LoggerParameter.java
                        LoggingManagerImpl.java
               logging/log4j/test maven.xml project.xml
  Log:
  Added a Log4J plugin.
  
  Revision  Changes    Path
  1.1                  avalon/logging/log4j/maven.xml
  
  Index: maven.xml
  ===================================================================
  <project default="jar:install" xmlns:maven="jelly:maven" xmlns:j="jelly:core" xmlns:util="jelly:util" xmlns:ant="jelly:ant">
  
    <postGoal name="java:prepare-filesystem">
      <attainGoal name="avalon:artifact"/>
    </postGoal>
  
    <postGoal name="jar:install">
      <ant:copy verbose="yes"
         toDir="${maven.repo.local}/${pom.groupId}/jars" 
         file="${maven.build.dir}/${pom.artifactId}-${pom.currentVersion}.jar.meta" />
    </postGoal>
  
  
  
  </project>
  
  
  
  1.1                  avalon/logging/log4j/project.properties
  
  Index: project.properties
  ===================================================================
  #
  # factory class
  #
  
  avalon.artifact.factory = org.apache.avalon.logging.log4j.Log4JLoggingFactory
  
  
  
  
  
  1.1                  avalon/logging/log4j/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-log4j-impl</id>
    <name>Avalon Log4J Logging Implementation</name>
    <package>org.apache.avalon.logging.log4j</package>
    <currentVersion>1.0-SNAPSHOT</currentVersion>
  
    <inceptionYear>2002</inceptionYear>
    <shortDescription>Avalon Log4J Logging Implementation.</shortDescription>
  
    <dependencies>
  
      <!-- avalon dependecies -->
  
      <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-framework</groupId>
        <artifactId>avalon-framework-api</artifactId>
        <version>4.1.5</version>
      </dependency>
      <dependency>
        <groupId>avalon-framework</groupId>
        <artifactId>avalon-framework-impl</artifactId>
        <version>4.1.5</version>
      </dependency>
  
      <dependency>
        <id>excalibur-i18n</id>
        <version>1.1</version>
      </dependency>
      <dependency>
        <id>excalibur-configuration</id>
        <version>1.1</version>
      </dependency>
  
      <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.8</version>
      </dependency>
  
      <!-- pre JDK 1.4 dependencies -->
  
      <dependency>
        <id>xml-apis</id>
        <version>2.0.2</version>
      </dependency>
      <dependency>
        <groupId>xml-apis</groupId>
        <artifactId>xmlParserAPIs</artifactId>
        <version>2.0.2</version>
      </dependency>
      <dependency>
        <id>xerces</id>
        <version>2.4.0</version>
      </dependency>
  
    </dependencies>
  </project>
  
  
  
  1.1                  avalon/logging/log4j/src/java/org/apache/avalon/logging/log4j/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.log4j;
  
  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.configuration.Configuration;
  import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
  
  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 or file to a configuration 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 DefaultConfigurationBuilder BUILDER =
        new DefaultConfigurationBuilder();
  
      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, final Configuration defaults ) 
      {
          super( key, Configuration.class, defaults );
      }
  
     /**
      * 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 Configuration )
          {
              return value;
          }
          if( value instanceof String )
          {
              try
              {
                  return resolve( super.resolve( File.class, value ) );
              }
              catch( CriteriaException ce )
              {
                  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
              {
                  String path = file.toURL().toString();
                  return BUILDER.build( path );
              }
              catch( Throwable e )
              {
                  final String error = 
                    REZ.getString( 
                      "parameter.configuration.file.error", 
                      file.toString() );
                  throw new CriteriaException( error );
              }
          }
          else if( value instanceof URL )
          {
              try
              {
                  String path = value.toString();
                  return BUILDER.build( path );
              }
              catch( Throwable e )
              {
                  final String error = 
                    REZ.getString( 
                      "parameter.configuration.url.error", 
                      value.toString() );
                  throw new CriteriaException( error );
              }
          }
          else
          {
              final String error = 
                REZ.getString( 
                  "parameter.unknown", 
                  value.getClass().getName(), Configuration.class.getName() );
              throw new CriteriaException( error );
          }
      }
  }
  
  
  
  1.1                  avalon/logging/log4j/src/java/org/apache/avalon/logging/log4j/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.log4j;
  
  import java.io.File;
  import java.net.URL;
  import java.io.IOException;
  import java.util.Properties;
  
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.DefaultConfiguration;
  import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.logger.ConsoleLogger;
  
  import org.apache.avalon.logging.provider.LoggingCriteria;
  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.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;
  
  import org.apache.excalibur.configuration.ConfigurationUtil;
  
  
  /**
   * 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 };
  
      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 DefaultConfiguration( "logging" ) ),
              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 ) )
          };
      }
  
      //--------------------------------------------------------------
      // 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( DefaultLoggingCriteria.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 logging system configuration
      * @param config the configuration
      */
      public void setConfiguration( Configuration config )
      {
          put( LOGGING_CONFIGURATION_KEY, config );
      }
  
     /**
      * Get the bootstrap logging channel
      * @return the boootstrap logging channel
      */
      public Logger getBootstrapLogger()
      {
          return (Logger) get( LOGGING_BOOTSTRAP_KEY );
      }
  
     /**
      * Return the base directory for logging resources.
      * @return the base directory
      */
      public File getBaseDirectory()
      {
          return (File) get( LOGGING_BASEDIR_KEY );
      }
  
     /**
      * Return the logging system configuration
      * @return the configuration
      */
      public Configuration getConfiguration()
      {
          return (Configuration) get( LOGGING_CONFIGURATION_KEY );
      }
  
     /**
      * Return 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;
      }
  
      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/log4j/src/java/org/apache/avalon/logging/log4j/Log4JLogger.java
  
  Index: Log4JLogger.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.log4j;
  
  import org.apache.avalon.framework.logger.Logger;
  
  import org.apache.log4j.Level;
  
  public class Log4JLogger 
      implements Logger
  {
      private org.apache.log4j.Logger  m_Logger;
      
      Log4JLogger( org.apache.log4j.Logger log4jLogger )
      {
          m_Logger = log4jLogger;
      }
      
      /**
       * Log a debug message.
       *
       * @param message the message
       */
      public void debug( String message )
      {
          m_Logger.debug( message );
      }
  
      /**
       * Log a debug message.
       *
       * @param message the message
       * @param throwable the throwable
       */
      public void debug( String message, Throwable throwable )
      {
          m_Logger.debug( message, throwable );
      }
  
      /**
       * Determine if messages of priority "debug" will be logged.
       *
       * @return true if "debug" messages will be logged
       */
      public boolean isDebugEnabled()
      {
          return m_Logger.isDebugEnabled();
      }
  
      /**
       * Log a info message.
       *
       * @param message the message
       */
      public void info( String message )
      {
          m_Logger.info( message );
      }
  
      /**
       * Log a info message.
       *
       * @param message the message
       * @param throwable the throwable
       */
      public void info( String message, Throwable throwable )
      {
          m_Logger.info( message, throwable );
      }
  
      /**
       * Determine if messages of priority "info" will be logged.
       *
       * @return true if "info" messages will be logged
       */
      public boolean isInfoEnabled()
      {
          return m_Logger.isInfoEnabled();
      }
  
      /**
       * Log a warn message.
       *
       * @param message the message
       */
      public void warn( String message )
      {
          m_Logger.warn( message );
      }
  
      /**
       * Log a warn message.
       *
       * @param message the message
       * @param throwable the throwable
       */
      public void warn( String message, Throwable throwable )
      {
          m_Logger.warn( message, throwable );
      }
  
      /**
       * Determine if messages of priority "warn" will be logged.
       *
       * @return true if "warn" messages will be logged
       */
      public boolean isWarnEnabled()
      {
          return m_Logger.isEnabledFor( Level.WARN );
      }
  
      /**
       * Log a error message.
       *
       * @param message the message
       */
      public void error( String message )
      {
          m_Logger.error( message );
      }
  
      /**
       * Log a error message.
       *
       * @param message the message
       * @param throwable the throwable
       */
      public void error( String message, Throwable throwable )
      {
          m_Logger.error( message, throwable );
      }
  
      /**
       * Determine if messages of priority "error" will be logged.
       *
       * @return true if "error" messages will be logged
       */
      public boolean isErrorEnabled()
      {
          return m_Logger.isEnabledFor( Level.ERROR );
      }
  
      /**
       * Log a fatalError message.
       *
       * @param message the message
       */
      public void fatalError( String message )
      {
          m_Logger.fatal( message );
      }
  
      /**
       * Log a fatalError message.
       *
       * @param message the message
       * @param throwable the throwable
       */
      public void fatalError( String message, Throwable throwable )
      {
          m_Logger.fatal( message, throwable );
      }
  
      /**
       * Determine if messages of priority "fatalError" will be logged.
       *
       * @return true if "fatalError" messages will be logged
       */
      public boolean isFatalErrorEnabled()
      {
          return m_Logger.isEnabledFor( Level.FATAL );
      }
  
      /**
       * Create a new child logger.
       * The name of the child logger is [current-loggers-name].[passed-in-name]
       * Throws <code>IllegalArgumentException</code> if name has an empty element name
       *
       * @param name the subname of this logger
       * @return the new logger
       */
      public Logger getChildLogger( String name )
      {
          String newName = m_Logger.getName() + "." + name;
          org.apache.log4j.Logger childLog4JLogger = 
              org.apache.log4j.Logger.getLogger( newName );
          Log4JLogger child = new Log4JLogger( childLog4JLogger );
          return child;
      }
  } 
  
  
  
  1.1                  avalon/logging/log4j/src/java/org/apache/avalon/logging/log4j/Log4JLoggingFactory.java
  
  Index: Log4JLoggingFactory.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.log4j;
  
  import java.util.HashMap;
  import java.util.Map;
  
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  
  import org.apache.avalon.framework.configuration.Configuration;
  
  import org.apache.avalon.logging.provider.LoggingCriteria;
  
  import org.apache.avalon.repository.provider.InitialContext;
  import org.apache.avalon.repository.provider.Factory;
  
  import org.apache.log4j.PropertyConfigurator;
  import org.apache.log4j.xml.DOMConfigurator;
  
  /**
   * A Log4J factory.
   *
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   * @version $Revision: 1.1 $
   */
  public class Log4JLoggingFactory
      implements Factory
  {
      private static final Resources REZ =
        ResourceManager.getPackageResources( DefaultLoggingCriteria.class );
      
      private final ClassLoader    m_Classloader;
      private final InitialContext m_Context;
      private       boolean        m_Log4JInitialized;
     
     /**
      * Creation of a new default factory.
      * @param context the repository inital context
      * @param classloader the factory classloader
      */
      public Log4JLoggingFactory( InitialContext context, ClassLoader classloader )
      {
          m_Context = context;
          m_Classloader = classloader;
          m_Log4JInitialized = false;
      }
     
     /**
      * Return a new instance of default criteria for the factory.
      * @return a new criteria instance
      */
      public Map createDefaultCriteria()
      {
          return new DefaultLoggingCriteria( m_Context );
      }
  
     /**
      * Create a new instance of an application.
      * @return the application instance
      */
      public Object create() throws Exception
      {
          return new LoggingManagerImpl();
      }
  
     /**
      * Create a new instance of an application.
      * @param criteria the creation criteria
      * @return the application instance
      */
      public Object create( Map criteriaMap ) 
          throws Exception
      {
          if( ! m_Log4JInitialized )
          {
              if( null == criteriaMap )
              {
                  throw new NullPointerException( "criteriaMap" );
              }
  
              final LoggingCriteria criteria = getLoggingCriteria( criteriaMap );
              
              final Configuration config = criteria.getConfiguration();
              Configuration srcConf = config.getChild( "src" );
              Configuration updateConf = config.getChild( "update" );
              String src = srcConf.getValue();
              long updateInterval = updateConf.getValueAsLong( 0 );
              if( updateInterval > 0 )
              {
                  configureWithWatch( src, updateInterval );
              }
              else
              {
                  configureWithOutWatch( src );
              }
          }
          return new LoggingManagerImpl();
      }
      
      private void configureWithWatch( String src, long interval )
      {
          if( src.endsWith( ".xml" ) )
          {
              DOMConfigurator.configureAndWatch( src, interval );
          }
          else
          {
              PropertyConfigurator.configureAndWatch( src, interval );
          }
      }
      
      private void configureWithOutWatch( String src )
      {
          if( src.endsWith( ".xml" ) )
          {
              DOMConfigurator.configure( src );
          }
          else
          {
              PropertyConfigurator.configure( src );
          }
      }
  
      private LoggingCriteria getLoggingCriteria( Map map )
      {
          if( map instanceof LoggingCriteria )
          {
              return (LoggingCriteria) map;
          }
          else
          {
              final String error = 
                REZ.getString( 
                  "factory.bad-criteria", 
                  map.getClass().getName() );
              throw new IllegalArgumentException( error );
          }
      }
  
  }
  
  
  
  1.1                  avalon/logging/log4j/src/java/org/apache/avalon/logging/log4j/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.log4j;
  
  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.framework.logger.ConsoleLogger;
  
  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 or file to a configuration 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/log4j/src/java/org/apache/avalon/logging/log4j/LoggingManagerImpl.java
  
  Index: LoggingManagerImpl.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.log4j;
  
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.logging.data.CategoryDirective;
  import org.apache.avalon.logging.data.CategoriesDirective;
  
  import org.apache.avalon.logging.provider.LoggingManager;
  import org.apache.avalon.logging.provider.LoggingException;
  
  /**
   * A <code>LoggerManager</code> that supports the management of a logging hierarchy.
   * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
   */
  public class LoggingManagerImpl
      implements LoggingManager
  {
      
      LoggingManagerImpl()
      {
      }
      
      /**
       * Add a set of category entries using the supplied categories descriptor.
       * @param descriptor a set of category descriptors to be added under the path
       */
      public void addCategories( CategoriesDirective descriptor )
      {
      }
  
      /**
       * Add a set of category entries relative to the supplied base category
       * path, using the supplied descriptor as the definition of subcategories.
       * @param path the category base path
       * @param descriptor a set of category descriptors to be added under
       *   the base path
       */
      public void addCategories( String path, CategoriesDirective descriptor )
      {
      }
  
      /**
       * Return the Logger for the specified category.
       * @param category the category path
       * @return the logging channel
       */
      public Logger getLoggerForCategory( final String category )
      {
          org.apache.log4j.Logger log4j = 
              org.apache.log4j.Logger.getLogger( category );
          return new Log4JLogger( log4j );
      }
  }
   
  
  
  
  1.1                  avalon/logging/log4j/test/maven.xml
  
  Index: maven.xml
  ===================================================================
  <project default="test:test">
  </project>
  
  
  
  1.1                  avalon/logging/log4j/test/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-log4j-test</id>
    <name>Avalon Log4J Logging Test</name>
    <package>org.apache.avalon.logging.log4j.test</package>
    <currentVersion>1.0-SNAPSHOT</currentVersion>
  
    <inceptionYear>2002</inceptionYear>
    <shortDescription>Avalon Log4J Logging Implementation.</shortDescription>
  
    <dependencies>
      <dependency>
        <groupId>avalon-repository</groupId>
        <artifactId>avalon-repository-main</artifactId>
        <version>2.0-SNAPSHOT</version>
      </dependency>
      <dependency>
        <groupId>avalon-framework</groupId>
        <artifactId>avalon-framework-api</artifactId>
        <version>4.1.5</version>
      </dependency>
      <dependency>
        <groupId>avalon-logging</groupId>
        <artifactId>avalon-logging-api</artifactId>
        <version>1.0-SNAPSHOT</version>
      </dependency>
    </dependencies>
  </project>
  
  
  

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