Log4cpp源碼解析——config

一、功能介紹

config組件實現了配置管理相關功能,配置控制着日誌的等級、日誌輸出路徑、日誌輸出格式,常用的配置模板如下:

# property configurator test file

log4cpp.rootCategory=DEBUG, rootAppender 
log4cpp.category.sub1=DEBUG, A1, A2, stderrAppender, stdoutAppender
log4cpp.category.sub1.sub2=DEBUG, A3

log4cpp.appender.rootAppender=ConsoleAppender
log4cpp.appender.rootAppender.layout=BasicLayout

log4cpp.appender.A1=FileAppender
log4cpp.appender.A1.fileName=A1.log
log4cpp.appender.A1.layout=PatternLayout
log4cpp.appender.A1.layout.ConversionPattern=The message %m at time %d, thread %t%n

log4cpp.appender.A2=FileAppender
log4cpp.appender.A2.threshold=WARN
log4cpp.appender.A2.fileName=A2.log
log4cpp.appender.A2.layout=PatternLayout
log4cpp.appender.A2.layout.ConversionPattern=The message %m at time %d, thread %t%n

該組件中包含兩個主要的類SimpleConfigurator、BasicConfigurator、PropertyConfigurator、PropertyConfiguratorImpl:

BasicConfigurator  提供基本的日誌配置,日誌等級設置INFO,日誌輸出到文件;

SimpleConfigurator 實現從配置文件中讀取功能配置

發佈了28 篇原創文章 · 獲贊 3 · 訪問量 5981
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章