Mark, Across threads the value of MDC is unique. But from what is see, the threads are mixed[threads 16,17 and 22] and not as expected.
here is my sample log. I have the following format [datetime] Level [session] Thread className [ 2002-05-05 13:38:48,820 ] DEBUG [csi5d04.cognizant.com-5%3A3cd4e7ba%3Ac6776d6e27a11965] * Thread-16 * com.pvn.newdispute.systemsrv.DbConnection [ 2002-05-05 13:38:48,840 ] INFO [csi5d04.cognizant.com-5%3A3cd4e7ba%3Ac6776d6e27a11965] * Thread-16 * com.pvn.newdispute.caseprocsrv.RelatedCases [ 2002-05-05 13:38:48,840 ] DEBUG [csi5d04.cognizant.com-6%3A3cd4e7bb%3Ac647516e821a214] * Thread-17 * com.pvn.newdispute.systemsrv.DbConnection [ 2002-05-05 13:38:48,840 ] INFO [csi5d04.cognizant.com-6%3A3cd4e7bb%3Ac647516e821a214] * Thread-17 * com.pvn.newdispute.caseprocsrv.RelatedCases [ 2002-05-05 13:38:48,880 ] DEBUG [csi5d04.cognizant.com-5%3A3cd4e7ba%3Ac6776d6e27a11965] * Thread-16 * com.pvn.newdispute.systemsrv.DbConnection [ 2002-05-05 13:38:48,880 ] DEBUG [csi5d04.cognizant.com-5%3A3cd4e7ba%3Ac6776d6e27a11965] * Thread-16 * com.pvn.newdispute.systemsrv.DbConnection [ 2002-05-05 13:38:48,890 ] DEBUG [csi5d04.cognizant.com-6%3A3cd4e7bb%3Ac647516e821a214] * Thread-17 * com.pvn.newdispute.systemsrv.DbConnection [ 2002-05-05 13:38:48,890 ] DEBUG [csi5d04.cognizant.com-6%3A3cd4e7bb%3Ac647516e821a214] * Thread-17 * com.pvn.newdispute.systemsrv.DbConnection [ 2002-05-05 13:38:48,950 ] DEBUG [csi5d04.cognizant.com-7%3A3cd4e7bc%3A3a69112135cbee94] * Thread-22 * com.pvn.newdispute.systemsrv.DbConnection [ 2002-05-05 13:38:48,950 ] DEBUG [csi5d04.cognizant.com-7%3A3cd4e7bc%3A3a69112135cbee94] * Thread-22 * com.pvn.newdispute.systemsrv.DbConnection thanks, Krishna --- Mark Womack <[EMAIL PROTECTED]> wrote: > Krishna, > > What does your output look like? The same NDC/MDC > value is displayed across > threads? I don't see anything obvious. > > -Mark > > > -----Original Message----- > > From: Krishna srinivasan > [mailto:[EMAIL PROTECTED]] > > Sent: Friday, May 03, 2002 9:13 AM > > To: Log4J Users List > > Subject: RE: NDC Usage/ MDC usage > > > > > > Mark, > > I tried using my logger wrapper and my > > sampleServlet.java. > > It does'nt seem to work properly. > > I can see messages getting mixed up. > > I tried it with MDC too. It is the same case. > > > > Here is my code snippet: > > > > ++++++++++++++++ > > logger wrapper: > > > > public static void push(String name,String value) > { > > MDC.put(name, value); > > //NDC.push(message); > > } > > > > public static void pop(String name) { > > MDC.get(name); > > MDC.remove(name); > > } > > +++++++++++++++++++++ > > > > Servlet code: > > HttpSession session = request.getSession(); > > if( session != null ) > > PvnLogger.push("session",session.getId()); > > try{ > > . > > . > > } > > finally{ > > if( session != null ) > > PvnLogger.pop("session"); > > } > > +++++++++++++ > > and log4j.properties file sample: > > > > log4j.rootLogger=debug, logfile > > > > # logfile is set to be a RollingFileAppender. > > > log4j.appender.logfile=org.apache.log4j.RollingFileAppender > > > log4j.appender.logfile.File=F:/IplanetWebServer6/docs/DOTS/WEB > > -INF/classes/dots1.log > > log4j.appender.logfile.MaxFileSize=500KB > > > > # Keep one backup file > > log4j.appender.logfile.MaxBackupIndex=10 > > > log4j.appender.logfile.layout=org.apache.log4j.PatternLayout > > > > log4j.appender.logfile.layout.ConversionPattern=[ > %d ] > > %p %X{session} * %t * %c * %m %n > > > > ++++++++++++++ > > > > Any idea where i'm goign wrong? > > > > thanks, > > Krishna > > > > > > --- Mark Womack <[EMAIL PROTECTED]> wrote: > > > Krishna, > > > > > > It looks to me that you have the basic NDC usage > > > down. However, if you read > > > the documentation for NDC you will find mention > that > > > the NDC.remove() method > > > should be called periodically to remove > references > > > from "dead" threads. > > > Without this I found that there was a > substantial > > > memory leak in our jsp > > > container caused by request objects referenced > by > > > the static NDC data not > > > being released. Our code ended up calling > > > NDC.remove() right after the > > > NDC.pop() call, but this has some inherent > overhead. > > > > > > If you are using log4j 1.2 I would highly > recommend > > > using the MDC class > > > (Mapped Diagnostic Context) instead of the NDC > > > class. It does not suffer > > > from the same static reference problems that NDC > > > does and it is much more > > > flexible as to how/what you can add as context > > > information. > > > > > > -Mark > > > > > > > -----Original Message----- > > > > From: Krishna srinivasan > > > [mailto:[EMAIL PROTECTED]] > > > > Sent: Wednesday, May 01, 2002 11:12 PM > > > > To: Log4J Users List > > > > Subject: NDC Usage > > > > > > > > > > > > Hi all, > > > > i'm trying to use NDC in my servlets. > > > > > > > > I have a logger wrapper[PvnLogger.java] with > > > push() > > > > and pop() methods besides logger methods. The > > > sample > > > > Servlet[sampleServlet.java] makes use of push > and > > > pop. > > > > > > > > > > > > > > > > Attached are the files. I'm not sure if i'm > doing > > > the > > > > correct thing. Any suggestion will help me > > > greatly. > > > > Thanks, > > > > Krishna > > > > > > > > > > > > > > > > > __________________________________________________ > > > > Do You Yahoo!? > > > > Yahoo! Health - your guide to health and > wellness > > > > http://health.yahoo.com > > > > > > > > > > -- > > > To unsubscribe, e-mail: > > > > <mailto:[EMAIL PROTECTED]> > > > For additional commands, e-mail: > > > <mailto:[EMAIL PROTECTED]> > > > > > > > > > __________________________________________________ > > Do You Yahoo!? > > Yahoo! Health - your guide to health and wellness > > http://health.yahoo.com > > > > -- > > To unsubscribe, e-mail: > > <mailto:[EMAIL PROTECTED]> > > For additional commands, e-mail: > > <mailto:[EMAIL PROTECTED]> > > > > -- > To unsubscribe, e-mail: > <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: > <mailto:[EMAIL PROTECTED]> > __________________________________________________ Do You Yahoo!? Yahoo! Health - your guide to health and wellness http://health.yahoo.com -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>