Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

logback ThresholdFilter how todo the opposite

Tags:

logback

I need a filter that only passes through everything info and LESS instead of info and more. I have seen this done somewhere before in logback. My full xml is here and I want info and less to go to stdout (without writing a filter as I know that was possible somehow)...

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> 
        <level>info</level>
    </filter>

    <layout class="ch.qos.logback.classic.PatternLayout">
        <pattern>%date{ISO8601} %X{sessionid}-%X{user} %caller{1} %-4level: %message%n</pattern>
    </layout>
</appender>

<appender name="STDERR" class="ch.qos.logback.core.ConsoleAppender">
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> 
        <level>warn</level>
    </filter>

    <layout class="ch.qos.logback.classic.PatternLayout">
        <pattern>%date{ISO8601} %X{sessionid}-%X{user} %caller{1} %-4level: %message%n</pattern>
    </layout>
    <target>System.err</target>
</appender>
like image 718
Dean Hiller Avatar asked Nov 01 '12 14:11

Dean Hiller


People also ask

How do you filter Logback logs?

In logback-classic, filters can be added to Appender instances. By adding one or more filters to an appender, you can filter events by arbitrary criteria, such as the contents of the log message, the contents of the MDC, the time of day or any other part of the logging event.

What is Appender in Logback?

Appenders place log messages in their final destinations. A Logger can have more than one Appender. We generally think of Appenders as being attached to text files, but Logback is much more potent than that. Layout prepares messages for outputting.

What is Logback?

Logback is a logging framework for Java applications, created as a successor to the popular log4j project.


1 Answers

figured it out finally....

<?xml version="1.0" encoding="UTF-8" ?>
<configuration scan="true" scanPeriod="30 seconds">
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <filter class="ch.qos.logback.core.filter.EvaluatorFilter">      
          <evaluator class="ch.qos.logback.classic.boolex.GEventEvaluator"> 
            <expression>
               e.level.toInt() &lt;= INFO.toInt()
            </expression>
          </evaluator>
          <OnMismatch>DENY</OnMismatch>
          <OnMatch>NEUTRAL</OnMatch>
        </filter>

        <encoder>
            <pattern>%date{ISO8601} %X{sessionid}-%X{user} %caller{1} %-4level: %message%n</pattern>
        </encoder>
    </appender>

    <appender name="STDERR" class="ch.qos.logback.core.ConsoleAppender">
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> 
            <level>warn</level>
        </filter>

        <encoder>
            <pattern>%date{ISO8601} %X{sessionid}-%X{user} %caller{1} %-4level: %message%n</pattern>
        </encoder>
        <target>System.err</target>
    </appender>

    <appender name="TEMP" class="com.alvazan.play.logging.CassandraAppender">
        <appender-ref ref="STDOUT"/>
    </appender>

    <root>
        <level value="INFO" />
        <appender-ref ref="STDOUT"/>
        <appender-ref ref="STDERR"/>
        <!-- appender-ref ref="TEMP"/-->
    </root>
</configuration>
like image 134
Dean Hiller Avatar answered Sep 23 '22 22:09

Dean Hiller