| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| <!--NewPage--> |
| <HTML> |
| <HEAD> |
| <!-- Generated by javadoc (build 1.6.0_31) --> |
| <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| <TITLE> |
| NDC (Apache Log4j 1.2.17 API) |
| </TITLE> |
| |
| <META NAME="date" CONTENT="2012-06-09"> |
| |
| <LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style"> |
| |
| <SCRIPT type="text/javascript"> |
| function windowTitle() |
| { |
| if (location.href.indexOf('is-external=true') == -1) { |
| parent.document.title="NDC (Apache Log4j 1.2.17 API)"; |
| } |
| } |
| </SCRIPT> |
| <NOSCRIPT> |
| </NOSCRIPT> |
| |
| </HEAD> |
| |
| <BODY BGCOLOR="white" onload="windowTitle();"> |
| <HR> |
| |
| |
| <!-- ========= START OF TOP NAVBAR ======= --> |
| <A NAME="navbar_top"><!-- --></A> |
| <A HREF="#skip-navbar_top" title="Skip navigation links"></A> |
| <TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY=""> |
| <TR> |
| <TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> |
| <A NAME="navbar_top_firstrow"><!-- --></A> |
| <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY=""> |
| <TR ALIGN="center" VALIGN="top"> |
| <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> |
| <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> |
| <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> |
| <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/NDC.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD> |
| <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> |
| <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> |
| <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> |
| <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> |
| </TR> |
| </TABLE> |
| </TD> |
| <TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM> |
| </EM> |
| </TD> |
| </TR> |
| |
| <TR> |
| <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> |
| <A HREF="../../../org/apache/log4j/MDC.html" title="class in org.apache.log4j"><B>PREV CLASS</B></A> |
| <A HREF="../../../org/apache/log4j/PatternLayout.html" title="class in org.apache.log4j"><B>NEXT CLASS</B></A></FONT></TD> |
| <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> |
| <A HREF="../../../index.html?org/apache/log4j/NDC.html" target="_top"><B>FRAMES</B></A> |
| <A HREF="NDC.html" target="_top"><B>NO FRAMES</B></A> |
| <SCRIPT type="text/javascript"> |
| <!-- |
| if(window==top) { |
| document.writeln('<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>'); |
| } |
| //--> |
| </SCRIPT> |
| <NOSCRIPT> |
| <A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A> |
| </NOSCRIPT> |
| |
| |
| </FONT></TD> |
| </TR> |
| <TR> |
| <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> |
| SUMMARY: NESTED | FIELD | CONSTR | <A HREF="#method_summary">METHOD</A></FONT></TD> |
| <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> |
| DETAIL: FIELD | CONSTR | <A HREF="#method_detail">METHOD</A></FONT></TD> |
| </TR> |
| </TABLE> |
| <A NAME="skip-navbar_top"></A> |
| <!-- ========= END OF TOP NAVBAR ========= --> |
| |
| <HR> |
| <!-- ======== START OF CLASS DATA ======== --> |
| <H2> |
| <FONT SIZE="-1"> |
| org.apache.log4j</FONT> |
| <BR> |
| Class NDC</H2> |
| <PRE> |
| <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">java.lang.Object</A> |
| <IMG SRC="../../../resources/inherit.gif" ALT="extended by "><B>org.apache.log4j.NDC</B> |
| </PRE> |
| <HR> |
| <DL> |
| <DT><PRE>public class <B>NDC</B><DT>extends <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A></DL> |
| </PRE> |
| |
| <P> |
| The NDC class implements <i>nested diagnostic contexts</i> as |
| defined by Neil Harrison in the article "Patterns for Logging |
| Diagnostic Messages" part of the book "<i>Pattern Languages of |
| Program Design 3</i>" edited by Martin et al. |
| |
| <p>A Nested Diagnostic Context, or NDC in short, is an instrument |
| to distinguish interleaved log output from different sources. Log |
| output is typically interleaved when a server handles multiple |
| clients near-simultaneously. |
| |
| <p>Interleaved log output can still be meaningful if each log entry |
| from different contexts had a distinctive stamp. This is where NDCs |
| come into play. |
| |
| <p><em><b>Note that NDCs are managed on a per thread |
| basis</b></em>. NDC operations such as <A HREF="../../../org/apache/log4j/NDC.html#push(java.lang.String)"><CODE>push</CODE></A>, <A HREF="../../../org/apache/log4j/NDC.html#pop()"><CODE>pop()</CODE></A>, <A HREF="../../../org/apache/log4j/NDC.html#clear()"><CODE>clear()</CODE></A>, <A HREF="../../../org/apache/log4j/NDC.html#getDepth()"><CODE>getDepth()</CODE></A> and <A HREF="../../../org/apache/log4j/NDC.html#setMaxDepth(int)"><CODE>setMaxDepth(int)</CODE></A> |
| affect the NDC of the <em>current</em> thread only. NDCs of other |
| threads remain unaffected. |
| |
| <p>For example, a servlet can build a per client request NDC |
| consisting the clients host name and other information contained in |
| the the request. <em>Cookies</em> are another source of distinctive |
| information. To build an NDC one uses the <A HREF="../../../org/apache/log4j/NDC.html#push(java.lang.String)"><CODE>push</CODE></A> |
| operation. Simply put, |
| |
| <p><ul> |
| <li>Contexts can be nested. |
| |
| <p><li>When entering a context, call <code>NDC.push</code>. As a |
| side effect, if there is no nested diagnostic context for the |
| current thread, this method will create it. |
| |
| <p><li>When leaving a context, call <code>NDC.pop</code>. |
| |
| <p><li><b>When exiting a thread make sure to call <A HREF="../../../org/apache/log4j/NDC.html#remove()"><CODE>NDC.remove()</CODE></A></b>. |
| </ul> |
| |
| <p>There is no penalty for forgetting to match each |
| <code>push</code> operation with a corresponding <code>pop</code>, |
| except the obvious mismatch between the real application context |
| and the context set in the NDC. |
| |
| <p>If configured to do so, <A HREF="../../../org/apache/log4j/PatternLayout.html" title="class in org.apache.log4j"><CODE>PatternLayout</CODE></A> and <A HREF="../../../org/apache/log4j/TTCCLayout.html" title="class in org.apache.log4j"><CODE>TTCCLayout</CODE></A> instances automatically retrieve the nested diagnostic |
| context for the current thread without any user intervention. |
| Hence, even if a servlet is serving multiple clients |
| simultaneously, the logs emanating from the same code (belonging to |
| the same category) can still be distinguished because each client |
| request will have a different NDC tag. |
| |
| <p>Heavy duty systems should call the <A HREF="../../../org/apache/log4j/NDC.html#remove()"><CODE>remove()</CODE></A> method when |
| leaving the run method of a thread. This ensures that the memory |
| used by the thread can be freed by the Java garbage |
| collector. There is a mechanism to lazily remove references to dead |
| threads. In practice, this means that you can be a little sloppy |
| and sometimes forget to call <A HREF="../../../org/apache/log4j/NDC.html#remove()"><CODE>remove()</CODE></A> before exiting a |
| thread. |
| |
| <p>A thread may inherit the nested diagnostic context of another |
| (possibly parent) thread using the <A HREF="../../../org/apache/log4j/NDC.html#inherit(java.util.Stack)"><CODE>inherit</CODE></A> |
| method. A thread may obtain a copy of its NDC with the <A HREF="../../../org/apache/log4j/NDC.html#cloneStack()"><CODE>cloneStack</CODE></A> method and pass the reference to any other |
| thread, in particular to a child. |
| <P> |
| |
| <P> |
| <DL> |
| <DT><B>Since:</B></DT> |
| <DD>0.7.0</DD> |
| <DT><B>Author:</B></DT> |
| <DD>Ceki Gülcü</DD> |
| </DL> |
| <HR> |
| |
| <P> |
| |
| <!-- ========== METHOD SUMMARY =========== --> |
| |
| <A NAME="method_summary"><!-- --></A> |
| <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> |
| <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> |
| <TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2"> |
| <B>Method Summary</B></FONT></TH> |
| </TR> |
| <TR BGCOLOR="white" CLASS="TableRowColor"> |
| <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> |
| <CODE>static void</CODE></FONT></TD> |
| <TD><CODE><B><A HREF="../../../org/apache/log4j/NDC.html#clear()">clear</A></B>()</CODE> |
| |
| <BR> |
| Clear any nested diagnostic information if any.</TD> |
| </TR> |
| <TR BGCOLOR="white" CLASS="TableRowColor"> |
| <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> |
| <CODE>static <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Stack.html?is-external=true" title="class or interface in java.util">Stack</A></CODE></FONT></TD> |
| <TD><CODE><B><A HREF="../../../org/apache/log4j/NDC.html#cloneStack()">cloneStack</A></B>()</CODE> |
| |
| <BR> |
| Clone the diagnostic context for the current thread.</TD> |
| </TR> |
| <TR BGCOLOR="white" CLASS="TableRowColor"> |
| <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> |
| <CODE>static <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A></CODE></FONT></TD> |
| <TD><CODE><B><A HREF="../../../org/apache/log4j/NDC.html#get()">get</A></B>()</CODE> |
| |
| <BR> |
| <font color="#FF4040"><b>Never use this method directly, use the <A HREF="../../../org/apache/log4j/spi/LoggingEvent.html#getNDC()"><CODE>LoggingEvent.getNDC()</CODE></A> method instead</b></font>.</TD> |
| </TR> |
| <TR BGCOLOR="white" CLASS="TableRowColor"> |
| <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> |
| <CODE>static int</CODE></FONT></TD> |
| <TD><CODE><B><A HREF="../../../org/apache/log4j/NDC.html#getDepth()">getDepth</A></B>()</CODE> |
| |
| <BR> |
| Get the current nesting depth of this diagnostic context.</TD> |
| </TR> |
| <TR BGCOLOR="white" CLASS="TableRowColor"> |
| <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> |
| <CODE>static void</CODE></FONT></TD> |
| <TD><CODE><B><A HREF="../../../org/apache/log4j/NDC.html#inherit(java.util.Stack)">inherit</A></B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Stack.html?is-external=true" title="class or interface in java.util">Stack</A> stack)</CODE> |
| |
| <BR> |
| Inherit the diagnostic context of another thread.</TD> |
| </TR> |
| <TR BGCOLOR="white" CLASS="TableRowColor"> |
| <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> |
| <CODE>static <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A></CODE></FONT></TD> |
| <TD><CODE><B><A HREF="../../../org/apache/log4j/NDC.html#peek()">peek</A></B>()</CODE> |
| |
| <BR> |
| Looks at the last diagnostic context at the top of this NDC |
| without removing it.</TD> |
| </TR> |
| <TR BGCOLOR="white" CLASS="TableRowColor"> |
| <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> |
| <CODE>static <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A></CODE></FONT></TD> |
| <TD><CODE><B><A HREF="../../../org/apache/log4j/NDC.html#pop()">pop</A></B>()</CODE> |
| |
| <BR> |
| Clients should call this method before leaving a diagnostic |
| context.</TD> |
| </TR> |
| <TR BGCOLOR="white" CLASS="TableRowColor"> |
| <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> |
| <CODE>static void</CODE></FONT></TD> |
| <TD><CODE><B><A HREF="../../../org/apache/log4j/NDC.html#push(java.lang.String)">push</A></B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> message)</CODE> |
| |
| <BR> |
| Push new diagnostic context information for the current thread.</TD> |
| </TR> |
| <TR BGCOLOR="white" CLASS="TableRowColor"> |
| <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> |
| <CODE>static void</CODE></FONT></TD> |
| <TD><CODE><B><A HREF="../../../org/apache/log4j/NDC.html#remove()">remove</A></B>()</CODE> |
| |
| <BR> |
| Remove the diagnostic context for this thread.</TD> |
| </TR> |
| <TR BGCOLOR="white" CLASS="TableRowColor"> |
| <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> |
| <CODE>static void</CODE></FONT></TD> |
| <TD><CODE><B><A HREF="../../../org/apache/log4j/NDC.html#setMaxDepth(int)">setMaxDepth</A></B>(int maxDepth)</CODE> |
| |
| <BR> |
| Set maximum depth of this diagnostic context.</TD> |
| </TR> |
| </TABLE> |
| <A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A> |
| <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> |
| <TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"> |
| <TH ALIGN="left"><B>Methods inherited from class java.lang.<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</A></B></TH> |
| </TR> |
| <TR BGCOLOR="white" CLASS="TableRowColor"> |
| <TD><CODE><A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#clone()" title="class or interface in java.lang">clone</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#equals(java.lang.Object)" title="class or interface in java.lang">equals</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#finalize()" title="class or interface in java.lang">finalize</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#getClass()" title="class or interface in java.lang">getClass</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#hashCode()" title="class or interface in java.lang">hashCode</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#notify()" title="class or interface in java.lang">notify</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#notifyAll()" title="class or interface in java.lang">notifyAll</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#toString()" title="class or interface in java.lang">toString</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#wait()" title="class or interface in java.lang">wait</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#wait(long)" title="class or interface in java.lang">wait</A>, <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Object.html?is-external=true#wait(long, int)" title="class or interface in java.lang">wait</A></CODE></TD> |
| </TR> |
| </TABLE> |
| |
| <P> |
| |
| <!-- ============ METHOD DETAIL ========== --> |
| |
| <A NAME="method_detail"><!-- --></A> |
| <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> |
| <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> |
| <TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2"> |
| <B>Method Detail</B></FONT></TH> |
| </TR> |
| </TABLE> |
| |
| <A NAME="clear()"><!-- --></A><H3> |
| clear</H3> |
| <PRE> |
| public static void <B>clear</B>()</PRE> |
| <DL> |
| <DD>Clear any nested diagnostic information if any. This method is |
| useful in cases where the same thread can be potentially used |
| over and over in different unrelated contexts. |
| |
| <p>This method is equivalent to calling the <A HREF="../../../org/apache/log4j/NDC.html#setMaxDepth(int)"><CODE>setMaxDepth(int)</CODE></A> |
| method with a zero <code>maxDepth</code> argument. |
| <P> |
| <DD><DL> |
| <DT><B>Since:</B></DT> |
| <DD>0.8.4c</DD> |
| </DL> |
| </DD> |
| </DL> |
| <HR> |
| |
| <A NAME="cloneStack()"><!-- --></A><H3> |
| cloneStack</H3> |
| <PRE> |
| public static <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Stack.html?is-external=true" title="class or interface in java.util">Stack</A> <B>cloneStack</B>()</PRE> |
| <DL> |
| <DD>Clone the diagnostic context for the current thread. |
| |
| <p>Internally a diagnostic context is represented as a stack. A |
| given thread can supply the stack (i.e. diagnostic context) to a |
| child thread so that the child can inherit the parent thread's |
| diagnostic context. |
| |
| <p>The child thread uses the <A HREF="../../../org/apache/log4j/NDC.html#inherit(java.util.Stack)"><CODE>inherit</CODE></A> method to |
| inherit the parent's diagnostic context. |
| <P> |
| <DD><DL> |
| |
| <DT><B>Returns:</B><DD>Stack A clone of the current thread's diagnostic context.</DL> |
| </DD> |
| </DL> |
| <HR> |
| |
| <A NAME="inherit(java.util.Stack)"><!-- --></A><H3> |
| inherit</H3> |
| <PRE> |
| public static void <B>inherit</B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Stack.html?is-external=true" title="class or interface in java.util">Stack</A> stack)</PRE> |
| <DL> |
| <DD>Inherit the diagnostic context of another thread. |
| |
| <p>The parent thread can obtain a reference to its diagnostic |
| context using the <A HREF="../../../org/apache/log4j/NDC.html#cloneStack()"><CODE>cloneStack()</CODE></A> method. It should |
| communicate this information to its child so that it may inherit |
| the parent's diagnostic context. |
| |
| <p>The parent's diagnostic context is cloned before being |
| inherited. In other words, once inherited, the two diagnostic |
| contexts can be managed independently. |
| |
| <p>In java, a child thread cannot obtain a reference to its |
| parent, unless it is directly handed the reference. Consequently, |
| there is no client-transparent way of inheriting diagnostic |
| contexts. Do you know any solution to this problem? |
| <P> |
| <DD><DL> |
| <DT><B>Parameters:</B><DD><CODE>stack</CODE> - The diagnostic context of the parent thread.</DL> |
| </DD> |
| </DL> |
| <HR> |
| |
| <A NAME="get()"><!-- --></A><H3> |
| get</H3> |
| <PRE> |
| public static <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> <B>get</B>()</PRE> |
| <DL> |
| <DD><font color="#FF4040"><b>Never use this method directly, use the <A HREF="../../../org/apache/log4j/spi/LoggingEvent.html#getNDC()"><CODE>LoggingEvent.getNDC()</CODE></A> method instead</b></font>. |
| <P> |
| <DD><DL> |
| </DL> |
| </DD> |
| </DL> |
| <HR> |
| |
| <A NAME="getDepth()"><!-- --></A><H3> |
| getDepth</H3> |
| <PRE> |
| public static int <B>getDepth</B>()</PRE> |
| <DL> |
| <DD>Get the current nesting depth of this diagnostic context. |
| <P> |
| <DD><DL> |
| <DT><B>Since:</B></DT> |
| <DD>0.7.5</DD> |
| <DT><B>See Also:</B><DD><A HREF="../../../org/apache/log4j/NDC.html#setMaxDepth(int)"><CODE>setMaxDepth(int)</CODE></A></DL> |
| </DD> |
| </DL> |
| <HR> |
| |
| <A NAME="pop()"><!-- --></A><H3> |
| pop</H3> |
| <PRE> |
| public static <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> <B>pop</B>()</PRE> |
| <DL> |
| <DD>Clients should call this method before leaving a diagnostic |
| context. |
| |
| <p>The returned value is the value that was pushed last. If no |
| context is available, then the empty string "" is returned. |
| <P> |
| <DD><DL> |
| |
| <DT><B>Returns:</B><DD>String The innermost diagnostic context.</DL> |
| </DD> |
| </DL> |
| <HR> |
| |
| <A NAME="peek()"><!-- --></A><H3> |
| peek</H3> |
| <PRE> |
| public static <A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> <B>peek</B>()</PRE> |
| <DL> |
| <DD>Looks at the last diagnostic context at the top of this NDC |
| without removing it. |
| |
| <p>The returned value is the value that was pushed last. If no |
| context is available, then the empty string "" is returned. |
| <P> |
| <DD><DL> |
| |
| <DT><B>Returns:</B><DD>String The innermost diagnostic context.</DL> |
| </DD> |
| </DL> |
| <HR> |
| |
| <A NAME="push(java.lang.String)"><!-- --></A><H3> |
| push</H3> |
| <PRE> |
| public static void <B>push</B>(<A HREF="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</A> message)</PRE> |
| <DL> |
| <DD>Push new diagnostic context information for the current thread. |
| |
| <p>The contents of the <code>message</code> parameter is |
| determined solely by the client. |
| <P> |
| <DD><DL> |
| <DT><B>Parameters:</B><DD><CODE>message</CODE> - The new diagnostic context information.</DL> |
| </DD> |
| </DL> |
| <HR> |
| |
| <A NAME="remove()"><!-- --></A><H3> |
| remove</H3> |
| <PRE> |
| public static void <B>remove</B>()</PRE> |
| <DL> |
| <DD>Remove the diagnostic context for this thread. |
| |
| <p>Each thread that created a diagnostic context by calling |
| <A HREF="../../../org/apache/log4j/NDC.html#push(java.lang.String)"><CODE>push(java.lang.String)</CODE></A> should call this method before exiting. Otherwise, |
| the memory used by the <b>thread</b> cannot be reclaimed by the |
| VM. |
| |
| <p>As this is such an important problem in heavy duty systems and |
| because it is difficult to always guarantee that the remove |
| method is called before exiting a thread, this method has been |
| augmented to lazily remove references to dead threads. In |
| practice, this means that you can be a little sloppy and |
| occasionally forget to call <A HREF="../../../org/apache/log4j/NDC.html#remove()"><CODE>remove()</CODE></A> before exiting a |
| thread. However, you must call <code>remove</code> sometime. If |
| you never call it, then your application is sure to run out of |
| memory. |
| <P> |
| <DD><DL> |
| </DL> |
| </DD> |
| </DL> |
| <HR> |
| |
| <A NAME="setMaxDepth(int)"><!-- --></A><H3> |
| setMaxDepth</H3> |
| <PRE> |
| public static void <B>setMaxDepth</B>(int maxDepth)</PRE> |
| <DL> |
| <DD>Set maximum depth of this diagnostic context. If the current |
| depth is smaller or equal to <code>maxDepth</code>, then no |
| action is taken. |
| |
| <p>This method is a convenient alternative to multiple <A HREF="../../../org/apache/log4j/NDC.html#pop()"><CODE>pop()</CODE></A> calls. Moreover, it is often the case that at the end of |
| complex call sequences, the depth of the NDC is |
| unpredictable. The <code>setMaxDepth</code> method circumvents |
| this problem. |
| |
| <p>For example, the combination |
| <pre> |
| void foo() { |
| int depth = NDC.getDepth(); |
| |
| ... complex sequence of calls |
| |
| NDC.setMaxDepth(depth); |
| } |
| </pre> |
| |
| ensures that between the entry and exit of foo the depth of the |
| diagnostic stack is conserved. |
| <P> |
| <DD><DL> |
| <DT><B>Since:</B></DT> |
| <DD>0.7.5</DD> |
| <DT><B>See Also:</B><DD><A HREF="../../../org/apache/log4j/NDC.html#getDepth()"><CODE>getDepth()</CODE></A></DL> |
| </DD> |
| </DL> |
| <!-- ========= END OF CLASS DATA ========= --> |
| <HR> |
| |
| |
| <!-- ======= START OF BOTTOM NAVBAR ====== --> |
| <A NAME="navbar_bottom"><!-- --></A> |
| <A HREF="#skip-navbar_bottom" title="Skip navigation links"></A> |
| <TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY=""> |
| <TR> |
| <TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> |
| <A NAME="navbar_bottom_firstrow"><!-- --></A> |
| <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY=""> |
| <TR ALIGN="center" VALIGN="top"> |
| <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> |
| <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> |
| <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> |
| <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/NDC.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD> |
| <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> |
| <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> |
| <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> |
| <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> |
| </TR> |
| </TABLE> |
| </TD> |
| <TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM> |
| </EM> |
| </TD> |
| </TR> |
| |
| <TR> |
| <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> |
| <A HREF="../../../org/apache/log4j/MDC.html" title="class in org.apache.log4j"><B>PREV CLASS</B></A> |
| <A HREF="../../../org/apache/log4j/PatternLayout.html" title="class in org.apache.log4j"><B>NEXT CLASS</B></A></FONT></TD> |
| <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> |
| <A HREF="../../../index.html?org/apache/log4j/NDC.html" target="_top"><B>FRAMES</B></A> |
| <A HREF="NDC.html" target="_top"><B>NO FRAMES</B></A> |
| <SCRIPT type="text/javascript"> |
| <!-- |
| if(window==top) { |
| document.writeln('<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>'); |
| } |
| //--> |
| </SCRIPT> |
| <NOSCRIPT> |
| <A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A> |
| </NOSCRIPT> |
| |
| |
| </FONT></TD> |
| </TR> |
| <TR> |
| <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> |
| SUMMARY: NESTED | FIELD | CONSTR | <A HREF="#method_summary">METHOD</A></FONT></TD> |
| <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> |
| DETAIL: FIELD | CONSTR | <A HREF="#method_detail">METHOD</A></FONT></TD> |
| </TR> |
| </TABLE> |
| <A NAME="skip-navbar_bottom"></A> |
| <!-- ======== END OF BOTTOM NAVBAR ======= --> |
| |
| <HR> |
| Copyright © 1999-2012 <a href="http://www.apache.org">Apache Software Foundation</a>. All Rights Reserved. |
| </BODY> |
| </HTML> |