0

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

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>

对于这个问题,crapAppender 被剥离为最基本的:

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)

本地 appender 只发出本地事件;远程附加程序永远不会到达本地垃圾附加程序。

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

4

1 回答 1

0

以防万一这咬别人,我找到了原因。其他工件之一依赖于 logback-classic:1.2.3; spring-boot 版本是 1.1.11。排除这种传递依赖可以解决问题。

医生,给自己疗伤...

于 2017-08-11T17:17:41.300 回答