(Mainly to Peter)
I am having a problem with logger Categories using the ECM. Not sure
exactly when this started happening, but I just noticed it.

If I specify an attribute, logger="something", for a component in my
components.xml file then the logger assigned to that component is
"something.something" rather than just "something".

It appears that this only happens in cases where Selectors are used.
To make the ECM work with both Loggable as well as LogEnabled components,
a compatability layer was added to make thigs work cleanly. The ECM
internally creates and instance of a LogkitLoggerManager from the component
package. (Note this is not LogKitLoggerManager from the logger package)
This class appears to be acting as a proxy so that all requests for
either type
of logger are handled correctly.

The problem arrises as soon as LogkitLoggerManager.getLogKitManager() is
called.
This creates an instance of a Logger2LogKitManager class which is then
stored
in the m_logKitManager field of the LogkitLoggerManager class. All
future calls
to LogkitLoggerManager.getLogKitLoggerForCategory() now make use of that
object to get the LogKit loggers.

Ok. Internally, when Logger2LogKitManager.getLogger() is called (See
modified code below):
---
public org.apache.log.Logger getLogger( final String categoryName )
{
final Logger logger =
m_loggerManager.getLoggerForCategory( categoryName );
logger.info( "Logger2LogKitManager.getLogger( " + categoryName + " )
logger" );
final org.apache.log.Logger logkitLogger =
getHierarchy().getLoggerFor( categoryName );
logkitLogger.info( "Logger2LogKitManager.getLogger( " + categoryName + "
) logkitLogger 1" );
final LogKit2LoggerTarget target =
new LogKit2LoggerTarget( logger );
logkitLogger.setLogTargets( new LogTarget[ ] { target } );
logkitLogger.info( "Logger2LogKitManager.getLogger( " + categoryName + "
) logkitLogger 2" );
return logkitLogger;
}
---
You will get the following output:
---
09-12T14:24:28.519 INFO [something ]: Logger2LogKitManager.getLogger(
something ) logger
09-12T14:24:28.669 INFO [something ]: Logger2LogKitManager.getLogger(
something ) logkitLogger 1
09-12T14:24:28.749 INFO [something.something]:
Logger2LogKitManager.getLogger( something ) logkitLogger 2
---

Notice how logging to the logKitLogger works correctly until
setLogTargets() is called.

Looking at the source of the LogKit2LoggerTarget in the
getLoggerForEvent method, you
see the following code, once again with debug output added. Also added
'+ "LTK"' to the
generated category names to make it clearer what was happening.:
---
private Logger getLoggerForEvent( final LogEvent event )
{
final String category = event.getCategory();
Logger logger = m_logger;
logger.info( "LogKit2LoggerTarget.getLoggerForEvent(event) category='" +
category + "' 1" );
if( !"".equals( category ) )
{
logger = m_logger.getChildLogger( category + "LKT" );
}
logger.info( "LogKit2LoggerTarget.getLoggerForEvent(event) category='" +
category + "' 2" );
return logger;
}
---
Then someplaces, I would get this:
---
09-12T15:00:32.060 INFO [ ]:
LogKit2LoggerTarget.getLoggerForEvent(event) category='something' 1
09-12T15:00:32.120 INFO [somethingLKT]:
LogKit2LoggerTarget.getLoggerForEvent(event) category='something' 2
09-12T15:00:32.140 DEBUG [somethingLKT]: Message
---
But in others, I would get:
---
09-12T15:00:32.340 INFO [something ]:
LogKit2LoggerTarget.getLoggerForEvent(event) category='something' 1
09-12T15:00:32.350 INFO [something.somethingLKT]:
LogKit2LoggerTarget.getLoggerForEvent(event) category='something' 2
09-12T15:00:32.530 INFO [something.somethingLKT]: Message
---
So it does not appear to be possible to do much in this method.

Looking back at the Logger2LogKitManager.getLogger( categoryName ) method,
It looked like the following change would work. The actual category that
we want to
log to is provided in the LogEvent as seen above. So it seems like we
always want
to be getting a logger relative to the root.

This led me to make the following extremely simple fix:
---
RCS file:
/home/cvs/jakarta-avalon-excalibur/component/src/java/org/apache/avalon/excalibur/component/Logger2LogKitManager.java,v
retrieving revision 1.3
diff -u -r1.3 Logger2LogKitManager.java
--- Logger2LogKitManager.java 29 Jul 2002 09:53:40 -0000 1.3
+++ Logger2LogKitManager.java 12 Sep 2002 06:31:29 -0000
@@ -36,7 +36,7 @@
public org.apache.log.Logger getLogger( final String categoryName )
{
final Logger logger =
- m_loggerManager.getLoggerForCategory( categoryName );
+ m_loggerManager.getLoggerForCategory( "" );
final org.apache.log.Logger logkitLogger =
getHierarchy().getLoggerFor( categoryName );
final LogKit2LoggerTarget target =
---

This seems to work great for me, but I wanted to check with the author
(Peter?)
to make sure that this will also work with other Logger implementations.
I am
using the LogKitLoggerManager.
It this looks Ok, then I will go ahead and commit it.

Figures ... ~4 hours for a 1 line fix :-/

Cheers,
Leif


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to