Search code examples
javalogginglogbackspring-logback

Logback : enable class on specific appender et disable it on the others


A specific class from a dependency produces too much logs, so I'm trying to store them in a specific file to avoid pollution of the other ones.

here's my logback-spring.xml file :

<configuration debug="true">

<!-- appenders declaration --> 

    <logger
        name="org.apache.james.protocols.netty.BasicChannelUpstreamHandler"
        level="INFO">
        <appender-ref ref="FileConnections" />
    </logger>


    <root level="DEBUG">
        <appender-ref ref="FileInf" /> <!-- ThresholdFilter Info -->
        <appender-ref ref="FileErr" /> <!-- ThresholdFilter Error -->
        <appender-ref ref="FileTra" /> <!-- ThresholdFilter Trace -->
        <appender-ref ref="JsonInf" /> <!-- Json formater -->
        <appender-ref ref="STDOUT" />  <!-- Console output -->
    </root>


</configuration> 

This code does redirect all the BasicChannelUpstreamHandler logs to my FileConnections appender but there is still logs fromm this class in other appenders.

Is there a way to disable BasicChannelUpstreamHandler logs on all the other appenders ?


Solution

  • You need to set the additivity flag to false as shown below.

    <logger name="org.apache.james.protocols.netty.BasicChannelUpstreamH‌​andler" level="INFO" additivity="false"> 
        <appender-ref ref="FileConnections" /> 
    </logger>