Logback exclude logger from root

2019-06-27 07:05发布

I have a few packaged and I want to separate logging.

<property name="A" value="com.a"/>
<property name="B" value="com.b"/>
<property name="C" value="com.c"/>

<logger name="${A}" level="DEBUG">
    <appender-ref ref="FILE_A"/>
</logger>

<logger name="${B}" level="DEBUG">
    <appender-ref ref="FILE_B"/>
</logger>

<logger name="${C}" level="DEBUG">
    <appender-ref ref="FILE_B"/> <!-- yes B -->
</logger>

<root level="DEBUG">      
    <-- used for other logs too ->
    <appender-ref ref="STDOUT"/>
    <appender-ref ref="ROOT_FILE"/>
</root>

So I have FILE_A FILE_B AND ROOT_FILE; ROOT_FILE contains info that writes by root logger and by A B and C loggers.

How I can exclude FILE_A FILE_B info from ROOT_FILE ?

Or in another words how i can exclude log data (com.c com.b com.a) from root logger ?

1条回答
闹够了就滚
2楼-- · 2019-06-27 07:49

set additivity flag for com.a and com.b loggers to false.

<logger name="${A}" level="DEBUG" additivity="false">
     <appender-ref ref="FILE_A"/>
</logger>

now events logged in that logger won't be propagated to parent loggers (root logger in your case).

documentation

查看更多
登录 后发表回答