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 Sandeep <sa...@bma.gov.bh> on 2003/10/09 12:27:01 UTC

Nested Diagnostic Context


Hi All ,

DO any one have example or document using NDC (Nested Diagnostic Context)
for webapplication as in jsp.

TIA 



Note
************************************************************************

This email including any attachments is intended solely for the use of named
recipient only.If you are not that person, you are not authorized to
read,copy,forward,disclose,take any action on information.Any other use of
this email and attachments is prohibited.The views expressed in this email
are not necessarily those of BMA.If you received this email by mistake,
please destroy all copies and contact  to the sender by email.your
cooperation is appreciated.

****************************************************************************
*********



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


Re: Nested Diagnostic Context

Posted by Adam Vainder <ad...@lexi.com>.
Whoops, the Logger declaration section was a copy+paste. You can do it 
either way, I usually prefer the getRootLogger. 

-----Original Message-----
From: "Adam Vainder" <ad...@lexi.com>
To: "Log4J Users List" <lo...@jakarta.apache.org>
Date: Thu, 09 Oct 2003 10:38:25 -0400
Subject: Re: Nested Diagnostic Context

> Hey,
> 
> Brief example.
> 
> jsp : 
> 
> <%@ page language="java" contentType="text/html" %>
> <%@ page import="org.apache.log4j.*" %>
> 
> <%--
> ------------------------------------------------------------------%>
> <%-- Page initialization                                            
> --%>
> <%--
> ------------------------------------------------------------------%>
> <%!//make logger private static 
> 	//private static Logger log = Logger.getRootLogger();
> 	private static Logger log = Logger.getLogger("com.foo");
> %>
> 
> <%
>         String userHost=request.getRemoteHost();
> 	String userIp=request.getRemoteAddr();
> 	NDC.clear();
> 	NDC.push(userHost);
> 	NDC.push(userIp);
> %>
> 
> <html>
>     <head>
> 	<title>LOG EXAMPLE</title>
> 
>     </head>
>     <body>
> <%
>     log.info("THIS IS A TEST");
> %>
>     <!--whatever else you want to do-->
>     </body>
> <%
>       NDC.remove(); //clear things up if not forwarding to another
> page, 
> otherwise omit this until the last page(s) the person can reach, 
> including error pages, etc.
> %>
> </html>
> 
> 
> Properties file :
> 
> log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
> log4j.appender.A1.file=/opt/tomcat/webapps/foo.log
> log4j.appender.A1.MaxFileSize=100KB
> log4j.appender.A1.MaxBackupIndex=1
> log4j.appender.A1.layout=org.apache.log4j.PatternLayout
> log4j.appender.A1.layout.ConversionPattern==%d{MM-dd-yyyy HH:mm:ss}
> %-5p 
> %c %x - %m%n
> 
> 
> Should give something along the format :
>   <date and time> INFO <jsp-filename> <hostname ip-address (e.g. NDC 
> info)> - THIS IS A TEST
> 
> the %x in the ConversionPattern is what outputs the NDC.
> 
> Does that help enough?
> 
> Adam Vainder
> 
> -----Original Message-----
> From: Sandeep <sa...@bma.gov.bh>
> To: 'Log4J Users List' <lo...@jakarta.apache.org>
> Date: Thu, 9 Oct 2003 13:27:01 +0300 
> Subject: Nested Diagnostic Context
> 
> > 
> > 
> > Hi All ,
> > 
> > DO any one have example or document using NDC (Nested Diagnostic
> > Context)
> > for webapplication as in jsp.
> > 
> > TIA 
> > 
> > 
> > 
> > Note
> >
> ***********************************************************************
> > *
> > 
> > This email including any attachments is intended solely for the use
> of
> > named
> > recipient only.If you are not that person, you are not authorized to
> > read,copy,forward,disclose,take any action on information.Any other
> use
> > of
> > this email and attachments is prohibited.The views expressed in this
> > email
> > are not necessarily those of BMA.If you received this email by
> mistake,
> > please destroy all copies and contact  to the sender by email.your
> > cooperation is appreciated.
> > 
> >
> ***********************************************************************
> > *****
> > *********
> > 
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: log4j-user-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: log4j-user-help@jakarta.apache.org


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


Re: Nested Diagnostic Context

Posted by Adam Vainder <ad...@lexi.com>.
Hey,

Brief example.

jsp : 

<%@ page language="java" contentType="text/html" %>
<%@ page import="org.apache.log4j.*" %>

<%-- ------------------------------------------------------------------%>
<%-- Page initialization                                             --%>
<%-- ------------------------------------------------------------------%>
<%!//make logger private static 
	//private static Logger log = Logger.getRootLogger();
	private static Logger log = Logger.getLogger("com.foo");
%>

<%
        String userHost=request.getRemoteHost();
	String userIp=request.getRemoteAddr();
	NDC.clear();
	NDC.push(userHost);
	NDC.push(userIp);
%>

<html>
    <head>
	<title>LOG EXAMPLE</title>

    </head>
    <body>
<%
    log.info("THIS IS A TEST");
%>
    <!--whatever else you want to do-->
    </body>
<%
      NDC.remove(); //clear things up if not forwarding to another page, 
otherwise omit this until the last page(s) the person can reach, 
including error pages, etc.
%>
</html>


Properties file :

log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A1.file=/opt/tomcat/webapps/foo.log
log4j.appender.A1.MaxFileSize=100KB
log4j.appender.A1.MaxBackupIndex=1
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern==%d{MM-dd-yyyy HH:mm:ss} %-5p 
%c %x - %m%n


Should give something along the format :
  <date and time> INFO <jsp-filename> <hostname ip-address (e.g. NDC 
info)> - THIS IS A TEST

the %x in the ConversionPattern is what outputs the NDC.

Does that help enough?

Adam Vainder

-----Original Message-----
From: Sandeep <sa...@bma.gov.bh>
To: 'Log4J Users List' <lo...@jakarta.apache.org>
Date: Thu, 9 Oct 2003 13:27:01 +0300 
Subject: Nested Diagnostic Context

> 
> 
> Hi All ,
> 
> DO any one have example or document using NDC (Nested Diagnostic
> Context)
> for webapplication as in jsp.
> 
> TIA 
> 
> 
> 
> Note
> ***********************************************************************
> *
> 
> This email including any attachments is intended solely for the use of
> named
> recipient only.If you are not that person, you are not authorized to
> read,copy,forward,disclose,take any action on information.Any other use
> of
> this email and attachments is prohibited.The views expressed in this
> email
> are not necessarily those of BMA.If you received this email by mistake,
> please destroy all copies and contact  to the sender by email.your
> cooperation is appreciated.
> 
> ***********************************************************************
> *****
> *********
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: log4j-user-help@jakarta.apache.org


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


RE: Nested Diagnostic Context

Posted by Preetham Kajekar <pr...@cisco.com>.
I have used NDC's. To put in very simply, it is some context information
attached with a thread. More context information can be pushed/popped as
required.

In a client/server application, you may typically push the NDC for every
client thread containing informatiion which will help you debug (like
user-name, session details etc). This would be done at the first level
interface class. (the server class which interfaces with the transport
mechanism)

 I have never used JSP', but guess should not be too diff. Can you give
us more details as to what you need it for ?

Cheers,
 ~preetham

> -----Original Message-----
> From: Sandeep [mailto:sandeep@bma.gov.bh] 
> Sent: Thursday, October 09, 2003 3:57 PM
> To: 'Log4J Users List'
> Subject: Nested Diagnostic Context
> 
> 
> 
> 
> Hi All ,
> 
> DO any one have example or document using NDC (Nested 
> Diagnostic Context) for webapplication as in jsp.
> 
> TIA 
> 
> 
> 
> Note
> **************************************************************
> **********
> 
> This email including any attachments is intended solely for 
> the use of named recipient only.If you are not that person, 
> you are not authorized to read,copy,forward,disclose,take any 
> action on information.Any other use of this email and 
> attachments is prohibited.The views expressed in this email 
> are not necessarily those of BMA.If you received this email 
> by mistake, please destroy all copies and contact  to the 
> sender by email.your cooperation is appreciated.
> 
> **************************************************************
> **************
> *********
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: log4j-user-help@jakarta.apache.org
> 


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