avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Leif Mortenson <l...@tanukisoftware.com>
Subject Question + Patch about use of LogKitLoggerManager with a log prefix
Date Tue, 06 Aug 2002 03:04:35 GMT
While looking into logging issues with fortress, I came across what I 
think is a problem in
LogKitLoggerManager.

If I create a LogKitLoggerManager specifying a prefix of "fortress" (As 
is done in fortress)
the categories specified in the configuration file for the LoggerManager 
will not be mapped
to Loggers obtained by getLoggerForCategory.

The problem is that if I specify a category in the conf file called 
"inst", it will be remapped
to a category called "fortress.inst" in the setupLoggers method.  That 
seems correct.

The problem is that when I call getLoggerForCategory( "inst" ), I am 
given a logger named
"inst"  I should be given a logger named "fortress.inst".  Shouldn't I?

I came up with a patch to fix this.  However, as this has the potential 
to affect a lot of people,
I wanted to make sure that those who designed this class agree with the 
patch before I apply
it.

I also made a change so that if a category "" is specified, the 
resulting logger will be named
"fortress" rather than "fortress."

Specifying a prefix seems to lead to some pretty long names.  But if 
this is what was intended
then that is fine.

Examples:
prefix=null, category=null => ""
prefix=null, category="" => ""
prefix="", category="" => ""
prefix=null, category="logkit" => "logkit"
prefix=null, category="inst" => "inst"
prefix="fortress", category=null => "fortress"
prefix="fortress", category="" => "fortress"
prefix="fortress", category="logkit" => "fortress.logkit"
prefix="fortress", category="inst" => "fortress.inst"

Cheers,
Leif

Patch: ( I also attached the new file to make it easier to try out.)
diff -r1.3 LogKitLoggerManager.java
109c109,111
<         final Logger logger = (Logger)m_loggers.get( categoryName );
---
 >         final String fullCategoryName = getFullCategoryName( 
m_prefix, categoryName );
 >        
 >         final Logger logger = (Logger)m_loggers.get( fullCategoryName );
115c117
<                 m_defaultLogger.debug( "Logger for category " + 
categoryName + " returned" );
---
 >                 m_defaultLogger.debug( "Logger for category " + 
fullCategoryName + " returned" );
122,123c124,125
<             m_defaultLogger.debug( "Logger for category " + categoryName
<                                    + " not defined in configuration. 
New Logger created and returned" );
---
 >             m_defaultLogger.debug( "Logger for category " + 
fullCategoryName + " not defined in "
 >                                     + "configuration. New Logger 
created and returned" );
126c128
<         return new LogKitLogger( m_hierarchy.getLoggerFor( 
categoryName ) );
---
 >         return new LogKitLogger( m_hierarchy.getLoggerFor( 
fullCategoryName ) );
226a229,261
 >    
 >     /**
 >      * 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;
 >             }
 >         }
 >     }
258,266c293
<             final String fullCategory;
<             if( null == parentCategory )
<             {
<                 fullCategory = category;
<             }
<             else
<             {
<                 fullCategory = parentCategory + 
org.apache.log.Logger.CATEGORY_SEPARATOR + category;
<             }
---
 >             final String fullCategory = getFullCategoryName( 
parentCategory, category );



Mime
View raw message