将阈值筛选器添加到 Logback <配置 debug= "true" >输出?



任何想法如何在记录本身的调试消息上设置阈值过滤器?

<configuration debug="true">
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} %-5level [%thread] [%logger{0}] [%M:%L] - %m%n</pattern>
        </encoder>
    </appender>
    ...
    <root level="TRACE">
        <appender-ref ref="STDOUT" />
        <appender-ref ref="ASYNC_SLACK_LOGS" />
    </root>
</configuration>

以上产生详细调试输出:

16:05:16,479 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
16:05:16,480 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback-test.xml] at [file:/W:/JavaProjects/logback-slack-appender/target/test-classes/logback-test.xml]
16:05:16,697 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
16:05:16,703 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
...
6:05:16,825 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@2d901eb0 - Registering current configuration as safe fallback point
16:05:17.696 INFO  [main] [SlackAppenderTest] [simulateAPITrouble:19] - This will fail to post to Slack
16:05:18.256 |-ERROR in com.github.maricn.logback.SlackAppender[SLACK_LOGS] - Slack POST request failed: 404 no_team

如何将调试输出限制为仅记录核心错误?例如:

16:05:17.696 INFO  [main] [SlackAppenderTest] [simulateAPITrouble:19] - This will fail to post to Slack
16:05:18.256 |-ERROR in com.github.maricn.logback.SlackAppender[SLACK_LOGS] - Slack POST request failed: 404 no_team

原因是因为我想在其他人的附录中捕获各种addError()调用的输出(理想地将捕获到文件附录(,但我不希望在应用程序启动上所有详细信息。<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<</p>

这看起来很有希望,但是没有设置可以控制控制台消息的粒度。

<configuration debug="false">
    <statusListener class="ch.qos.logback.core.status.OnErrorConsoleStatusListener" />
    ...

相反,我创建了一个自定义的概念验证状态侦听器:

import ch.qos.logback.core.status.Status;
import ch.qos.logback.core.status.StatusListener;
public class ErrorStatusListener implements StatusListener
{
    @Override
    public void addStatusEvent( Status status )
    {
        if ( status.getLevel() >= Status.WARN )
            System.out.println( status.getMessage() );
    }
}

现在,我也可以控制错误消息,然后将它们送回日志式管道,以由文件Appender拾取。

17:40:32.336 INFO  [main] [SlackAppenderTest] [simulateAPITrouble:21] - This will fail to post to Slack
Slack POST request failed: 404, no_team

相关内容

  • 没有找到相关文章

最新更新