blob: 127ae902200ed2835e7019a3f09c577d6f5edf92 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (version 1.7.0_80) on Sun Oct 02 12:26:02 MST 2016 -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>NDC (Apache Log4j 1.x Compatibility API 2.7 API)</title>
<meta name="date" content="2016-10-02">
<link rel="stylesheet" type="text/css" href="../../../stylesheet.css" title="Style">
</head>
<body>
<script type="text/javascript"><!--
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="NDC (Apache Log4j 1.x Compatibility API 2.7 API)";
}
//-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar_top">
<!-- -->
</a><a href="#skip-navbar_top" title="Skip navigation links"></a><a name="navbar_top_firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="class-use/NDC.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../index-all.html">Index</a></li>
<li><a href="../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../org/apache/log4j/MDC.html" title="class in org.apache.log4j"><span class="strong">Prev Class</span></a></li>
<li><a href="../../../org/apache/log4j/PatternLayout.html" title="class in org.apache.log4j"><span class="strong">Next Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../index.html?org/apache/log4j/NDC.html" target="_top">Frames</a></li>
<li><a href="NDC.html" target="_top">No Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../allclasses-noframe.html">All Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_top");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method_summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method_detail">Method</a></li>
</ul>
</div>
<a name="skip-navbar_top">
<!-- -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<div class="subTitle">org.apache.log4j</div>
<h2 title="Class NDC" class="title">Class NDC</h2>
</div>
<div class="contentContainer">
<ul class="inheritance">
<li><a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">java.lang.Object</a></li>
<li>
<ul class="inheritance">
<li>org.apache.log4j.NDC</li>
</ul>
</li>
</ul>
<div class="description">
<ul class="blockList">
<li class="blockList">
<hr>
<br>
<pre>public final class <a href="../../../src-html/org/apache/log4j/NDC.html#line.24">NDC</a>
extends <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</a></pre>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- ========== METHOD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="method_summary">
<!-- -->
</a>
<h3>Method Summary</h3>
<table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation">
<caption><span>Methods</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Method and Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static void</code></td>
<td class="colLast"><code><strong><a href="../../../org/apache/log4j/NDC.html#clear()">clear</a></strong>()</code>
<div class="block">Clear any nested diagnostic information if any.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static <a href="http://docs.oracle.com/javase/7/docs/api/java/util/Stack.html?is-external=true" title="class or interface in java.util">Stack</a></code></td>
<td class="colLast"><code><strong><a href="../../../org/apache/log4j/NDC.html#cloneStack()">cloneStack</a></strong>()</code>
<div class="block">Clone the diagnostic context for the current thread.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a></code></td>
<td class="colLast"><code><strong><a href="../../../org/apache/log4j/NDC.html#get()">get</a></strong>()</code>
<div class="block"><strong style="color:#FF4040">Never use this method directly.</strong></div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../org/apache/log4j/NDC.html#getDepth()">getDepth</a></strong>()</code>
<div class="block">Get the current nesting depth of this diagnostic context.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static void</code></td>
<td class="colLast"><code><strong><a href="../../../org/apache/log4j/NDC.html#inherit(java.util.Stack)">inherit</a></strong>(<a href="http://docs.oracle.com/javase/7/docs/api/java/util/Stack.html?is-external=true" title="class or interface in java.util">Stack</a>&lt;<a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&gt;&nbsp;stack)</code>
<div class="block">Inherit the diagnostic context of another thread.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a></code></td>
<td class="colLast"><code><strong><a href="../../../org/apache/log4j/NDC.html#peek()">peek</a></strong>()</code>
<div class="block">Looks at the last diagnostic context at the top of this NDC
without removing it.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a></code></td>
<td class="colLast"><code><strong><a href="../../../org/apache/log4j/NDC.html#pop()">pop</a></strong>()</code>
<div class="block">Clients should call this method before leaving a diagnostic
context.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static void</code></td>
<td class="colLast"><code><strong><a href="../../../org/apache/log4j/NDC.html#push(java.lang.String)">push</a></strong>(<a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;message)</code>
<div class="block">Push new diagnostic context information for the current thread.</div>
</td>
</tr>
<tr class="altColor">
<td class="colFirst"><code>static void</code></td>
<td class="colLast"><code><strong><a href="../../../org/apache/log4j/NDC.html#remove()">remove</a></strong>()</code>
<div class="block">Remove the diagnostic context for this thread.</div>
</td>
</tr>
<tr class="rowColor">
<td class="colFirst"><code>static void</code></td>
<td class="colLast"><code><strong><a href="../../../org/apache/log4j/NDC.html#setMaxDepth(int)">setMaxDepth</a></strong>(int&nbsp;maxDepth)</code>
<div class="block">Set maximum depth of this diagnostic context.</div>
</td>
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods_inherited_from_class_java.lang.Object">
<!-- -->
</a>
<h3>Methods inherited from class&nbsp;java.lang.<a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true" title="class or interface in java.lang">Object</a></h3>
<code><a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#clone()" title="class or interface in java.lang">clone</a>, <a href="http://docs.oracle.com/javase/7/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://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#finalize()" title="class or interface in java.lang">finalize</a>, <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#getClass()" title="class or interface in java.lang">getClass</a>, <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#hashCode()" title="class or interface in java.lang">hashCode</a>, <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#notify()" title="class or interface in java.lang">notify</a>, <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#notifyAll()" title="class or interface in java.lang">notifyAll</a>, <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#toString()" title="class or interface in java.lang">toString</a>, <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#wait()" title="class or interface in java.lang">wait</a>, <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#wait(long)" title="class or interface in java.lang">wait</a>, <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html?is-external=true#wait(long,%20int)" title="class or interface in java.lang">wait</a></code></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ============ METHOD DETAIL ========== -->
<ul class="blockList">
<li class="blockList"><a name="method_detail">
<!-- -->
</a>
<h3>Method Detail</h3>
<a name="clear()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>clear</h4>
<pre>public static&nbsp;void&nbsp;<a href="../../../src-html/org/apache/log4j/NDC.html#line.38">clear</a>()</pre>
<div class="block">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></div>
</li>
</ul>
<a name="cloneStack()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>cloneStack</h4>
<pre>public static&nbsp;<a href="http://docs.oracle.com/javase/7/docs/api/java/util/Stack.html?is-external=true" title="class or interface in java.util">Stack</a>&nbsp;<a href="../../../src-html/org/apache/log4j/NDC.html#line.58">cloneStack</a>()</pre>
<div class="block">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>
<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></div>
<dl><dt><span class="strong">Returns:</span></dt><dd>Stack A clone of the current thread's diagnostic context.</dd></dl>
</li>
</ul>
<a name="inherit(java.util.Stack)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>inherit</h4>
<pre>public static&nbsp;void&nbsp;<a href="../../../src-html/org/apache/log4j/NDC.html#line.88">inherit</a>(<a href="http://docs.oracle.com/javase/7/docs/api/java/util/Stack.html?is-external=true" title="class or interface in java.util">Stack</a>&lt;<a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&gt;&nbsp;stack)</pre>
<div class="block">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>
<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>
<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></div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>stack</code> - The diagnostic context of the parent thread.</dd></dl>
</li>
</ul>
<a name="get()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>get</h4>
<pre>public static&nbsp;<a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;<a href="../../../src-html/org/apache/log4j/NDC.html#line.98">get</a>()</pre>
<div class="block"><strong style="color:#FF4040">Never use this method directly.</strong></div>
<dl><dt><span class="strong">Returns:</span></dt><dd>The string value of the specified key.</dd></dl>
</li>
</ul>
<a name="getDepth()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>getDepth</h4>
<pre>public static&nbsp;int&nbsp;<a href="../../../src-html/org/apache/log4j/NDC.html#line.107">getDepth</a>()</pre>
<div class="block">Get the current nesting depth of this diagnostic context.</div>
<dl><dt><span class="strong">Returns:</span></dt><dd>int The number of elements in the call stack.</dd><dt><span class="strong">See Also:</span></dt><dd><a href="../../../org/apache/log4j/NDC.html#setMaxDepth(int)"><code>setMaxDepth(int)</code></a></dd></dl>
</li>
</ul>
<a name="pop()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>pop</h4>
<pre>public static&nbsp;<a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;<a href="../../../src-html/org/apache/log4j/NDC.html#line.120">pop</a>()</pre>
<div class="block">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></div>
<dl><dt><span class="strong">Returns:</span></dt><dd>String The innermost diagnostic context.</dd></dl>
</li>
</ul>
<a name="peek()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>peek</h4>
<pre>public static&nbsp;<a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;<a href="../../../src-html/org/apache/log4j/NDC.html#line.133">peek</a>()</pre>
<div class="block">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></div>
<dl><dt><span class="strong">Returns:</span></dt><dd>String The innermost diagnostic context.</dd></dl>
</li>
</ul>
<a name="push(java.lang.String)">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>push</h4>
<pre>public static&nbsp;void&nbsp;<a href="../../../src-html/org/apache/log4j/NDC.html#line.145">push</a>(<a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html?is-external=true" title="class or interface in java.lang">String</a>&nbsp;message)</pre>
<div class="block">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></div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>message</code> - The new diagnostic context information.</dd></dl>
</li>
</ul>
<a name="remove()">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>remove</h4>
<pre>public static&nbsp;void&nbsp;<a href="../../../src-html/org/apache/log4j/NDC.html#line.169">remove</a>()</pre>
<div class="block">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>
<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 <code>remove</code> 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></div>
</li>
</ul>
<a name="setMaxDepth(int)">
<!-- -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>setMaxDepth</h4>
<pre>public static&nbsp;void&nbsp;<a href="../../../src-html/org/apache/log4j/NDC.html#line.204">setMaxDepth</a>(int&nbsp;maxDepth)</pre>
<div class="block">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>
<p>
For example, the combination
</p>
<pre>
void foo() {
&nbsp; int depth = NDC.getDepth();
&nbsp; ... complex sequence of calls
&nbsp; NDC.setMaxDepth(depth);
}
</pre>
<p>
ensures that between the entry and exit of foo the depth of the
diagnostic stack is conserved.
</p></div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>maxDepth</code> - The maximum depth of the stack.</dd><dt><span class="strong">See Also:</span></dt><dd><a href="../../../org/apache/log4j/NDC.html#getDepth()"><code>getDepth()</code></a></dd></dl>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<!-- ========= END OF CLASS DATA ========= -->
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar_bottom">
<!-- -->
</a><a href="#skip-navbar_bottom" title="Skip navigation links"></a><a name="navbar_bottom_firstrow">
<!-- -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="class-use/NDC.html">Use</a></li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../index-all.html">Index</a></li>
<li><a href="../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../org/apache/log4j/MDC.html" title="class in org.apache.log4j"><span class="strong">Prev Class</span></a></li>
<li><a href="../../../org/apache/log4j/PatternLayout.html" title="class in org.apache.log4j"><span class="strong">Next Class</span></a></li>
</ul>
<ul class="navList">
<li><a href="../../../index.html?org/apache/log4j/NDC.html" target="_top">Frames</a></li>
<li><a href="NDC.html" target="_top">No Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../allclasses-noframe.html">All Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
allClassesLink = document.getElementById("allclasses_navbar_bottom");
if(window==top) {
allClassesLink.style.display = "block";
}
else {
allClassesLink.style.display = "none";
}
//-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method_summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li>Constr&nbsp;|&nbsp;</li>
<li><a href="#method_detail">Method</a></li>
</ul>
</div>
<a name="skip-navbar_bottom">
<!-- -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
<p class="legalCopy"><small><p align="center">Copyright &#169; 1999-2016 <a href="http://www.apache.org">Apache Software Foundation</a>. All Rights Reserved.<br /> Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.</p></small></p>
</body>
</html>