在搜索什麼感覺太長時間後,我決定在stackoverflow上問這個簡單的問題: 如何爲log4cplus(1.1.2)創建自定義佈局? 最接近的相關問題是How do I add a custom filter in log4cplus?,作者將新類直接添加到log4cplus目錄中(或使用log4cplus命名空間?)。我沒有這個選項作爲log4plus頭文件和庫是獨立安裝(和簡單的設置命名空間log4cplus也不管用如何爲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?