[[PageNavi(NavigationList)]]
=== サンプル ===
{{{ html
<span style="float:right">
}}}
{{{ GoogleAdsense
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0702888637712330";
/* 20120131 */
google_ad_slot = "8641490082";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
}}}
{{{ html
</span>
}}}
log4cppのサンプルはtestsディレクトリの中にあります。しかし、説明が無いので、分かり難いところがありますので、説明します。
==== testsディレクトリの構成 ====
以下は、testsディレクトリの中にあるファイルと、その概要です。
===== 1.testbench.cpp
ログ出力にかかった時間を計測しています。
※Clock.cppとClock.hhも使用しています。
===== 2.testCategory.cpp
[http://log4cpp-jp.sourceforge.jp/api/classlog4cpp_1_1Category.html log4cpp::Category]の使い方です。[[BR]]
1つのカテゴリに複数のアペンダーを設定したり、1つも設定されていないときにどうなるか?など。
===== 3.testConfig.cpp
log4cppの設定ファイル(シンプルフォーマット形式)の例です。
[http://log4cpp-jp.sourceforge.jp/api/classlog4cpp_1_1SimpleConfigurator.html log4cpp::SimpleConfigurator]の使い方となります。
※log4cpp.initを読み込みます。[[BR]]
※注意:この形式の設定ファイルは非推奨です。
===== 4.testErrorCollision.cpp
ERRORという識別子が衝突しないことを確認するサンプルです。
===== 5.testFilter.cpp
フィルター([http://log4cpp-jp.sourceforge.jp/api/classlog4cpp_1_1Filter.html log4cpp::Filter])を使ったサンプルです。
===== 6.testFixedContextCategory.cpp
[http://log4cpp-jp.sourceforge.jp/api/classlog4cpp_1_1FixedContextCategory.html log4cpp::FixedContextCategory]を使ったサンプルです。
このクラスはlog4cpp::Categoryのサブクラスな訳ですが、何が違うかと言うと、NDC(ネスト化診断コンテキスト)の部分が固定文字列に置き換えられるということです。
{{{ html
<span style="float:left">
}}}
{{{ GoogleAdsense
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0702888637712330";
/* 20120131 */
google_ad_slot = "8641490082";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
}}}
{{{ html
</span>
}}}
===== 7.testmain.cpp
いろいろなAppenderを使ったサンプルです。カテゴリも複数使用しています。[[BR]]
恐らく、最も最初に見ることとなるサンプルでしょう。
===== 8.testNDC.cpp
[http://log4cpp-jp.sourceforge.jp/api/classlog4cpp_1_1NDC.html log4cpp::NDC]を使ったサンプルで、[NDC NDC(ネスト化診断コンテキスト)]が、どのようなものなのかを示すものとなっています。
===== 9.testNTEventLog.cpp
[http://log4cpp-jp.sourceforge.jp/api/classlog4cpp_1_1NTEventLogAppender.html log4cpp::NTEventLogAppender]を使ったサンプルです。
※NTEventLogAppenderはWindowsのイベントログにログ出力を行うアペンダーです。
===== 10.testPattern.cpp
[http://log4cpp-jp.sourceforge.jp/api/classlog4cpp_1_1PatternLayout.html log4cpp::PatternLayout]のサンプル、すなわち、[[BR]]
%c:カテゴリ[[BR]]
%d:日付[[BR]]
など、実際に置換した後の文字列を確認することができます。
===== 11.testPriority.cpp
[http://log4cpp-jp.sourceforge.jp/api/classlog4cpp_1_1Priority.html log4cpp::Priority]のサンプルです。[[BR]]
優先度のコード(値)を文字列に変換したりといったことをしています。
===== 12.testProperties.cpp
[Properties log4cppの設定ファイル]がどのように解析されるかを知ることができるサンプルです。
※log4cpp.propertiesを読み込みます。
===== 13.testPropertyConfig.cpp
[Properties log4cppの設定ファイル]を使用し、ログ出力を行うサンプルです。
※testConfig.log4cpp.propertiesを読み込みます。
[[PageNavi(NavigationList)]]