[logback-user] lower-upper level limits

Ceki Gulcu ceki at qos.ch
Sat Oct 13 17:45:32 CEST 2007


Hello Dávid,

Yes, there is. You need to create to console appenders, named STDOUT and STDERR, 
  sending output to stdout and respectively to stderr. You attach both appenders 
to an appropriate logger, say root. One you have done that, attach a LevelFilter 
denying messages of level ERROR to the STDOUT appender, and attach a LevelFilter 
accepting messages of level ERROR (and denying other levels) to STDERR. You can 
learn more on filters in dedicated chapter in  the logback manual:

   http://logback.qos.ch/manual/filters.html

Here is my attempt at a config file doing the kind of filtering you asked for.

<configuration>
   <appender name="STDOUT"
     class="ch.qos.logback.core.ConsoleAppender">
     <filter class="ch.qos.logback.classic.filter.LevelFilter">
       <level>ERROR</level>
       <onMatch>DENY</onMatch>
       <onMismatch>ACCEPT</onMismatch>
     </filter>
     <layout class="ch.qos.logback.classic.PatternLayout">
       <pattern>
         %-4relative [%thread] %-5level %logger{30} - %msg%n
       </pattern>
     </layout>
   </appender>

  <appender name="STDERR"
     class="ch.qos.logback.core.ConsoleAppender">
     <target>System.err</target>
     <filter class="ch.qos.logback.classic.filter.LevelFilter">
       <level>ERROR</level>
       <onMatch>ACCEPT</onMatch>
       <onMismatch>DENY</onMismatch>
     </filter>
     <layout class="ch.qos.logback.classic.PatternLayout">
       <pattern>
         %-4relative [%thread] %-5level %logger{30} - %msg%n
       </pattern>
     </layout>
   </appender>

   <root>
     <level value="DEBUG" />
     <appender-ref ref="STDOUT" />
     <appender-ref ref="STDERR" />
   </root>
</configuration>

Please let us know if the above works for you,

Karnok Dávid wrote:
> Hi,
> 
>  
> 
> Is there a way to setup the loggers that any log message between DEBUG 
> and WARN goes to System.out and ERROR+FATAL goes to System.err only?
> 
>  
> 
> --------------------------------
> 
> Karnok Dávid
> 
> PhD Student

-- 
Ceki Gülcü
Logback: The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch



More information about the Logback-user mailing list