(sigh)
This actually isn't working because I am unable to control log levels
from the
logkit.xml file. The log message displays to the screen as the "something"
category, but the LogKit manager is controlling the category as if it was
the "" category.

I tried switching things around like this:
---
public org.apache.log.Logger getLogger( final String categoryName )
{
final Logger logger =
m_loggerManager.getLoggerForCategory( categoryName );
final org.apache.log.Logger logkitLogger =
getHierarchy().getLoggerFor( "" );
final LogKit2LoggerTarget target =
new LogKit2LoggerTarget( logger );
logkitLogger.setLogTargets( new LogTarget[ ] { target } );
return logkitLogger;
}
---
But this does not work because the Logger assigned to logkitLogger is always
the same instance. This means that the log target is always set to the last
category called.

After playing with this some more, I ended up backing out the change in the
original message and then changing LogKit2LoggerTarget as follows:
---
RCS file:
/home/cvs/jakarta-avalon-excalibur/component/src/java/org/apache/avalon/excalibur/component/LogKit2LoggerTarget.java,v
retrieving revision 1.2
diff -u -r1.2 LogKit2LoggerTarget.java
--- LogKit2LoggerTarget.java 2 Jun 2002 06:03:01 -0000 1.2
+++ LogKit2LoggerTarget.java 12 Sep 2002 08:54:53 -0000
@@ -46,7 +46,7 @@

public void processEvent( LogEvent event )
{
- final Logger logger = getLoggerForEvent( event );
+ final Logger logger = m_logger;

final String message = event.getMessage();
final Throwable throwable = event.getThrowable();
@@ -71,23 +71,5 @@
{
logger.fatalError( message, throwable );
}
- }
-
- /**
- * Retrieve Logger for event. If event is from a child
- * Log
- *
- * @param event the LogEvent
- * @return the Logger
- */
- private Logger getLoggerForEvent( final LogEvent event )
...
---
In summary, the target class was just simplified down so that the
m_logger is
always used. This made it possible to get rid of the getLoggerForEvent
method
completely.

So far this method has been passing all of my tests... So far..

Looking at the LogKit2LoggerTarget.createLogger method, I question
whether it
will work. It is doing exactly what I tried above. That didn't seem to work.

Moving on, I also saw some ways to simplfy and optimize the code in
LogkitLoggerManager. The above changes do not depend on these. They would
be in addition. I was noticing that once getLogKitManager() was called,
future
calls to getLoggerForCategory were being done using the Logger2LogKitManager
wrapper even though the original LoggerManager was available. I also made
getLogKitManager always be called when a getLogKitLoggerForCategory is
called
to remove some duplicate code. This also got rid of one call to
LogKit2LoggerTarget.createLogger (It is still being used by
AbstractDualLogEnabled
however)
---
RCS file:
/home/cvs/jakarta-avalon-excalibur/component/src/java/org/apache/avalon/excalibur/component/LogkitLoggerManager.java,v
retrieving revision 1.3
diff -u -r1.3 LogkitLoggerManager.java
--- LogkitLoggerManager.java 29 Jul 2002 09:53:40 -0000 1.3
+++ LogkitLoggerManager.java 12 Sep 2002 15:37:22 -0000
@@ -31,32 +31,20 @@
m_logKitManager = logKitManager;
}

- public org.apache.log.Logger
- getLogKitLoggerForCategory( final String categoryName )
+ public org.apache.log.Logger getLogKitLoggerForCategory( final String
categoryName )
{
- if( null != m_logKitManager )
- {
- return m_logKitManager.getLogger( categoryName );
- }
- else
- {
- final Logger logger =
- m_loggerManager.getLoggerForCategory( categoryName );
- return LogKit2LoggerTarget.createLogger( logger );
- }
+ return getLogKitManager().getLogger( categoryName );
}

public Logger getLoggerForCategory( String categoryName )
{
- if( null != m_logKitManager )
+ if( null != m_loggerManager )
{
- final org.apache.log.Logger logger =
- m_logKitManager.getLogger( categoryName );
- return new LogKitLogger( logger );
+ return m_loggerManager.getLoggerForCategory( categoryName );
}
else
{
- return m_loggerManager.getLoggerForCategory( categoryName );
+ return new LogKitLogger( getLogKitLoggerForCategory( categoryName ) );
}
---

These changes seem to all be working, so I'll go ahead and commit them.
Let me know
if you see any problems.

Cheers,
Leif

Leif Mortenson wrote:

>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]>
>
>
>  
>



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

Reply via email to