長すぎると感じるものを検索した後、stackoverflow で次の簡単な質問をすることにしました: log4cplus (1.1.2) のカスタム レイアウトを作成するにはどうすればよいですか? 最も関連性の高い質問は、log4cplus にカスタム フィルターを追加するにはどうすればよいですか? です。作成者は新しいクラスを直接 log4cplus ディレクトリに追加します (または log4cplus 名前空間を使用しますか?)。log4plus ヘッダーとライブラリは個別にインストールされるため、このオプションはありません (名前空間を log4cplus に設定するだけでは機能しません。
私が試したのは、log4cplus::PatternLayout から継承した最小限の例です。
namespace myNameSpace {
class LOG4CPLUS_EXPORT MyPatternLayout: public ::log4cplus::PatternLayout {
public:
MyPatternLayout(const log4cplus::tstring& pattern);
MyPatternLayout(const log4cplus::helpers::Properties& properties);
~MyPatternLayout();
private:
// Disallow copying of instances of this class
MyPatternLayout(const MyPatternLayout&);
MyPatternLayout& operator=(const MyPatternLayout&);
};
}
LOG4CPLUS_EXPORT がクラスを log4cplus フレームワークに登録して、構成ファイルで使用できるようにすることを期待しています。ただし、追加
log4cplus.appender.STDOUT.layout=myNameSpace::MyPatternLayout
エラーが発生します。
log4cplus:ERROR Cannot find LayoutFactory: "myNameSpace::MyPatternLayout"
では、カスタム Layout/Appender を登録するにはどうすればよいですか?