logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Smith <paul.sm...@lawlex.com.au>
Subject Re: Chaining
Date Wed, 01 Oct 2003 21:58:59 GMT
This is where the NDC would be useful.

In Class 2:

NDC.push("Class 2");

In Class 1:

NDC.push("Class 1");

Then when you are ready to log a message:


The NDC entries will be available via the LoggingEvent that is send to
the appender, so if you configure an appender to actually output the
contents of the NDC, you'll be able to see it. (see things like
PatternLayout on how to explicitly request NDC to be output in the
appender).  NDC acts as a Stack for each Thread of execution, so it
retains the order of push/pop.

Don't forget to NDC.pop() at the end of each method where you


Paul Smith

On Thu, 2003-10-02 at 01:10, David Liles wrote:
> I just started using log4j and am having trouble trying to figure out how to chain logging
> class 1 makes a call to class 2.... I would like to be able to pass the message from
class 2 to class 1 where it would ultimately be logged, that way when I review the log file
it would show that the message originated in class 2, but would be displayed something like
> class2 -> class1 - message.....
> Hope I'm making sense....
> Thanks - Dave

To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org

View raw message