Java 使 log4j 可加性等于 true 或 false 的结果是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22692097/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 17:19:16  来源:igfitidea点击:

What is the result of making log4j additivity equals to true or false?

javalogginglog4j

提问by user3433510

In simple terms what is the result of making additivity="true"or additivity="false"when adding a Log4j configuration for a specific class like this?

简单来说,为这样的特定类添加additivity="true"additivity="false"添加 Log4j 配置的结果是什么?

<Logger name="com.mypage.glass.TryWindow" level="INFO" additivity="true">
  <AppenderRef ref="console"/>
  <AppenderRef ref="file"/>
</Logger>

采纳答案by Duncan Jones

By default, a logger inherits the appenders from its ancestors. By setting additivity="false", you prevent this behaviour.

默认情况下,记录器从其祖先继承附加程序。通过设置additivity="false",您可以防止这种行为。

In your example, there may be appenders associated with com.mypage.glassor com.mypageor even the root logger that would be inherited if you don't set that property to false.

在你的榜样,有可能是相关的追加程序com.mypage.glasscom.mypage或者即使你不设置该属性将被继承了根记录false