简体   繁体   中英

Logback: separate logging WARN / TRACE

I'm trying to configure logback to print: - everything (level trace or debug) to the screen - everything (level trace or debug) to the debugfile - warnings and above to an error file

My logback.xml config is like this:

...
<logger name="be" level="TRACE">
    <appender-ref ref="FILE-AUDIT" />
    <appender-ref ref="STDOUT" />
</logger>

<root level="WARN">
    <appender-ref ref="FILE-ERROR" />
</root>

However, the error and debug file contain exactly the same, being ALL logging (debug and error). I've already tried to play with the additivity option, but that's apparently not what I need.

The second question is that I use name "be" to have all classes under be.* but actually I want to capture everything there (com.* as well).

Found a solution by adding a filter to the appender:

    <appender name="FILE-ERROR"
    class="ch.qos.logback.core.rolling.RollingFileAppender">
       <!-- deny all events with a level below WARNING -->
       <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
           <level>WARN</level>
       </filter>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM