Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is the difference between logger level and threshold filter level in Logback?

I have an appender with a ThreshholdFilter with level INFO:

<appender name="my_apender" class="com.my.apender.MyAppender">
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
        <level>INFO</level>
    </filter>
</appender>

and a logger with level INFO, too:

<logger name="whatever" level="INFO">
    <appender-ref ref="my_appender"/>
</logger>

Which is the difference between both levels?

like image 511
Héctor Avatar asked Dec 30 '16 10:12

Héctor


2 Answers

The level assigned for the logger is the one used by your logger, whereas the level assigned inside the filter ch.qos.logback.classic.filter.ThresholdFilter is the level from which this appender will be logging stuff, for more details.

Here is an example to clarify things :

<!-- deny all events with a level below INFO, that is TRACE and DEBUG -->
<appender name="my_apender1" class="com.my.apender.MyAppender">
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
        <level>INFO</level>
    </filter>
</appender>

<!-- deny all events with a level below DEBUG, that is TRACE-->
<appender name="my_apender2" class="com.my.apender.MyAppender">
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
        <level>DEBUG</level>
    </filter>
</appender>

<!-- event with level DEBUG will be handled only by my_apender2, and events with higher levels than DEBUG will be handled by both appenders -->
<logger name="whatever" level="DEBUG">
    <appender-ref ref="my_appender1"/>
    <appender-ref ref="my_appender2"/>
</logger>
like image 81
Youssef NAIT Avatar answered Nov 11 '22 10:11

Youssef NAIT


To make the distinction clear, lets take an example... ...Lets say your logger is associated with two appenders, one appender logging to myapp_all.log file and another logging to myapp_error.log. Now if you want log only ERROR level logs to the myapp_error.log, you would use an appender filter as opposed to logger filter. Since a single class is generally associated with a single logger, you cannot bifurcate the ERROR level flow using a logger level.

like image 31
Piyush Bansal Avatar answered Nov 11 '22 09:11

Piyush Bansal