You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2002/08/22 08:11:58 UTC

cvs commit: jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly DefaultLoggerManager.java

mcconnell    2002/08/21 23:11:57

  Modified:    assembly/src/java/org/apache/excalibur/merlin/assembly
                        DefaultLoggerManager.java
  Log:
  checkstyle ok
  
  Revision  Changes    Path
  1.8       +103 -87   jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/DefaultLoggerManager.java
  
  Index: DefaultLoggerManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/merlin/assembly/DefaultLoggerManager.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DefaultLoggerManager.java	14 Aug 2002 03:03:35 -0000	1.7
  +++ DefaultLoggerManager.java	22 Aug 2002 06:11:57 -0000	1.8
  @@ -19,13 +19,6 @@
   import org.apache.avalon.excalibur.i18n.ResourceManager;
   import org.apache.avalon.excalibur.i18n.Resources;
   import org.apache.avalon.excalibur.logger.LoggerManager;
  -import org.apache.avalon.framework.configuration.Configurable;
  -import org.apache.avalon.framework.configuration.Configuration;
  -import org.apache.avalon.framework.configuration.ConfigurationException;
  -import org.apache.avalon.framework.context.Context;
  -import org.apache.avalon.framework.context.ContextException;
  -import org.apache.avalon.framework.context.Contextualizable;
  -import org.apache.avalon.framework.logger.AbstractLogEnabled;
   import org.apache.avalon.framework.logger.AvalonFormatter;
   import org.apache.avalon.framework.logger.LogKitLogger;
   import org.apache.excalibur.merlin.model.TargetDescriptor;
  @@ -46,10 +39,15 @@
       implements LoggerManager
   {
   
  +   /**
  +    * The default logging priority value.
  +    */
       public static final String DEFAULT_PRIORITY = "INFO";
  -    public static final String DEFAULT_TARGET = "default";
   
  -    public static final String HOME_KEY = "app.home";
  +   /**
  +    * The default logging target name.
  +    */
  +    public static final String DEFAULT_TARGET = "default";
   
       private static final Resources REZ =
           ResourceManager.getPackageResources( DefaultLoggerManager.class );
  @@ -204,82 +202,6 @@
           }
       }
   
  -    public Logger addCategory( String path, Category category )
  -    {
  -        return addCategory( path, category.getPriority(), category.getTarget(), true );
  -    }
  -
  -    private Logger addCategory( String path, String priority, String target )
  -    {
  -        return addCategory( path, priority, target, true );
  -    }
  -
  -    private Logger addCategory( String path, String priority, String target, boolean notify )
  -    {
  -        final Logger logger = getHierarchy().getLoggerFor( path );
  -        if( priority != null )
  -        {
  -            final Priority priorityValue = Priority.getPriorityForName( priority );
  -            if( !priorityValue.getName().equals( priority ) )
  -            {
  -               final String message = REZ.getString( "unknown-priority", priority, path );
  -               throw new IllegalArgumentException( message );
  -            }
  -            logger.setPriority( priorityValue );
  -        }
  -
  -        if( target != null )
  -        {
  -            final LogTarget logTarget = (LogTarget) m_targets.get( target );
  -            if( logTarget != null )
  -              logger.setLogTargets( new LogTarget[]{ logTarget } );
  -        }
  -        else
  -        {
  -            logger.setLogTargets( new LogTarget[]{ (LogTarget) m_targets.get( DEFAULT_TARGET ) } );
  -        }
  -
  -        if( notify && getLogger().isInfoEnabled() )
  -        {
  -            final String message =
  -                REZ.getString( "category-create", path, target, logger.getPriority() );
  -            getLogger().info( message );
  -        }
  -
  -        return logger;
  -    }
  -
  -    private void addTarget( TargetDescriptor target ) throws Exception
  -    {
  -         File base = new File( System.getProperty("user.dir") );
  -         final String name = target.getName();
  -         TargetProvider provider = target.getProvider();
  -         if( provider instanceof FileTargetProvider )
  -         {
  -             FileTargetProvider fileProvider = (FileTargetProvider) provider;
  -             String filename = fileProvider.getLocation();
  -             final AvalonFormatter formatter = new AvalonFormatter( DEFAULT_FORMAT );
  -             try
  -             {
  -                 File file = new File( base, filename );
  -                 FileTarget logTarget = new FileTarget( file.getAbsoluteFile(), false, formatter );
  -                 m_targets.put( name, logTarget );
  -             }
  -             catch( final IOException ioe )
  -             {
  -                 final String message =
  -                     REZ.getString( "target.nocreate", name, filename, ioe.getMessage() );
  -                 throw new TypeException( message, ioe );
  -             }
  -         }
  -         else
  -         {
  -            final String error = 
  -              "Unrecognized logging provider: " + provider.getClass().getName();
  -              throw new IllegalArgumentException( error );
  -         }
  -    }
  -
       /**
        * Create a logging channel configured with the supplied category path, 
        * priority and target.
  @@ -287,6 +209,7 @@
        * @param name logging category path
        * @param target the logging target to assign the channel to
        * @param priority the priority level to assign to the channel
  +     * @return the logging channel
        * @throws Exception if an error occurs
        */
       public org.apache.avalon.framework.logger.Logger getLoggerForCategory( 
  @@ -301,6 +224,7 @@
        * category descriptor.
        *
        * @param category defintion of the channel category, priority and target
  +     * @return the logging channel
        * @throws Exception if an error occurs
        */
       public org.apache.avalon.framework.logger.Logger getLoggerForCategory( final Category category )
  @@ -322,6 +246,7 @@
       /**
        * Return the Logger for the specified category.
        * @param category the category path
  +     * @return the logging channel
        */
       public org.apache.avalon.framework.logger.Logger getLoggerForCategory( final String category )
       {
  @@ -336,7 +261,9 @@
               {
                   cat = category.replace('/','.');
                   if( cat.startsWith(".") )
  -                  cat = cat.substring(1);
  +                {
  +                    cat = cat.substring(1);
  +                }
               }
               else
               {
  @@ -349,12 +276,101 @@
       /**
        * Return the default Logger.  This is the same
        * as getting the Logger for the "" category.
  +     * @return the default logging channel
        */
       public org.apache.avalon.framework.logger.Logger getDefaultLogger( )
       {
           if( m_logger == null )
  -          m_logger = getLoggerForCategory("");
  +        {
  +            m_logger = getLoggerForCategory("");
  +        }
           return m_logger;
  +    }
  +
  +   /**
  +    * Add a single category entries relative to the supplied base category 
  +    * path, using the supplied category.
  +    * @param path the category base path
  +    * @param category a category descriptors to be added under the base path
  +    */
  +    private Logger addCategory( String path, Category category )
  +    {
  +        return addCategory( 
  +          path, category.getPriority(), category.getTarget(), true );
  +    }
  +
  +    private Logger addCategory( String path, String priority, String target )
  +    {
  +        return addCategory( path, priority, target, true );
  +    }
  +
  +
  +    private Logger addCategory( String path, String priority, String target, boolean notify )
  +    {
  +        final Logger logger = getHierarchy().getLoggerFor( path );
  +        if( priority != null )
  +        {
  +            final Priority priorityValue = Priority.getPriorityForName( priority );
  +            if( !priorityValue.getName().equals( priority ) )
  +            {
  +               final String message = REZ.getString( "unknown-priority", priority, path );
  +               throw new IllegalArgumentException( message );
  +            }
  +            logger.setPriority( priorityValue );
  +        }
  +
  +        if( target != null )
  +        {
  +            final LogTarget logTarget = (LogTarget) m_targets.get( target );
  +            if( logTarget != null )
  +            {
  +                logger.setLogTargets( new LogTarget[]{ logTarget } );
  +            }
  +        }
  +        else
  +        {
  +            logger.setLogTargets( new LogTarget[]{ (LogTarget) m_targets.get( DEFAULT_TARGET ) } );
  +        }
  +
  +        if( notify && getLogger().isInfoEnabled() )
  +        {
  +            final String message =
  +                REZ.getString( "category-create", path, target, logger.getPriority() );
  +            getLogger().info( message );
  +        }
  +
  +        return logger;
  +    }
  +
  +    private void addTarget( TargetDescriptor target ) throws Exception
  +    {
  +         File base = new File( System.getProperty("user.dir") );
  +         final String name = target.getName();
  +         TargetProvider provider = target.getProvider();
  +         if( provider instanceof FileTargetProvider )
  +         {
  +             FileTargetProvider fileProvider = (FileTargetProvider) provider;
  +             String filename = fileProvider.getLocation();
  +             final AvalonFormatter formatter = new AvalonFormatter( DEFAULT_FORMAT );
  +             try
  +             {
  +                 File file = new File( base, filename );
  +                 FileTarget logTarget = new FileTarget( file.getAbsoluteFile(), false, formatter );
  +                 m_targets.put( name, logTarget );
  +             }
  +             catch( final IOException ioe )
  +             {
  +                 final String message =
  +                     REZ.getString( "target.nocreate", name, filename, ioe.getMessage() );
  +                 throw new TypeException( message, ioe );
  +             }
  +         }
  +         else
  +         {
  +            final String error = 
  +              "Unrecognized logging provider: " + provider.getClass().getName();
  +              throw new IllegalArgumentException( error );
  +         }
       }
   
       /**
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>