代码部分
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
;
}