logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Vincent.Bourdar...@nokia.com>
Subject High performance NDC filtering
Date Wed, 19 Jul 2006 16:13:16 GMT
Hi all,

Considering the following code snippet

// the following method is called-back hundred of time per second.
public void process(Request request, Response response)
    NDC.push("source-ip=" + request.getSourceAddress());
    NDC.push("user-id=" + request.getUser().getId());
    // ... set all needed NDC information
    if (log.isDebugEnabled())
        // Create a debug message for troubleshooting
        // (request dump e.g.), this is CPU-intensive
        String msg = buildDebugMessage(request);
    // process request and send response ...
    // ... pop all pushed data

I'm looking for a way to log debug message only when debug mode is
enabled AND the context matches some runtime-configurable criteria(s).
The idea there is to debug only some specific (problematic) context(s)
so that it is possible to enable debug in live servers without huge
performance impact.

I know NDC and Filters are meant to do than. But if Filters
(log4j_sandbox's NDCMatchFilter e.g.) save log4j from sending a
LoggingEvent to the Appenders (saving layout and write actions), they
does not save the time spent in buildDebugMessage() which could imply
huge performance penalty.

I've not find any way to perform filtering behing log.isDebugEnabled()
calls. Is that feasible in log4j 1.2 or 1.3? If not, do you believe it
would make sense to add this kind of feature in a future release
regarding log4j goals and design?

Thanks a lot for your help and your time,
Vincent Bourdaraud.

View raw message