logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Curt Arnold <carn...@apache.org>
Subject Re: Logging NDC value
Date Wed, 16 Jul 2008 15:57:37 GMT

On Jul 16, 2008, at 8:29 AM, Duseja, Sushil wrote:

> Hello,
>
> I used event.getNDC() to log the NDC value (where event is a
> org.apache.log4j.spi.LoggingEvent object), but it's fetching - 'null'.
> Similarly, I used event.getThrowableStrRep() to log the exception  
> value
> but that is again fetching a null.

event.getNDC() would be expected to be null if no NDC value had been  
set for the thread.  event.getThrowableStrRep() would be expected to  
be null if you did not call one of the logging methods that took an  
exception as the second argument.  Since we don't have access to your  
test app and you haven't described it, there is nothing to indicate  
that anything is wrong.

If you want to set the NDC value, do something like:

NDC.push("Context 1");
logger.debug("Hello, World");
NDC.pop();

If you want to a logging request to include an exception:

try {
...
} catch(Exception e) {
	logger.warn("Unable to complete action", e);
}

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


Mime
View raw message