简体   繁体   English

Log4j,不同的appender,同一个包和一个单独的类,写入不同的文件?

[英]Log4j, different appenders, same package and an individual class, write to different files?

I normally associate a package to an appender. 我通常将一个包与一个appender相关联。 But in this one case, this class is writing a lot of logs I want to filter out to a different appender. 但在这种情况下,这个类正在编写很多我希望过滤到不同appender的日志。 But the class is in the same package as my other classes. 但是这个类与我的其他类在同一个包中。

I am trying to do this: 我想这样做:

log4j.logger.com.app=DEBUG,MainAppender
log4j.logger.com.app.webservice.Web=DEBUG,WSAppender

I want the WSAppender to write to one file but I DON'T want the same logs from the MainAppender. 我希望WSAppender写入一个文件,但我不想从MainAppender获取相同的日志。 Right now, the logs from WSAppender also appear in MainAppender. 现在,来自WSAppender的日志也出现在MainAppender中。

You need to set additivity=false on the child logger. 您需要在子记录器上设置additivity = false。

See example here . 这里的例子。

log4j.additivity.com.app.webservice.Web = false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM