⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 classlog4cpp_1_1ndc.html

📁 log4cpp 的参考文档, 一个非常好用的C++ log 类库
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>log4cpp: log4cpp::NDC Class Reference</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.4.2 --><div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="namespacemembers.html">Namespace&nbsp;Members</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div><div class="nav"><a class="el" href="namespacelog4cpp.html">log4cpp</a>::<a class="el" href="classlog4cpp_1_1NDC.html">NDC</a></div><h1>log4cpp::NDC Class Reference</h1>The <a class="el" href="classlog4cpp_1_1NDC.html">NDC</a> class implements <em>nested diagnostic contexts</em> as defined by Neil Harrison in the article "Patterns for Logging Diagnostic Messages" part of the book "<em>Pattern Languages of Program Design 3</em>" edited by Martin et al.  <a href="#_details">More...</a><p><code>#include &lt;<a class="el" href="NDC_8hh-source.html">NDC.hh</a>&gt;</code><p><a href="classlog4cpp_1_1NDC-members.html">List of all members.</a><table border="0" cellpadding="0" cellspacing="0"><tr><td></td></tr><tr><td colspan="2"><br><h2>Public Types</h2></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">typedef std::vector&lt; <a class="el" href="structlog4cpp_1_1NDC_1_1DiagnosticContext.html">DiagnosticContext</a> &gt;&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classlog4cpp_1_1NDC.html#w0">ContextStack</a></td></tr><tr><td colspan="2"><br><h2>Public Member Functions</h2></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classlog4cpp_1_1NDC.html#a0">NDC</a> ()</td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">virtual&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classlog4cpp_1_1NDC.html#a1">~NDC</a> ()</td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">virtual void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classlog4cpp_1_1NDC.html#a2">_clear</a> ()</td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">virtual <a class="el" href="classlog4cpp_1_1NDC.html#w0">ContextStack</a> *&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classlog4cpp_1_1NDC.html#a3">_cloneStack</a> ()</td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">virtual const std::string &amp;&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classlog4cpp_1_1NDC.html#a4">_get</a> () const </td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">virtual size_t&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classlog4cpp_1_1NDC.html#a5">_getDepth</a> () const </td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">virtual void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classlog4cpp_1_1NDC.html#a6">_inherit</a> (<a class="el" href="classlog4cpp_1_1NDC.html#w0">ContextStack</a> *stack)</td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">virtual std::string&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classlog4cpp_1_1NDC.html#a7">_pop</a> ()</td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">virtual void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classlog4cpp_1_1NDC.html#a8">_push</a> (const std::string &amp;message)</td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">virtual void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classlog4cpp_1_1NDC.html#a9">_setMaxDepth</a> (int maxDepth)</td></tr><tr><td colspan="2"><br><h2>Static Public Member Functions</h2></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">static void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classlog4cpp_1_1NDC.html#e0">clear</a> ()</td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Clear any nested disgnostic information if any.  <a href="#e0"></a><br></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">static <a class="el" href="classlog4cpp_1_1NDC.html#w0">ContextStack</a> *&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classlog4cpp_1_1NDC.html#e1">cloneStack</a> ()</td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Clone the diagnostic context for the current thread.  <a href="#e1"></a><br></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">static const std::string &amp;&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classlog4cpp_1_1NDC.html#e2">get</a> ()</td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Get the current diagnostic context string.  <a href="#e2"></a><br></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">static size_t&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classlog4cpp_1_1NDC.html#e3">getDepth</a> ()</td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Get the current nesting depth of this diagnostic context.  <a href="#e3"></a><br></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">static void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classlog4cpp_1_1NDC.html#e4">inherit</a> (<a class="el" href="classlog4cpp_1_1NDC.html#w0">ContextStack</a> *stack)</td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">static std::string&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classlog4cpp_1_1NDC.html#e5">pop</a> ()</td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Clients should call this method before leaving a diagnostic context.  <a href="#e5"></a><br></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">static void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classlog4cpp_1_1NDC.html#e6">push</a> (const std::string &amp;message)</td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Push new diagnostic context information for the current thread.  <a href="#e6"></a><br></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">static void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classlog4cpp_1_1NDC.html#e7">setMaxDepth</a> (int maxDepth)</td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Set the maximum nesting depth for the current <a class="el" href="classlog4cpp_1_1NDC.html">NDC</a>.  <a href="#e7"></a><br></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">static <a class="el" href="classlog4cpp_1_1NDC.html">NDC</a> &amp;&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classlog4cpp_1_1NDC.html#e8">getNDC</a> ()</td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Return the <a class="el" href="classlog4cpp_1_1NDC.html">NDC</a> for the current thread.  <a href="#e8"></a><br></td></tr><tr><td colspan="2"><br><h2>Public Attributes</h2></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="el" href="classlog4cpp_1_1NDC.html#w0">ContextStack</a>&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classlog4cpp_1_1NDC.html#o0">_stack</a></td></tr><tr><td colspan="2"><br><h2>Classes</h2></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">struct &nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="structlog4cpp_1_1NDC_1_1DiagnosticContext.html">DiagnosticContext</a></td></tr></table><hr><a name="_details"></a><h2>Detailed Description</h2>The <a class="el" href="classlog4cpp_1_1NDC.html">NDC</a> class implements <em>nested diagnostic contexts</em> as defined by Neil Harrison in the article "Patterns for Logging Diagnostic Messages" part of the book "<em>Pattern Languages of Program Design 3</em>" edited by Martin et al. <p>A Nested Diagnostic Context, or <a class="el" href="classlog4cpp_1_1NDC.html">NDC</a> 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-simulatanously.<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>. <a class="el" href="classlog4cpp_1_1NDC.html">NDC</a> operations such as <code>push</code>, <code> pop</code>, <code>clear</code>, <code>getDepth</code> and <code> setMaxDepth</code> affect the <a class="el" href="classlog4cpp_1_1NDC.html">NDC</a> of the <em>current</em> thread only. NDCs of other threads remain unaffected.<p>To build an <a class="el" href="classlog4cpp_1_1NDC.html">NDC</a> one uses the <code>push</code> operation. Simply put,<p><ul><li>Contexts can be nested.<p><p></li><li>When entering a context, call <code><a class="el" href="classlog4cpp_1_1NDC.html#e6">NDC.push</a></code>. As a side effect, if there is no nested diagnostic context for the current thread, this method will create it.<p><p></li><li>When leaving a context, call <code><a class="el" href="classlog4cpp_1_1NDC.html#e5">NDC.pop</a></code>. </li></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 <a class="el" href="classlog4cpp_1_1NDC.html">NDC</a>.<p>Custom Layouts may include the nested diagnostic context for the current thread in log messages, without any user intervention. Hence, even if a server 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 <a class="el" href="classlog4cpp_1_1NDC.html">NDC</a> tag.<p><em>Unfortunately, unlike Java, C++ does not have platform independent multithreading support. Therefore, currently <a class="el" href="namespacelog4cpp.html">log4cpp</a> is not multithread aware, it implicitly assumes only one thread exists, the main process thread. </em> <p><hr><h2>Member Typedef Documentation</h2><a class="anchor" name="w0" doxytag="log4cpp::NDC::ContextStack"></a><p><table class="mdTable" cellpadding="2" cellspacing="0">  <tr>    <td class="mdRow">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top">typedef std::vector&lt;<a class="el" href="structlog4cpp_1_1NDC_1_1DiagnosticContext.html">DiagnosticContext</a>&gt; <a class="el" href="classlog4cpp_1_1NDC.html#w0">log4cpp::NDC::ContextStack</a>          </td>        </tr>      </table>    </td>  </tr></table><table cellspacing="5" cellpadding="0" border="0">  <tr>    <td>      &nbsp;    </td>    <td><p>    </td>  </tr></table><hr><h2>Constructor &amp; Destructor Documentation</h2><a class="anchor" name="a0" doxytag="log4cpp::NDC::NDC"></a><p><table class="mdTable" cellpadding="2" cellspacing="0">  <tr>    <td class="mdRow">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top">log4cpp::NDC::NDC           </td>          <td class="md" valign="top">(&nbsp;</td>          <td class="mdname1" valign="top" nowrap>          </td>          <td class="md" valign="top">&nbsp;)&nbsp;</td>          <td class="md" nowrap></td>        </tr>      </table>    </td>  </tr></table><table cellspacing="5" cellpadding="0" border="0">  <tr>    <td>      &nbsp;    </td>    <td><p>    </td>  </tr></table><a class="anchor" name="a1" doxytag="log4cpp::NDC::~NDC"></a><p><table class="mdTable" cellpadding="2" cellspacing="0">  <tr>    <td class="mdRow">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top">log4cpp::NDC::~NDC           </td>          <td class="md" valign="top">(&nbsp;</td>          <td class="mdname1" valign="top" nowrap>          </td>          <td class="md" valign="top">&nbsp;)&nbsp;</td>          <td class="md" nowrap><code> [virtual]</code></td>        </tr>      </table>    </td>  </tr></table><table cellspacing="5" cellpadding="0" border="0">  <tr>    <td>      &nbsp;    </td>    <td><p>    </td>  </tr></table><hr><h2>Member Function Documentation</h2><a class="anchor" name="a2" doxytag="log4cpp::NDC::_clear"></a><p><table class="mdTable" cellpadding="2" cellspacing="0">  <tr>    <td class="mdRow">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top">void log4cpp::NDC::_clear           </td>          <td class="md" valign="top">(&nbsp;</td>          <td class="mdname1" valign="top" nowrap>          </td>          <td class="md" valign="top">&nbsp;)&nbsp;</td>          <td class="md" nowrap><code> [virtual]</code></td>        </tr>      </table>    </td>  </tr></table><table cellspacing="5" cellpadding="0" border="0">  <tr>    <td>      &nbsp;    </td>    <td><p>    </td>  </tr></table><a class="anchor" name="a3" doxytag="log4cpp::NDC::_cloneStack"></a><p><table class="mdTable" cellpadding="2" cellspacing="0">  <tr>    <td class="mdRow">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top"><a class="el" href="classlog4cpp_1_1NDC.html#w0">NDC::ContextStack</a> * log4cpp::NDC::_cloneStack           </td>          <td class="md" valign="top">(&nbsp;</td>          <td class="mdname1" valign="top" nowrap>          </td>          <td class="md" valign="top">&nbsp;)&nbsp;</td>          <td class="md" nowrap><code> [virtual]</code></td>        </tr>      </table>    </td>  </tr></table><table cellspacing="5" cellpadding="0" border="0">  <tr>    <td>      &nbsp;    </td>    <td><p>    </td>  </tr></table><a class="anchor" name="a4" doxytag="log4cpp::NDC::_get"></a><p><table class="mdTable" cellpadding="2" cellspacing="0">  <tr>    <td class="mdRow">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top">const std::string &amp; log4cpp::NDC::_get           </td>          <td class="md" valign="top">(&nbsp;</td>          <td class="mdname1" valign="top" nowrap>          </td>          <td class="md" valign="top">&nbsp;)&nbsp;</td>          <td class="md" nowrap> const<code> [virtual]</code></td>        </tr>      </table>    </td>  </tr></table><table cellspacing="5" cellpadding="0" border="0">  <tr>    <td>      &nbsp;    </td>    <td><p>    </td>  </tr></table><a class="anchor" name="a5" doxytag="log4cpp::NDC::_getDepth"></a><p><table class="mdTable" cellpadding="2" cellspacing="0">  <tr>    <td class="mdRow">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top">size_t log4cpp::NDC::_getDepth           </td>          <td class="md" valign="top">(&nbsp;</td>          <td class="mdname1" valign="top" nowrap>          </td>          <td class="md" valign="top">&nbsp;)&nbsp;</td>          <td class="md" nowrap> const<code> [virtual]</code></td>        </tr>      </table>    </td>  </tr></table><table cellspacing="5" cellpadding="0" border="0">  <tr>    <td>      &nbsp;    </td>    <td><p>    </td>  </tr></table><a class="anchor" name="a6" doxytag="log4cpp::NDC::_inherit"></a><p><table class="mdTable" cellpadding="2" cellspacing="0">  <tr>    <td class="mdRow">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top">void log4cpp::NDC::_inherit           </td>          <td class="md" valign="top">(&nbsp;</td>          <td class="md" nowrap valign="top"><a class="el" href="classlog4cpp_1_1NDC.html#w0">ContextStack</a> *&nbsp;</td>          <td class="mdname1" valign="top" nowrap> <em>stack</em>          </td>          <td class="md" valign="top">&nbsp;)&nbsp;</td>          <td class="md" nowrap><code> [virtual]</code></td>        </tr>      </table>    </td>  </tr></table><table cellspacing="5" cellpadding="0" border="0">  <tr>    <td>      &nbsp;    </td>    <td><p>    </td>  </tr></table><a class="anchor" name="a7" doxytag="log4cpp::NDC::_pop"></a><p><table class="mdTable" cellpadding="2" cellspacing="0">  <tr>    <td class="mdRow">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top">std::string log4cpp::NDC::_pop           </td>          <td class="md" valign="top">(&nbsp;</td>          <td class="mdname1" valign="top" nowrap>          </td>          <td class="md" valign="top">&nbsp;)&nbsp;</td>          <td class="md" nowrap><code> [virtual]</code></td>        </tr>      </table>    </td>  </tr></table><table cellspacing="5" cellpadding="0" border="0">  <tr>    <td>      &nbsp;    </td>    <td><p>    </td>  </tr></table><a class="anchor" name="a8" doxytag="log4cpp::NDC::_push"></a><p><table class="mdTable" cellpadding="2" cellspacing="0">  <tr>    <td class="mdRow">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top">void log4cpp::NDC::_push           </td>          <td class="md" valign="top">(&nbsp;</td>          <td class="md" nowrap valign="top">const std::string &amp;&nbsp;</td>          <td class="mdname1" valign="top" nowrap> <em>message</em>          </td>          <td class="md" valign="top">&nbsp;)&nbsp;</td>          <td class="md" nowrap><code> [virtual]</code></td>        </tr>      </table>    </td>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -