logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Womack <mwom...@bevocal.com>
Subject RE: Sample usage of NDC in servlets.
Date Wed, 02 Jan 2002 16:43:57 GMT
Pushing the session id is a pretty good use of the NDC in servlets, and this
is a good example code.  But be aware that you will need to call the
NDC.remove() method periodically, otherwise you will end up with a huge
memory leak over time.  Do not ignore the notes in the api documentation.
It has my experience that a new NDC reference was created for EACH request
object, which is stored statically in the NDC.  This caused the request
object to not be released at the end of the request, and any attributes it
happened to reference were not released as well.  It doesn't take much to
see this is a problem.

Using the new MDC class might be a better way to go.  Or updating the NDC
code to use the same mechanism as the MDC class to free memory when a thread
is no longer being used.

just be aware,
-Mark

-----Original Message-----
From: Regele, Manfred [mailto:Manfred.Regele@Adig.de]
Sent: Wednesday, January 02, 2002 2:34 AM
To: 'Log4J Users List'
Subject: AW: Sample usage of NDC in servlets.


Hi,

you could use something like this:


      session = request.getSession();	
      if( session != null ) _log.push( "S" + session.getId() );
.....

      }finally{
          if( session != null) _log.pop();
      }//finally

Manfred Regele 
Dipl. Betriebswirt (BA)
ADIG Investment GmbH
22 Methoden&Tools
Richard-Reitzner-Allee 2
85540 Haar
Tel: 089/46268-308
mailto:Manfred.Regele@Adig.de
http://www.adig.de

> -----Urspr√ľngliche Nachricht-----
> Von:	Thomas Tuft Muller [SMTP:ttm@online.no]
> Gesendet am:	Freitag, 28. Dezember 2001 10:32
> An:	Log4J Users List
> Betreff:	SV: Sample usage of NDC in servlets.
> 
> Krishna,
> 
> You can use session-ID or username (if applicable) in conjunction with NDC
> in order to separate log-entries from different sessions.
> 
> --
> 
> Thomas
> 
> 
> | -----Opprinnelig melding-----
> | Fra: Krishna srinivasan [mailto:jaguaarrr@yahoo.co.uk]
> | Sendt: 28. desember 2001 09:36
> | Til: Log4J Users List
> | Emne: Sample usage of NDC in servlets.
> |
> |
> | Hi,
> | I'm new to Log4J and just read about usage of NDC.
> | Is there any sample usage of NDC in servlets ?
> | Please share any samples on NDC that you come across.
> |
> | Thanks,
> | Krishna
> |
> |
> |
> |
> |
> |
> | __________________________________________________
> | Do You Yahoo!?
> | Send your FREE holiday greetings online!
> | http://greetings.yahoo.com
> |
> | --
> | To unsubscribe, e-mail:
> | <mailto:log4j-user-unsubscribe@jakarta.apache.org>
> | For additional commands, e-mail:
> | <mailto:log4j-user-help@jakarta.apache.org>
> |
> |
> 
> 
> --
> To unsubscribe, e-mail:
> <mailto:log4j-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:log4j-user-help@jakarta.apache.org>

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

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


Mime
View raw message