全局函数
在全局函数中完成 LoggerAppender 的初始化工作
initializeFactoryRegistry ();
void initializeFactoryRegistry () {
AppenderFactoryRegistry & reg = getAppenderFactoryRegistry ();
auto_ptr < AppenderFactory > ptr1 ( new ConsoleAppenderFactory ());
reg . put ( ptr1 );
auto_ptr < AppenderFactory > ptr2 ( new NullAppenderFactory ());
reg . put ( ptr2 );
auto_ptr < AppenderFactory > ptr3 ( new FileAppenderFactory ());
reg . put ( ptr3 );
auto_ptr < AppenderFactory > ptr4 ( new RollingFileAppenderFactory ());
reg . put ( ptr4 );
auto_ptr < AppenderFactory > ptr5 ( new DailyRollingFileAppenderFactory ());
reg . put ( ptr5 );
auto_ptr < AppenderFactory > ptr6 ( new SocketAppenderFactory ());
reg . put ( ptr6 );
#if defined( _WIN32 )
auto_ptr < AppenderFactory > ptr7 ( new NTEventLogAppenderFactory ());
reg . put ( ptr7 );
#elif defined( HAVE_SYSLOG_H )
auto_ptr < AppenderFactory > ptr8 ( new SysLogAppenderFactory ());
reg . put ( ptr8 );
#endif
LayoutFactoryRegistry & reg2 = getLayoutFactoryRegistry ();
auto_ptr < LayoutFactory > ptr21 ( new SimpleLayoutFactory ());
reg2 . put ( ptr21 );
auto_ptr < LayoutFactory > ptr22 ( new TTCCLayoutFactory ());
reg2 . put ( ptr22 );
auto_ptr < LayoutFactory > ptr23 ( new PatternLayoutFactory ());
reg2 . put ( ptr23 );
FilterFactoryRegistry & reg3 = getFilterFactoryRegistry ();
auto_ptr < FilterFactory > ptr31 ( new DenyAllFilterFactory ());
reg3 . put ( ptr31 );
auto_ptr < FilterFactory > ptr32 ( new LogLevelMatchFilterFactory ());
reg3 . put ( ptr32 );
auto_ptr < FilterFactory > ptr33 ( new LogLevelRangeFilterFactory ());
reg3 . put ( ptr33 );
auto_ptr < FilterFactory > ptr34 ( new StringMatchFilterFactory ());
reg3 . put ( ptr34 );
}
通过这种方式来实现
AppenderFactoryRegistry
LayoutFactoryRegistry
FilterFactoryRegistry
的初始化工作 – 如果要加入新的类型的数据的支持 , 需要将这部分的内容也要实现
如何利用 Registry 中的内容来实现对象数据的创建 ?
注意
得到的指针内容都是 Factory 中定义的内容 ,
通过调用 Factory 方法来获取具体的能够使用的对象的实例