[logback-user] How To Use Filters

Ceki Gülcü listid at qos.ch
Wed Dec 20 21:46:00 CET 2006


Thanks for using logback.

You can instruct logback-classic to tell you to print its internal
status with the following call:


This will print logback's internal error messages on the console.

You can achieve a similar affect in configuration files by setting the
debug attribute of the configuration element to true. For example:

<configuration debug="true">   <--- this line
   <appender name="STDOUT"
     <layout class="ch.qos.logback.classic.PatternLayout">
         %d{HH:mm:ss.SSS} [%thread] %-5level %logger{32} - %msg%n
     <level value="DEBUG" />
     <appender-ref ref="STDOUT" />

When logback is done configuring itself using the above config file,
it will dump its internal status on the console.

Anyway, I'd first try invoking LoggerStatusPrinter's
printStatusInDefaultContext() after  the

   logger.debug(pcMarker, "Cnfiguration...")

call and see what logback tells you.

My guess is that it will complain about exceptions thrown by the
expression evaluator because marker is null. Try changing the
expressions to

    <evaluator name="myEval">
      <expression>(marker != null) &amp;&amp; 

The &amp;&amp; combination represents Java's expression for logical AND,
that is '&&', which you cannot write as is in XML files.

Please let us know how it goes.

At 08:18 PM 12/20/2006, Yoram Forscher wrote:
>After reading chapter 6, “Filter Chains,” I tried to use some filters 
>myself with no success. My configuration file contains the following:
><appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
><filter class="ch.qos.logback.core.filter.EvaluatorFilter">
>                         <evaluator name="myEval">
>                         </evaluator>
>                         <OnMismatch>NEUTRAL</OnMismatch>
>                         <OnMatch>DENY</OnMatch>
>             </filter>
>             <layout class="ch.qos.logback.classic.PatternLayout">
>                         <param name="pattern" value="%d{ISO8601} %-5p 
> [%c{40}] %m%n"/>
>             </layout>
>In my code I have the following:
>private Marker pcMarker = MarkerFactory.getMarker("printConfiguration");

>logger.debug(pcMarker, “Configuration Information”);

>I expect in that case that no output will be created, but it keeps 
>printing it regardless of how I set it up. I also tried to change the 
>expression to ‘marker.contains(“printConfiguration”)’ and change the 
>OnMismatch and OnMatch both to DENY. Same result.
>What am I doing wrong?

Ceki Gülcü
Logback: The reliable, generic, fast and flexible logging framework for Java.

More information about the Logback-user mailing list