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 David Liles <da...@dynamichostings.com> on 2003/10/01 17:10:18 UTC

Chaining

I just started using log4j and am having trouble trying to figure out how to chain logging messages....
 
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 this:
 
class2 -> class1 - message.....
 
Hope I'm making sense....
 
Thanks - Dave

Re: Chaining

Posted by Paul Smith <pa...@lawlex.com.au>.
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:

log.debug("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
NDC.push(...)..

cheers,

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 messages....
>  
> 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 this:
>  
> 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