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?
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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With