[[PageNavi(NavigationList)]]
==== サンプル12 testProperties.cpp ====
[Properties log4cppの設定ファイル]がどのように解析されるかを知ることができるサンプルです。
===== 関連ファイル =====
* testProperties.cpp
* log4cpp.properties
===== ファイルの中身 =====
testProperties.cpp[[BR]]
{{{ code cpp
#include "Properties.hh"
#include <iostream>
#include <fstream>
int main(int argc, char** argv) {
log4cpp::Properties properties;
std::string inFile = (argc > 1) ? argv[1] : "log4cpp.properties";
std::ifstream in(inFile.c_str());
properties.load(in);
properties.save(std::cout);
}
}}}
log4cpp.properties[[BR]]
{{{
# Set root category priority to DEBUG and its only appender to A1.
log4j.rootCategory=ERROR, A4
# categories for Board Control
log4j.category.BoardControl=INFO, A4
log4j.category.BoardControl.additivity=false
# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.BasicLayout
log4j.appender.A2=org.apache.log4j.RemoteSyslogAppender
log4j.appender.A2.syslogName=log4cppApp
log4j.appender.A2.syslogHost=localhost
log4j.appender.A2.facility=-1
log4j.appender.A2.portNumber=-1
log4j.appender.A2.layout=org.apache.log4j.BasicLayout
log4cpp.appender.A3=org.apache.log4j.Win32DebugAppender
log4cpp.appender.A3.layout=org.apache.log4j.BasicLayout
appender.A4=org.apache.log4j.FileAppender
appender.A4.fileName=smas2.log
appender.A4.layout=org.apache.log4j.BasicLayout
}}}
===== 実行結果例 =====
testProperties.cppをビルドし、実行した結果です。実行環境はLinux(Ubuntu 11.0)です。
stdout(標準出力):
{{{
priority debug(700): DEBUG
priority debug(700): 700
priority debug(700): 700
caught unknown priority name: '700arghh'
takashi@takashi-virtual-machine:/mnt/hgfs/share/log4cpp/tests$ ./testProperties
appender.A1=org.apache.log4j.ConsoleAppender
appender.A1.layout=org.apache.log4j.BasicLayout
appender.A2=org.apache.log4j.RemoteSyslogAppender
appender.A2.facility=-1
appender.A2.layout=org.apache.log4j.BasicLayout
appender.A2.portNumber=-1
appender.A2.syslogHost=localhost
appender.A2.syslogName=log4cppApp
appender.A3=org.apache.log4j.Win32DebugAppender
appender.A3.layout=org.apache.log4j.BasicLayout
appender.A4=org.apache.log4j.FileAppender
appender.A4.fileName=smas2.log
appender.A4.layout=org.apache.log4j.BasicLayout
category.BoardControl=INFO, A4
category.BoardControl.additivity=false
rootCategory=ERROR, A4
}}}
[[PageNavi(NavigationList)]]