You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Scott Heaberlin <he...@gmail.com> on 2004/09/23 23:25:40 UTC

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: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org