avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit LoggerParameter.java
Date Mon, 26 Jan 2004 17:35:27 GMT
mcconnell    2004/01/26 09:35:27

  Added:       merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit
                        LoggerParameter.java
  Log:
  Parameter class to construct a logger from a string containing a priority label such as
"debug", "error", info", etc.
  
  Revision  Changes    Path
  1.1                  avalon/merlin/logging/logkit/impl/src/java/org/apache/avalon/logging/logkit/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.logkit;
  
  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:mcconnell@apache.org">Stephen McConnell</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 initial 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 );
      }
  
  }
  
  
  

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


Mime
View raw message