Logback Do not inherit root appenders

老子叫甜甜 提交于 2020-01-11 09:39:06

问题


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>

In this example, I do not want jsonlogger to inherit the syslog appender-ref from root.


回答1:


Turn off additivity (default true) for your logger:

<logger name="jsonlogger" level="INFO" additivity="false">
    <appender-ref ref="SYSLOGJSON" />
</logger>

As the logback-manual describes: http://logback.qos.ch/manual/configuration.html#overrridingCumulativity

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.



来源:https://stackoverflow.com/questions/21597827/logback-do-not-inherit-root-appenders

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!