サンプル8 testNDC.cpp

 log4cpp::NDCを使ったサンプルで、NDC(ネスト化診断コンテキスト)が、どのようなものなのかを示すものとなっています。

関連ファイル
  • testNDC.cpp
ファイルの中身

testNDC.cpp

  1. #include <iostream>
  2. #include "log4cpp/NDC.hh"
  3. using namespace log4cpp;
  4. int main(int argc, char** argv) {
  5. std::cout << "1. empty NDC: " << NDC::get() << std::endl;
  6. NDC::push("context1");
  7. std::cout << "2. push context1: " << NDC::get() << std::endl;
  8. NDC::push("context2");
  9. std::cout << "3. push context2: " << NDC::get() << std::endl;
  10. NDC::push("context3");
  11. std::cout << "4. push context3: " << NDC::get() << std::endl;
  12. std::cout << "5. get depth: " << NDC::getDepth() << std::endl;
  13. std::cout << "6. pop: " << NDC::pop() << std::endl;
  14. NDC::clear();
  15. std::cout << "7. clear: " << NDC::get() << std::endl;
  16. return 0;
  17. }

実行結果例

 testNDC.cppをビルドし、実行した結果です。実行環境はLinux(Ubuntu 11.0)です。

stdout(標準出力):

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: