代碼部分
? void
log4cplus :: PropertyConfigurator :: replaceEnvironVariables ()
{
std :: vector < log4cplus :: tstring > keys = properties . propertyNames ();
// 解析屬性文件中的內容 , 需要定義什么是主屬性 , 什么次屬性
-- 注意 propertyName 以及 substEnvironVars
??? std :: vector < log4cplus :: tstring >:: iterator ? it = keys . begin ();
??? for (; it != keys . end (); ++ it ) {
??????? log4cplus :: tstring ? key = * it ;
??????? log4cplus :: tstring ? val = properties . getProperty ( key );
??????? log4cplus :: tstring ? subKey = substEnvironVars ( key , getLogLog ());
??????? if ( subKey != key ) {
??????????? properties . removeProperty ( key );
??????????? properties . setProperty ( subKey , val );
??????? }
??????? log4cplus :: tstring ? subVal = substEnvironVars ( val , getLogLog ());
??????? if ( subVal != val ) {
??????????? properties . setProperty ( subKey , subVal );
??????? }
??? }
}
void
log4cplus :: PropertyConfigurator :: configureLoggers ()
{
??? // 定義屬性文件的屬性項
??? if ( properties . exists ( LOG4CPLUS_TEXT ( "rootLogger" ) )) {
??????? Logger ? root = h . getRoot ();
??????? // 加載有關根 log 模塊的信息
??????? configureLogger ( root ,
??????? properties . getProperty ( LOG4CPLUS_TEXT ( "rootLogger" )));
??? }
??? // 獲取子屬性部件
?? ? Properties ? loggerProperties =
??????????? properties . getPropertySubset ( LOG4CPLUS_TEXT ( "logger." ));
vector < tstring > loggers = loggerProperties . propertyNames ();
// 注意 ConfigureLogger 部分的內容 , 獲取有關屬性值的描述
??? for ( vector < tstring >:: iterator ? it = loggers . begin (); it != loggers . end (); ++ it ) {
??????? Logger ? log = getLogger (* it );
??????? configureLogger ( log , loggerProperties . getProperty (* it ));
??? }
}
void
log4cplus :: PropertyConfigurator :: configureLogger ( log4cplus :: Logger ? logger ,
????????????????????????????????????? ??????????? const ? log4cplus :: tstring & config )
{
??? // Remove all spaces from config
tstring ? configString ;
// 如何實現 trim 的功能,實現一個范型的方法調用
??? remove_copy_if ( config . begin (), config . end (),
?????????????????? string_append_iterator < tstring >( configString ),
?????????????????? bind1st ( equal_to < tchar >(), ' ' ));
// "Tokenize" configString
// 分離字符部分的內容 , 按照 ? “,” 進行分隔
??? vector < tstring > tokens ;
??? tokenize ( configString , ',' ,
???????????? back_insert_iterator < vector < tstring > >( tokens ));
??? if ( tokens . size () == 0) {
??????? getLogLog (). error (? LOG4CPLUS_TEXT ( "PropertyConfigurator::configureLogger()- Invalid config string(Logger = " )
????????????????????????? + logger . getName ()
????????????????????????? + LOG4CPLUS_TEXT ( "): \"" )
????????????????????????? + config ?
????????????????????????? + LOG4CPLUS_TEXT ( "\"" ));
??????? return ;
??? }
?