Logback: how to log only errors to file

Put this into your file appender definition:

<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
    <level>ERROR</level>
</filter>

The ThresholdFilter is in logback-classic.jar.


I don't understand why wrong answer here is upvoted. The guy wants ONLY error messages in his file.

Here is the correct answer:

<filter class="ch.qos.logback.classic.filter.LevelFilter">
  <level>ERROR</level>
  <onMatch>ACCEPT</onMatch>
  <onMismatch>DENY</onMismatch>
</filter>

Reference: https://logback.qos.ch/manual/filters.html#levelFilter