登录不继承根追加程序 [英] Logback Do not inherit root appenders
问题描述
我有一个logback配置,其中有一个记录器,该记录器不应继承已添加到根记录器的syslog附加程序.我在文档中找不到任何方法.
I have a logback config where I have one logger that should not inherit the syslog appender that has been added to the root logger. I can't find anywhere in the documentation how to do this.
<root level="DEBUG">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
<appender-ref ref="SYSLOG" />
</root>
<logger name="jsonlogger" level="INFO">
<appender-ref ref="SYSLOGJSON" />
</logger>
在此示例中,我不希望jsonlogger从根继承syslog appender-ref.
In this example, I do not want jsonlogger to inherit the syslog appender-ref from root.
推荐答案
为记录器关闭可加性(默认为true):
Turn off additivity (default true) for your logger:
<logger name="jsonlogger" level="INFO" additivity="false">
<appender-ref ref="SYSLOGJSON" />
</logger>
如logback-manual所述: http://logback.qos.ch/manual /configuration.html#overrridingCumulativity
As the logback-manual describes: http://logback.qos.ch/manual/configuration.html#overrridingCumulativity
如果只希望它不具有SYSLOG附加程序,而没有FILE和STDOUT,则还必须在记录器本身中注册它们.
If you just want it to not have the SYSLOG appender, but FILE and STDOUT, you'll have to register those at the logger itself as well.
这篇关于登录不继承根追加程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!