log4j中logger标签中additivity属性的⽤法说明
⽬录
log4j logger标签中additivity属性
log4j.additivity⽤法和例⼦
log4j logger标签中additivity属性
将logger中的 additivity 属性配置为 false,则这个logger不会将⽇志流反馈到root中。
可以达到以logger中配置的appender⽅式来输出⽇志⽽其他地⽅输出的⽬的,看配置:
< 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中配置了
log4j2 appenderadditivity="false",就不会反馈到root中。
意味着不会重复输出!
log4j.additivity⽤法和例⼦
因为需要将packageOne和packageTwo的⽇志写⼊各⾃单独的⽂件,同时在总的⽇志中不出现packageOne和PackageTwo的⽇志。
可以使⽤log4j.additivity。因为log4j是层次的,如果没有log4j.additivity默认写⼊到packageOneFileAppender和packageTwoFileAppender的都会写⼊rootLogger的rootFileAppender
log4j.logger.demo.packageOone = INFO, packageOneFileAppender
log4j.additivity.demo.
packageOne
= false
log4j.category.demo.packageTwo = INFO, packageTwoFileAppender
log4j.additivity.demo.packageTwo = false
以上为个⼈经验,希望能给⼤家⼀个参考,也希望⼤家多多⽀持。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论