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 Joe Pennio <jp...@imcva.com> on 2002/07/18 18:04:20 UTC

Using Nested Diagnostics Context (NDC)

What is the proper way to use the NDC class.

We are using the logger class in our web based application. The web
application is based on the MVC architecture where there are many event
handlers to handle each request received by the server.

In order to log the appropriate session id associated with the request
the choices were either concatenate it to the message or use the NDC and
take advantage of its "log file" formatting capability.  For our use I
am going with NDC.

I started to implement it using the NDC (code snippet) as follows:

String sid = session.getId();
NDC.push(sid);

String msg = "msg description"; 
if ( logger.isDebugEnabled() )
  logger.debug("process -> msg= " + msg);

NDC.remove();

I understand that the NDC should be on a per thread basis but we are not
creating any specialized threads.

1. Where should the NDC.remove() be placed OR is the
NDC.remove()necessary OR should the NDC.pop() OR NDC.clear be used
instead?

2. Is there a performance hit using the NDC in this manner greater than
just concatenating the id to the log message?

Any feedback in this area will be welcomed ...

Joe
____________________________________ 
Joe Pennio,  Sr. Software Engineer 
Innovative Management Concepts, Inc. 
voice:  (434) 220-4658
fax:     (434) 220-4663 
email:   jpennio@imcva.com 
web:     http://www.imcva.com 



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>