avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From atagu...@apache.org
Subject cvs commit: avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/logkit LogKitConfHelper.java
Date Wed, 11 Jun 2003 13:32:06 GMT
atagunov    2003/06/11 06:32:06

  Modified:    logger/src/java/org/apache/avalon/excalibur/logger/logkit
                        LogKitConfHelper.java
  Log:
  working on providing better message in the exception (with path to source of configuration)
  
  Revision  Changes    Path
  1.3       +67 -67    avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/logkit/LogKitConfHelper.java
  
  Index: LogKitConfHelper.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/logkit/LogKitConfHelper.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- LogKitConfHelper.java	11 Jun 2003 12:07:12 -0000	1.2
  +++ LogKitConfHelper.java	11 Jun 2003 13:32:06 -0000	1.3
  @@ -138,10 +138,9 @@
           final LogTargetManager targetManager = setupTargetManager( targets, targetFactoryManager
);
   
           final Configuration categories = configuration.getChild( "categories" );
  -        final Configuration[] category = categories.getChildren( "category" );
           setupLoggers( targetManager,
                         null,
  -                      category,
  +                      categories,
                         true,
                         categories.getAttributeAsBoolean( "additive", false ) );
       }
  @@ -207,90 +206,91 @@
        */
       private final void setupLoggers( final LogTargetManager targetManager,
                                        final String parentCategory,
  -                                     final Configuration[] categories,
  +                                     final Configuration parentElement,
                                        boolean root,
                                        final boolean defaultAdditive )
           throws ConfigurationException
       {
           boolean rootLoggerConfigured = false;
   
  -        for( int i = 0; i < categories.length; i++ )
  +        final Configuration[] categories = parentElement.getChildren( "category" );
  +
  +        if( null != categories )
           {
  -            final Configuration category = categories[ i ];
  -            final String name = category.getAttribute( "name" );
  -            final String loglevel = category.getAttribute( "log-level" ).toUpperCase();
  -            final boolean additive = category.
  -                getAttributeAsBoolean( "additive", defaultAdditive );
  -
  -            final Configuration[] targets = category.getChildren( "log-target" );
  -            final LogTarget[] logTargets = new LogTarget[ targets.length ];
  -            for( int j = 0; j < targets.length; j++ )
  +            for( int i = 0; i < categories.length; i++ )
               {
  -                final String id = targets[ j ].getAttribute( "id-ref" );
  -                logTargets[ j ] = targetManager.getLogTarget( id );
  -                if( !m_targets.contains( logTargets[ j ] ) )
  +                final Configuration category = categories[ i ];
  +                final String name = category.getAttribute( "name" );
  +                final String loglevel = category.getAttribute( "log-level" ).toUpperCase();
  +                final boolean additive = category.
  +                    getAttributeAsBoolean( "additive", defaultAdditive );
  +        
  +                final Configuration[] targets = category.getChildren( "log-target" );
  +                final LogTarget[] logTargets = new LogTarget[ targets.length ];
  +                for( int j = 0; j < targets.length; j++ )
                   {
  -                    m_targets.add( logTargets[ j ] );
  +                    final String id = targets[ j ].getAttribute( "id-ref" );
  +                    logTargets[ j ] = targetManager.getLogTarget( id );
  +                    if( !m_targets.contains( logTargets[ j ] ) )
  +                    {
  +                        m_targets.add( logTargets[ j ] );
  +                    }
                   }
  -            }
  -
  -            final String fullCategory;
  -            final org.apache.log.Logger logger;
  -
  -            if ( "".equals( name ) )
  -            {
  -                if ( !root )
  +        
  +                final String fullCategory;
  +                final org.apache.log.Logger logger;
  +        
  +                if ( "".equals( name ) )
                   {
  -                    final String message = "'category' element with empty name not " +
  -                            "at the root level: " + category.getLocation();
  -                    throw new ConfigurationException( message );
  +                    if ( !root )
  +                    {
  +                        final String message = "'category' element with empty name not
" +
  +                                "at the root level: " + category.getLocation();
  +                        throw new ConfigurationException( message );
  +                    }
  +        
  +                    if ( logTargets.length == 0 )
  +                    {
  +                        final String message = "At least one log-target should be " +
  +                                "specified for the root category " + category.getLocation();
  +                        throw new ConfigurationException( message );
  +                    }
  +        
  +                    fullCategory = null;
  +                    logger = m_hierarchy.getRootLogger();
  +                    rootLoggerConfigured = true;
                   }
  -
  -                if ( logTargets.length == 0 )
  +                else
                   {
  -                    final String message = "At least one log-target should be " +
  -                            "specified for the root category " + category.getLocation();
  -                    throw new ConfigurationException( message );
  +                    fullCategory = LoggerUtil.getFullCategoryName( parentCategory, name
);
  +                    logger = m_hierarchy.getLoggerFor( fullCategory );
                   }
  -
  -                fullCategory = null;
  -                logger = m_hierarchy.getRootLogger();
  -                rootLoggerConfigured = true;
  -            }
  -            else
  -            {
  -                fullCategory = LoggerUtil.getFullCategoryName( parentCategory, name );
  -                logger = m_hierarchy.getLoggerFor( fullCategory );
  -            }
  -
  -            if( getLogger().isDebugEnabled() )
  -            {
  -                /**
  -                 * We have to identify ourselves now via 'LogKitConfHelper:'
  -                 * because we are likely to be logging to a shared bootstrap
  -                 * logger, not to a dedicated category Logger.
  -                 */
  -                final String message = "LogKitConfHelper: adding logger for category '"
+
  -                        ( fullCategory != null ? fullCategory : "" ) + "'";
  -                getLogger().debug( message );
  -            }
  -
  -            logger.setPriority( Priority.getPriorityForName( loglevel ) );
  -            logger.setLogTargets( logTargets );
  -            logger.setAdditivity( additive );
  -
  -            final Configuration[] subCategories = category.getChildren( "category" );
  -            if( null != subCategories )
  -            {
  -                setupLoggers( targetManager, fullCategory, subCategories, false, defaultAdditive
);
  +        
  +                if( getLogger().isDebugEnabled() )
  +                {
  +                    /**
  +                     * We have to identify ourselves now via 'LogKitConfHelper:'
  +                     * because we are likely to be logging to a shared bootstrap
  +                     * logger, not to a dedicated category Logger.
  +                     */
  +                    final String message = "LogKitConfHelper: adding logger for category
'" +
  +                            ( fullCategory != null ? fullCategory : "" ) + "'";
  +                    getLogger().debug( message );
  +                }
  +        
  +                logger.setPriority( Priority.getPriorityForName( loglevel ) );
  +                logger.setLogTargets( logTargets );
  +                logger.setAdditivity( additive );
  +        
  +                setupLoggers( targetManager, fullCategory, category, false, defaultAdditive
);
               }
           }
   
           if ( root && !rootLoggerConfigured )
           {
               final String message = 
  -                    "No configuration for root category (<category name=''/>) found.";
  -
  +                    "No configuration for root category (<category name=''/>) found
in "+
  +                            parentElement.getLocation();
               throw new ConfigurationException( message );
           }
       }
  
  
  

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


Mime
View raw message