0

我正在尝试从我的 Logback 日志记录中过滤掉“net.schmizz.concurrent.Promise”类。我试过两种方法,都不管用。我的 logback.xml 看起来像这样:

<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
    <filter class="com.websudos.loggers.ClassNameFilter">
        <className>net.schmizz.concurrent.Promise</className>
        <onMatch>DENY</onMatch>
    </filter>
    <param name="Target" value="System.out"/>
    <encoder>
        <pattern>%date %-4relative [%thread] %-5level %logger{35} - %msg %n</pattern>
    </encoder>
</appender>

<appender name="debugfile" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>debugFile.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>debugFile.%d{yyyy-MM-dd}.log</fileNamePattern>
        <MaxHistory>30</MaxHistory>
    </rollingPolicy>
    <encoder>
        <pattern>%date %-4relative [%thread] %-5level %logger{35} - %msg %n</pattern>
    </encoder>
</appender>

<filter class="com.websudos.loggers.ClassNameFilter">
    <className>net.schmizz.concurrent.Promise</className>
    <onMatch>DENY</onMatch>
</filter>

<!-- Setup the Root category -->
<root level="DEBUG">
    <appender-ref ref="console"/>
    <appender-ref ref="debugfile"/>
</root>

这会产生以下日志文​​件:

2020-11-06 09:12:54,063 1566 [main] DEBUG n.s.sshj.transport.TransportImpl - Sending SSH_MSG_DISCONNECT: reason=[BY_APPLICATION], msg=[] 
2020-11-06 09:12:54,063 1566 [main] DEBUG net.schmizz.concurrent.Promise - Setting <<transport close>> to `SOME` 
2020-11-06 09:12:54,063 1566 [main] DEBUG o.m.D.DownloadWebSiteBackups - Successfully finished DownloadWebSiteBackups 
2020-11-06 09:12:54,063 1566 [reader] DEBUG net.schmizz.sshj.transport.Reader - Stopping 

正如您从第二个日志语句中看到的那样,两个过滤器都不起作用。为什么不?

编辑:以下代码有效,但我更喜欢在 logback.xml 文件中进行:

ch.qos.logback.classic.Logger logger = ( ch.qos.logback.classic.Logger ) LoggerFactory.getLogger( "net.schmizz" );
logger.setLevel( Level.INFO );
4

1 回答 1

0

发现错误。它应该看起来像:

<filter class="ch.qos.logback.classic.filter.LevelFilter">
    <className>net.schmizz.concurrent.Promise</className>
    <level>DEBUG</level>
    <onMatch>DENY</onMatch>
    <onMismatch>ACCEPT</onMismatch>
</filter>

过滤器类名错误,级别丢失。

于 2020-11-08T19:16:19.960 回答