This Project Has Not Released Any Files
NDCはnested diagnostic contextsの略で、日本語にすると「ネスト化診断コンテキスト」となります。
どういう物かを説明するより、どんなときに、何のために使うのかを説明した方が分かりやすいと思いますから、 その方針で説明してきます。
どんなときに:
何のために使うのか:
ログにスレッドIDやスレッド名を出力すれば?
そこでNDCを使います。
log4cppの中にサンプルがありますので、そのソースと、それを実行した結果を以下に示します。
ソース(tests/testNDC.cpp):
- #include <iostream>
- #include "log4cpp/NDC.hh"
- using namespace log4cpp;
- int main(int argc, char** argv) {
- std::cout << "1. empty NDC: " << NDC::get() << std::endl;
- NDC::push("context1");
- std::cout << "2. push context1: " << NDC::get() << std::endl;
- NDC::push("context2");
- std::cout << "3. push context2: " << NDC::get() << std::endl;
- NDC::push("context3");
- std::cout << "4. push context3: " << NDC::get() << std::endl;
- std::cout << "5. get depth: " << NDC::getDepth() << std::endl;
- std::cout << "6. pop: " << NDC::pop() << std::endl;
- NDC::clear();
- std::cout << "7. clear: " << NDC::get() << std::endl;
- return 0;
- }
実行結果:
1. empty NDC: 2. push context1: context1 3. push context2: context1 context2 4. push context3: context1 context2 context3 5. get depth: 3 6. pop: context3 7. clear:
APIドキュメント内でのNDCの説明
Log4J徹底解説~使い方(1)
Log4j Q&Aの中の「Q3:特定のクライアントのログの追跡を行うには?」
[PageInfo]
LastUpdate: 2012-05-13 07:59:22, ModifiedBy: daruma_kyo
[License]
GNU Free Documentation License
[Permissions]
view:all, edit:login users, delete/config:members