One idea - at runtime as contexts are defined, instantiate loggers and stuff
them in the MDC but name the loggers by context.  Then when a logging call
is made, you'd have to wrap Log4j and in your wrapper make a logging call to
each of the loggers stored in MDC (thread storage) in addition to the normal
Logger instance.

Please let me know what you think of this, we were considering using this
approach on a current project.

Mike

-----Original Message-----
From: Scott Heaberlin [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 23, 2004 5:26 PM
To: Log4j
Subject: Contextual Logging - A downside?


Hello log4j users,

I have a question about context-based log filtering (ie, NDC, MDC). 
To achieve log event 'separation', filters are attached to appenders. 
Suppose the following:

Application MyApp has three distinct modules, A,B, and C.  At the
entry points to A,B, and C, the application pushes the module name
"A", "B", "C" into logging context (we'll use NDC here for this
example).

Lets say modules A,B, and C reuse a large amount of java classes. 
Contextual logging is a god-send because we can achieve a high level
of code reuse and still separate or "squelch"  log events based on the
context from which logged (via something like a LevelMatchFilter
combined with a NDCMatchFilter).

Now, instead of setting the logging level on the Logger level in my
log4j configuration, I must set it at the appender level (via
threshold or LevelMatchFilter).  To allow the events to pass to the
filters to decide(), I must set the logger's level lower than or equal
to that which my filters will be allowing, otherwise the events will
never be passed to the appender.

I am now effectively bypassing the object-generation benefit of the
following:

if (log.isDebugEnabled() {
    log.debug("I " + "like " + "to " + "create " + "String " + "instances");
}

Does anyone see any way around this? 

It seems to me that Logger hierarchy if you can use it is still a more
optimal way of separating log events (eg, define separate or even
dynamic but still dot-based logger names and using that to set logging
level as opposed to contextual filtering)...


Thanks in advance for all your comments,
-- 


-Scott


Scott Heaberlin

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

-------------------------------------------------------------------------------
This message and any included attachments are from Siemens Medical Solutions 
USA, Inc. and are intended only for the addressee(s).  
The information contained herein may include trade secrets or privileged or 
otherwise confidential information.  Unauthorized review, forwarding, printing, 
copying, distributing, or using such information is strictly prohibited and may 
be unlawful.  If you received this message in error, or have reason to believe 
you are not authorized to receive it, please promptly delete this message and 
notify the sender by e-mail with a copy to [EMAIL PROTECTED] 

Thank you

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

Reply via email to