使用 Logback ServerSocketReceiver 时缺少 Spring 引导事件



症状:spring-boot 基本应用程序(没有 web、没有 jpa、没有插件(在 logback-spring.xml 中定义了一个接收器,但远程追加器事件永远不会到达本地追加器。

logback-spring.xml:

<configuration debug="true">
<receiver name="logsink" class="ch.qos.logback.classic.net.server.ServerSocketReceiver">
<port>6004</port>
</receiver>
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss} %-5level %logger{25} - %X{client} %msg %n</pattern>
</encoder>
</appender>
<appender name="crap" class="org.oclc.hadoop.logging.logbacksinksb.service.CrapAppender"/>
<root level="DEBUG">
<appender-ref ref="stdout"/>
<appender-ref ref="crap"/>
</root>
</configuration>

废话Appender被剥离到这个问题的骨架:

public class CrapAppender extends AppenderBase<ILoggingEvent> {
@Override
protected void append(ILoggingEvent eventObject) {
System.out.println("got event!");
}
}

启动时,日志显示我的组件正在实例化:

16:39:12,103 |-INFO in ch.qos.logback.classic.joran.action.ReceiverAction - About to instantiate receiver of type [ch.qos.logback.classic.net.server.ServerSocketReceiver]
16:39:12,119 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
16:39:12,119 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [stdout]
16:39:12,119 |-INFO in ch.qos.logback.classic.net.server.RemoteAppenderServerRunner@228dc826 - listening on 0.0.0.0:6004
16:39:12,120 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
16:39:12,135 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [org.oclc.hadoop.logging.logbacksinksb.service.CrapAppender]
16:39:12,135 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [crap]
16:39:12,136 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG
16:39:12,136 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [stdout] to Logger[ROOT]
16:39:12,136 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [crap] to Logger[ROOT]
16:39:12,136 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
16:39:12,136 |-INFO in org.springframework.boot.logging.logback.SpringBootJoranConfigurator@1dd02175 - Registering current configuration as safe fallback point
16:39:12,138 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@23bb8443 - Propagating INFO level on Logger[org.springframework] onto the JUL framework

我什至可以看到远程附加器已连接到接收器端口(6004(:

java      5935 jamiesoh   32u  IPv6 0xaf52811569ae62a3      0t0  TCP localhost:54160->localhost:6004 (ESTABLISHED)
java      6642 jamiesoh   53u  IPv6 0xaf52811569ae5d63      0t0  TCP *:6004 (LISTEN)
java      6642 jamiesoh   54u  IPv6 0xaf5281155d876d63      0t0  TCP localhost:6004->localhost:54160 (ESTABLISHED)

本地追加器仅发出本地事件;远程追加器永远不会到达本地垃圾追加器。

有人对阻止远程事件通过本地追加器的原因有任何想法吗?

以防万一这咬了别人,我找到了原因。 另一个工件依赖于logback-classic:1.2.3; Spring 引导版本是 1.1.11。 排除此传递依赖项纠正了该问题。

医生,治愈你自己...

相关内容

  • 没有找到相关文章

最新更新