logback ThresholdFilter如何反转

时间:2012-11-01 14:59:13

标签: logback

我需要一个只能通过所有信息和LESS而不是信息等的过滤器。我已经在logback中看到过这个问题。我的完整xml在这里,我想要信息,而不是去stdout(没有编写过滤器,因为我知道这可能是某种方式)......

<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>

1 个答案:

答案 0 :(得分:7)

终于弄清楚了......

<?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>