首页 > 解决方案 > 如何设置 FailureSummaryLoggingAppenderListener 以便我知道我的异步 appender 何时删除了日志消息

问题描述

我在大量使用 logback/slf4j 进行日志记录的应用程序上工作。我正在研究使用异步附加程序来增加吞吐量。但是,如果我丢失了日志消息,我想得到一些指示。

我的印象是以下内容是关键:https ://github.com/logstash/logstash-logback-encoder/blob/main/src/main/java/net/logstash/logback/appender/listener /FailureSummaryLoggingAppenderListener.java

但是,我无法将其集成到我们的 logback 配置中。

我们的 logback.xml 文件看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="5 seconds" debug="true">
  <include file=".../baselogback.xml"/>
  <appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
    <appender-ref ref="STDOUT" />
    <listener class="net.logstash.logback.appender.listener.FailureSummaryLoggingAppenderListener"/>
    <discardingThreshold>0</discardingThreshold>
    <queueSize>256</queueSize>
    <includeCallerData>false</includeCallerData>
    <neverBlock>false</neverBlock>
  </appender>
  <logger name="..." level="DEBUG" additivity="false">
    <appender-ref ref="ASYNC"/>
  </logger>
  <logger name="..." level="DEBUG" additivity="false">
    <appender-ref ref="STDOUT"/>
  </logger>
  <root level="INFO">
    <appender-ref ref="STDOUT"/>
  </root>
</configuration>

在添加“侦听器”行之前,我能够测试服务并验证它是否正确记录事务。当我添加该“侦听器”时,它在启动时失败,并显示以下内容:

Logging system failed to initialize using configuration from '.../logback.xml'
java.lang.IllegalStateException: Logback configuration error detected: 
ERROR in ch.qos.logback.core.joran.spi.Interpreter@5:101 - no applicable action for [listener], current ElementPath  is [[configuration][appender][listener]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@5:101 - no applicable action for [listener], current ElementPath  is [[configuration][appender][listener]]
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:169)

我在这里想念什么?

更新

我想我在这里缺少的是这只适用于 TCP 附加程序,而不是控制台附加程序。有没有办法让这样的东西适用于控制台附加程序?

标签: javalogback

解决方案


推荐阅读