[logback-user] How To Use Filters

Sebastien Pennec sebastien at qos.ch
Wed Jan 3 17:41:13 CET 2007


Hello Yoram,

Happy new year to you :)

I've searched for a while and still cannot reproduce the same status output with 
version 0.7.1.
I've eventually tried with older versions, and found that version 0.5 of logback 
outputs _exactly_ the same lines that you included in your last email.

Could you make really sure that you are using version 0.7.1 before we go into further 
investigations?

You can check that by editing the pom.xml that is inside the jars. If you open the 
logback-core jar, you will find it in this directory:

$LOGBACK_JAR/META-INF/maven/ch.qos.logback/logback-core/pom.xml

At the beginning of the file, you should see these lines if you're using version 0.5:

<parent>
   <artifactId>logback</artifactId>
   <groupId>ch.qos.logback</groupId>
   <version>0.5</version>
</parent>

and these if you're using version 0.7.1:

<parent>
   <groupId>ch.qos.logback</groupId>
   <artifactId>logback-parent</artifactId>
   <version>0.7.1</version>
</parent>

Let me know what comes out...

One more thing about the jars that you will need. If you want to use evaluation 
filters, you will need the Janino jar as well as the logback jars, since Janino is a 
logback dependency. You will find them at the Janino home page[1].

Cheers,

Sébastien

[1]http://www.janino.net/download.html#packages

Yoram Forscher wrote:
> Hi Sebastien,
> 
> Sorry for the long delay due to the holiday season. Here's the information that you requested:
> * The version of logback that I'm using is 0.7.1
> * The full configuration file is:
> 
> <?xml version="1.0" encoding="UTF-8" ?>
> <configuration debug="true">
>   <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
>     <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
>       <evaluator name="myEval" >
>         <expression>
>           (marker != null) &amp;&amp;
>             (marker.contains("printConfiguration"))
>         </expression>
>       </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>
>   </appender>
> 
>   <root>
>     <level value="debug"/>
>     <appender-ref ref="STDOUT"/>
>   </root>
> 
>   <logger name="org.apache">
> 	<level value="info"/>
>   </logger>
> 
> </configuration>
> 
> * Even though I specified 'debug="true",' I did not get any debug output until I invoked LoggerStatusPrinter.printStatusInDefaultContext();
> 
> * The information output by the LoggerStatusPrinter is:
> |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
> |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
> |-INFO in ch.qos.logback.core.joran.action.NestedComponentIA - is dmmed applicable for /configuration/appender/filter
> |-INFO in ch.qos.logback.core.joran.action.NestedComponentIA - Pushing component <filter> on top of the object stack.
> |-INFO in ch.qos.logback.core.joran.action.NestedComponentIA - is dmmed applicable for /configuration/appender/filter/evaluator
> |-ERROR in ch.qos.logback.core.joran.action.NestedComponentIA - No class name attribute in <evaluator>
> |-ERROR in ch.qos.logback.core.joran.spi.InterpretationContext at 5ff916 - no applicable action for <expression>, current pattern is [/configuration/appender/filter/evaluator/expression]
> |-ERROR in ch.qos.logback.core.joran.spi.InterpretationContext at 5ff916 - no applicable action for <OnMatch>, current pattern is [/configuration/appender/filter/OnMatch]
> |-ERROR in ch.qos.logback.core.filter.EvaluatorFilter at da3772 - No evaluator set for filter null
> |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Popping appender named [STDOUT] from the object stack
> |-INFO in ch.qos.logback.classic.joran.action.LevelAction - root level set to DEBUG
> |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT to Logger[root]
> |-INFO in ch.qos.logback.classic.joran.action.LevelAction - org.apache level set to INFO
> |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
> 
> * One more thing: My application runs as a Web Application under Tomcat and is also using Spring. The logback JAR files (classic and core) as well as alf4j-api JAR file are in WEB-INF/lib. The configuration file is in WEB-INF.
> 
> Thanks,
> 
> Yoram
>  
> -----Original Message-----
> From: Sebastien Pennec [mailto:sebastien at qos.ch] 
> Sent: Friday, December 22, 2006 6:12 AM
> To: logback users list
> Subject: Re: [logback-user] How To Use Filters
> 
> Hello Yoram,
> 
> Thanks for posting the status messages.
> 
> I am having a hard time reproducing these messages based on the configuration that 
> you posted previously. Could you post the entire output, and your complete 
> configuration file?
> 
> Also, could you tell me which version of logback are you using?
> 
> Cheers,
> 
> Sébastien
> 
> 
> Yoram Forscher wrote:
>> Thanks for the prompt reply. 
>> I changed the configuration file as you suggested and invoked LoggerStatusPrinter.printStatusInDefaultContext() after the logging request. I received a lot of output and I included below the four lines that indicated an error.
>>
>> The filter still does not give me the result that I'm looking for. I appreciate any help you can give me.
>>
>> --
>> Yoram
>>
>> |-ERROR in ch.qos.logback.core.joran.action.NestedComponentIA - No class name attribute in <evaluator>
>> |-ERROR in ch.qos.logback.core.joran.spi.InterpretationContext at 1762fc7 - no applicable action for <expression>, current pattern is [/configuration/appender/filter/evaluator/expression]
>> |-ERROR in ch.qos.logback.core.joran.spi.InterpretationContext at 1762fc7 - no applicable action for <OnMatch>, current pattern is [/configuration/appender/filter/OnMatch]
>> |-ERROR in ch.qos.logback.core.filter.EvaluatorFilter at 3aef16 - No evaluator set for filter null
>> |
>>
>> -----Original Message-----
>> From: Ceki Gülcü [mailto:listid at qos.ch] 
>> Sent: Wednesday, December 20, 2006 3:46 PM
>> To: logback users list
>> Subject: Re: [logback-user] How To Use Filters
>>
>>
>> Yoram,
>>
>> Thanks for using logback.
>>
>> You can instruct logback-classic to tell you to print its internal
>> status with the following call:
>>
>>    LoggerStatusPrinter.printStatusInDefaultContext();
>>
>> 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"
>>              class="ch.qos.logback.core.ConsoleAppender">
>>      <layout class="ch.qos.logback.classic.PatternLayout">
>>        <pattern>
>>          %d{HH:mm:ss.SSS} [%thread] %-5level %logger{32} - %msg%n
>>        </pattern>
>>      </layout>
>>    </appender>
>>    <root>
>>      <level value="DEBUG" />
>>      <appender-ref ref="STDOUT" />
>>    </root>
>> </configuration>
>>
>>
>> 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; 
>> (marker.contains("printConfiguration"))</expression>
>>     </evaluator>
>>     <OnMismatch>NEUTRAL</OnMismatch>
>>     <OnMatch>DENY</OnMatch>
>>
>> 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">
>>>
>>> <expression>marker.getName().equals("printConfiguration")</expression>
>>>                         </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>
>>> </appender>
>>>
>>> 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?
> 

-- 
Sébastien Pennec
sebastien at qos.ch

Logback: The reliable, generic, fast and flexible logging framework for Java.
http://logback.qos.ch/



More information about the Logback-user mailing list