サンプル11 testPriority.cpp

 log4cpp::Priorityのサンプルです。
優先度のコード(値)を文字列に変換したりといったことをしています。

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

testPriority.cpp

#include <iostream>
#include "log4cpp/Priority.hh"

using namespace log4cpp;

int main(int argc, char** argv) {
    
    std::cout << "priority debug(700): " << Priority::getPriorityName(700) << std::endl;
    std::cout << "priority debug(700): " << Priority::getPriorityValue("DEBUG") << std::endl;
    std::cout << "priority debug(700): " << Priority::getPriorityValue("700") << std::endl;
    try {
	std::cout << "priority debug(700): " << Priority::getPriorityValue("700arghh") << std::endl;
    } catch(std::invalid_argument& e) {
	std::cout << "caught " << e.what() << std::endl;
    }
    return 0;
}

実行結果例

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

stdout(標準出力):

priority debug(700): DEBUG
priority debug(700): 700
priority debug(700): 700
caught unknown priority name: '700arghh'