You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by le...@apache.org on 2002/08/07 06:05:59 UTC

cvs commit: jakarta-avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger Log4JLoggerManager.java LogKitLoggerManager.java

leif        2002/08/06 21:05:59

  Modified:    logger/src/java/org/apache/avalon/excalibur/logger
                        Log4JLoggerManager.java LogKitLoggerManager.java
  Log:
  Make it possible to specify a logger for use by the manager. (Works the same
    as before when existing constructors are used.)
  Fixed the LogKitLoggerManager so that the prefix is handled correctly when
    specified.
  
  Revision  Changes    Path
  1.2       +28 -13    jakarta-avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/Log4JLoggerManager.java
  
  Index: Log4JLoggerManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/Log4JLoggerManager.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Log4JLoggerManager.java	4 Apr 2002 02:34:14 -0000	1.1
  +++ Log4JLoggerManager.java	7 Aug 2002 04:05:59 -0000	1.2
  @@ -32,14 +32,17 @@
       /** The root logger to configure */
       private String m_prefix;
   
  -    /** The hierarchy private to LogKitManager */
  +    /** The hierarchy private to Log4JManager */
       private Hierarchy m_hierarchy;
   
       /** The default logger used for this system */
       final private Logger m_defaultLogger;
  +    
  +    /** The logger used to log output from the logger manager. */
  +    final private Logger m_logger;
   
       /**
  -     * Creates a new <code>DefaultLogKitManager</code>. It will use a new <code>Hierarchy</code>.
  +     * Creates a new <code>DefaultLog4JManager</code>. It will use a new <code>Hierarchy</code>.
        */
       public Log4JLoggerManager()
       {
  @@ -47,7 +50,7 @@
       }
   
       /**
  -     * Creates a new <code>DefaultLogKitManager</code> with an existing <code>Hierarchy</code>.
  +     * Creates a new <code>DefaultLog4JManager</code> with an existing <code>Hierarchy</code>.
        */
       public Log4JLoggerManager( final Hierarchy hierarchy )
       {
  @@ -55,7 +58,7 @@
       }
   
       /**
  -     * Creates a new <code>DefaultLogKitManager</code> using
  +     * Creates a new <code>DefaultLog4JManager</code> using
        * specified logger name as root logger.
        */
       public Log4JLoggerManager( final String prefix )
  @@ -64,7 +67,7 @@
       }
   
       /**
  -     * Creates a new <code>DefaultLogKitManager</code> with an existing <code>Hierarchy</code> using
  +     * Creates a new <code>DefaultLog4JManager</code> with an existing <code>Hierarchy</code> using
        * specified logger name as root logger.
        */
       public Log4JLoggerManager( final String prefix, final Hierarchy hierarchy )
  @@ -74,20 +77,32 @@
       }
   
       /**
  -     * Creates a new <code>DefaultLogKitManager</code> with an existing <code>Hierarchy</code> using
  +     * Creates a new <code>DefaultLog4JManager</code> with an existing <code>Hierarchy</code> using
        * specified logger name as root logger.
        */
  -    public Log4JLoggerManager( final String prefix, final Hierarchy hierarchy, final Logger defaultLogger )
  +    public Log4JLoggerManager( final String prefix, final Hierarchy hierarchy,
  +        final Logger defaultLogger )
  +    {
  +        this( prefix, hierarchy, defaultLogger, defaultLogger );
  +    }
  +
  +    /**
  +     * Creates a new <code>DefaultLog4JManager</code> with an existing <code>Hierarchy</code> using
  +     * specified logger name as root logger.
  +     */
  +    public Log4JLoggerManager( final String prefix, final Hierarchy hierarchy,
  +        final Logger defaultLogger, final Logger logger )
       {
           m_prefix = prefix;
           m_hierarchy = hierarchy;
           m_defaultLogger = defaultLogger;
  +        m_logger = logger;
       }
   
       /**
        * Retrieves a Logger from a category name. Usually
        * the category name refers to a configuration attribute name.  If
  -     * this LogKitManager does not have the match the default Logger will
  +     * this Log4JManager does not have the match the default Logger will
        * be returned and a warning is issued.
        *
        * @param categoryName  The category name of a configured Logger.
  @@ -99,16 +114,16 @@
   
           if( null != logger )
           {
  -            if( m_defaultLogger.isDebugEnabled() )
  +            if( m_logger.isDebugEnabled() )
               {
  -                m_defaultLogger.debug( "Logger for category " + categoryName + " returned" );
  +                m_logger.debug( "Logger for category " + categoryName + " returned" );
               }
               return logger;
           }
   
  -        if( m_defaultLogger.isDebugEnabled() )
  +        if( m_logger.isDebugEnabled() )
           {
  -            m_defaultLogger.debug( "Logger for category " + categoryName
  +            m_logger.debug( "Logger for category " + categoryName
                                      + " not defined in configuration. New Logger created and returned" );
           }
   
  
  
  
  1.4       +64 -22    jakarta-avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/LogKitLoggerManager.java
  
  Index: LogKitLoggerManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/logger/src/java/org/apache/avalon/excalibur/logger/LogKitLoggerManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LogKitLoggerManager.java	9 Jul 2002 11:18:38 -0000	1.3
  +++ LogKitLoggerManager.java	7 Aug 2002 04:05:59 -0000	1.4
  @@ -48,6 +48,9 @@
   
       /** The default logger used for this system */
       final private Logger m_defaultLogger;
  +    
  +    /** The logger used to log output from the logger manager. */
  +    final private Logger m_logger;
   
       /**
        * Creates a new <code>DefaultLogKitManager</code>. It will use a new <code>Hierarchy</code>.
  @@ -88,11 +91,23 @@
        * Creates a new <code>DefaultLogKitManager</code> with an existing <code>Hierarchy</code> using
        * specified logger name as root logger.
        */
  -    public LogKitLoggerManager( final String prefix, final Hierarchy hierarchy, final Logger defaultLogger )
  +    public LogKitLoggerManager( final String prefix, final Hierarchy hierarchy,
  +        final Logger defaultLogger )
  +    {
  +        this( prefix, hierarchy, defaultLogger, defaultLogger );
  +    }
  +
  +    /**
  +     * Creates a new <code>DefaultLogKitManager</code> with an existing <code>Hierarchy</code> using
  +     * specified logger name as root logger.
  +     */
  +    public LogKitLoggerManager( final String prefix, final Hierarchy hierarchy,
  +        final Logger defaultLogger, final Logger logger )
       {
           m_prefix = prefix;
           m_hierarchy = hierarchy;
           m_defaultLogger = defaultLogger;
  +        m_logger = logger;
       }
   
       /**
  @@ -106,24 +121,26 @@
        */
       public final Logger getLoggerForCategory( final String categoryName )
       {
  -        final Logger logger = (Logger)m_loggers.get( categoryName );
  +        final String fullCategoryName = getFullCategoryName( m_prefix, categoryName );
  +        
  +        final Logger logger = (Logger)m_loggers.get( fullCategoryName );
   
           if( null != logger )
           {
  -            if( m_defaultLogger.isDebugEnabled() )
  +            if( m_logger.isDebugEnabled() )
               {
  -                m_defaultLogger.debug( "Logger for category " + categoryName + " returned" );
  +                m_logger.debug( "Logger for category " + fullCategoryName + " returned" );
               }
               return logger;
           }
   
  -        if( m_defaultLogger.isDebugEnabled() )
  +        if( m_logger.isDebugEnabled() )
           {
  -            m_defaultLogger.debug( "Logger for category " + categoryName
  -                                   + " not defined in configuration. New Logger created and returned" );
  +            m_logger.debug( "Logger for category " + fullCategoryName + " not defined in "
  +                                    + "configuration. New Logger created and returned" );
           }
   
  -        return new LogKitLogger( m_hierarchy.getLoggerFor( categoryName ) );
  +        return new LogKitLogger( m_hierarchy.getLoggerFor( fullCategoryName ) );
       }
   
       public final Logger getDefaultLogger()
  @@ -175,7 +192,7 @@
           final DefaultLogTargetFactoryManager targetFactoryManager = new DefaultLogTargetFactoryManager();
           if( targetFactoryManager instanceof LogEnabled )
           {
  -            targetFactoryManager.enableLogging( m_defaultLogger );
  +            targetFactoryManager.enableLogging( m_logger );
           }
   
           if( targetFactoryManager instanceof Contextualizable )
  @@ -209,7 +226,7 @@
   
           if( targetManager instanceof LogEnabled )
           {
  -            targetManager.enableLogging( m_defaultLogger );
  +            targetManager.enableLogging( m_logger );
           }
   
           if( targetManager instanceof LogTargetFactoryManageable )
  @@ -224,6 +241,39 @@
   
           return targetManager;
       }
  +    
  +    /**
  +     * Generates a full category name given a prefix and category.  Either may be
  +     *  null.
  +     *
  +     * @param prefix Prefix or parent category.
  +     * @param category Child category name.
  +     */
  +    private final String getFullCategoryName( String prefix, String category )
  +    {
  +        if( ( null == prefix ) || ( prefix.length() == 0 )  )
  +        {
  +            if ( category == null )
  +            {
  +                return "";
  +            }
  +            else
  +            {
  +                return category;
  +            }
  +        }
  +        else
  +        {
  +            if( ( null == category ) || ( category.length() == 0 ) )
  +            {
  +                return prefix;
  +            }
  +            else
  +            {
  +                return prefix + org.apache.log.Logger.CATEGORY_SEPARATOR + category;
  +            }
  +        }
  +    }
   
       /**
        * Setup Loggers
  @@ -255,21 +305,13 @@
                   m_hierarchy.setDefaultLogTargets( logTargets );
               }
   
  -            final String fullCategory;
  -            if( null == parentCategory )
  -            {
  -                fullCategory = category;
  -            }
  -            else
  -            {
  -                fullCategory = parentCategory + org.apache.log.Logger.CATEGORY_SEPARATOR + category;
  -            }
  +            final String fullCategory = getFullCategoryName( parentCategory, category );
   
               final org.apache.log.Logger logger = m_hierarchy.getLoggerFor( fullCategory );
               m_loggers.put( fullCategory, new LogKitLogger( logger ) );
  -            if( m_defaultLogger.isDebugEnabled() )
  +            if( m_logger.isDebugEnabled() )
               {
  -                m_defaultLogger.debug( "added logger for category " + fullCategory );
  +                m_logger.debug( "added logger for category " + fullCategory );
               }
               logger.setPriority( Priority.getPriorityForName( loglevel ) );
               logger.setLogTargets( logTargets );
  
  
  

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