2017-08-09 93 views
0

症狀:spring-boot基本應用程序(沒有web,沒有jpa,沒有插件)在logback-spring.xml中定義了一個接收器,但遠程appender事件從未到達本地appender。缺少使用Logback ServerSocketReceiver的彈簧引導事件

的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 [email protected]dc826 - 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.s[email protected]1dd02175 - Registering current configuration as safe fallback point 
16:39:12,138 |-INFO in [email protected] - Propagating INFO level on Logger[org.springframework] onto the JUL framework 

我甚至可以看到rem ote appender已連接到接收端口(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只發出本地事件;遠程appender永遠不會到達當地廢話appender。

任何人有什麼想法防止遠程事件通過本地appender?

回答

0

爲了防止咬人,我找到了原因。其他工件之一依賴於logback-classic:1.2.3; spring-boot版本是1.1.11。排除這種傳遞性依賴糾正了這個問題。

醫生,治癒你自己...