How to filter stacktrace frames in Logback

I contacted Tomasz Nurkiewicz (the author of the blog linked in the question) and he kindly answered my question. I'm posting the answer, just in case:
While printing stack trace, to filter lines from bar package use the following:

<configuration>
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> 
    <encoder>
      <pattern>[%thread] %-5level - %msg%n%rEx{full, bar}</pattern>
    </encoder>
  </appender>
  ...
</configuration>

I wanted to use it in my web application (Tomcat+Spring+Hibernate+etc). So I configured logback with the following not to print any stack trace line from org.something packages (e.g. org.apache, org.springframework, org.hibernate, etc):

<configuration>
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> 
    <encoder>
      <pattern>[%thread] %-5level - %msg%n%rEx{full, org}</pattern>
    </encoder>
  </appender>
  ...
</configuration>

Thanks Tomasz!


This may help someone who is writing springboot apps like me

I am currently using

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true" packagingData="true">
<springProperty scope="context" name="APP_NAME" source="spring.application.name"/>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<springProfile name="!cloud">

    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>${APP_NAME} %green(%d{dd-MM-yyyy HH:mm:ss.SSS}) %magenta([%thread]) %highlight(%-5level) %red(%logger.%M:%L) - %magenta(%msg) %rEx{full,java.lang.reflect.Method,
                org.apache.catalina,
                org.apache.tomcat,
                org.apache.coyote,
                javax,
                java.util.concurrent,
                java.lang.Thread,
                org.springframework.aop,
                org.springframework.boot.actuate,
                org.springframework.security,
                org.springframework.transaction,
                org.springframework.web,
                sun.reflect,
                net.sf.cglib,
                ByCGLIB
                }%n
            </pattern>
        </encoder>
    </appender>
</springProfile>
<springProfile name="cloud">
    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <!-- send cloud event in one line so kibana can log it as one event -->
            <pattern>%d{dd-MM-yyyy HH:mm:ss.SSS} [%thread] %-5level %logger.%M:%L - %msg %replace(%rEx){'[\r\n]+', '\\n'}%nopex %n</pattern>
        </encoder>
    </appender>
</springProfile>


<root level="INFO">
    <appender-ref ref="CONSOLE"/>
</root>

<logger name="com.aaa" level="DEBUG"/>
<logger name="org.springframework.web.filter" level="INFO"/>
<logger name="org.springframework.cloud" level="INFO"/>
<logger name="org.springframework.core.env" level="INFO"/>
<logger name="org.springframework.boot" level="INFO"/>
<logger name="org.springframework.boot.actuate" level="WARN"/>
<logger name="org.springframework.boot.context" level="INFO"/>
<logger name="org.springframework.boot.autoconfigure" level="INFO"/>
<logger name="io.lettuce.core.protocol" level="WARN"/>


I wrote my own feature that filters stacktrace which I used since 2010 and I am very happy with it. I published my own Open Source Java Library called MgntUtils which has stackfiltering feature and some other useful (IMHO) features. Here is the link to maven central MgntUtils and here is a link to github if you want a source code: MgntUtils at github also here is the link to the article that describes the library: MgntUtils Open Source Java library with stack trace filtering, Silent String parsing, Unicode converter and Version comparison. See The paragraph "Stacktrace noise filter"