将logger中的 additivity 属性配置为 false,则这个logger不会将日志流反馈到root中。
可以达到以logger中配置的appender方式来输出日志而其他地方输出的目的,看配置:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
<
appender
name
=
"DEMO"
class
=
"com.XXXXX.RollingFileAppender"
>
<
param
name
=
"file"
value
=
"${loggingRoot}/xxx.log"
/>
<
param
name
=
"append"
value
=
"true"
/>
<
param
name
=
"encoding"
value
=
"GB2312"
/>
<
param
name
=
"threshold"
value
=
"info"
/>
<
param
name
=
"MaxFileSize"
value
=
"50MB"
/>
<
param
name
=
"MaxBackupIndex"
value
=
"10"
/>
<
layout
class
=
"org.apache.log4j.PatternLayout"
>
<
param
name
=
"ConversionPattern"
value
=
"%d [%X{requestURIWithQueryString}] %-5p %c{2} - %m%n"
/>
</
layout
>
</
appender
>
<
logger
name
=
"XXXX.XXXX.XXXX"
additivity
=
"false"
>
<
level
value
=
"${loggingLevel}"
/>
<
appender-ref
ref
=
"DEMO"
/>
</
logger
>
|
root的作用是收集下面所有反馈上来的信息流并根据配置在root中appender进行输出,只要你在looger中配置了additivity="false",就不会反馈到root中。
意味着不会重复输出!