2013-10-14 78 views
3

我想从服务器上的客户端应用程序接收日志。 我已经尝试了logback-examples项目中提供的标准'receiver'配置。如何使用Logback正确配置ServerSocketReceiver

<configuration debug="true"> 

    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> 
    <encoder> 
     <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern> 
    </encoder> 
    </appender> 

    <root level="DEBUG"> 
    <appender-ref ref="CONSOLE" /> 
    </root> 

    <receiver class="ch.qos.logback.classic.net.server.ServerSocketReceiver"> 
    <port>6000</port> 
    </receiver> 

</configuration> 

的logback时分析此文件,它提供了以下错误:

16:28:09,067 |-ERROR in [email protected]:76 - no applicable action for [receiver], current pattern is [[configuration][receiver]] 
16:28:09,068 |-ERROR in [email protected]:11 - no applicable action for [port], current pattern is [[configuration][receiver][port]] 

我很茫然,什么是错误的配置。 我有:SLF4J-API-1.7.5,的logback经典-1.0.9,的logback核-1.0.9

不出所料客户端登录失败发送到服务器:

16:30:39,052 |-INFO in ch.qos.logback.classic.net.SocketAppender[SERVER] - Could not connect to remote logback server at [MAGENTA.comrad.local]. We will try again later. java.net.ConnectException: Connection refused: connect 
    at java.net.ConnectException: Connection refused: connect 
    at at java.net.PlainSocketImpl.socketConnect(Native Method) 
    at at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351) 
+0

这个特定的服务器是做这一项任务吗?即接收消息并记录它们?如果是这样,你是否运行SimpleSocketServer?如果是这样,则不需要定义Receiver。 –

+1

我设法让SimpleSocketServer工作。不过,我不想要一个单独的独立程序。我宁愿使用现有的服务器应用程序进行日志记录。因此需要在logback.xml中将其配置为接收者。 (假设我已经正确理解了该手册) – giorgio

回答

1

的我得到错误的原因是我链接到了logback 1.0.9。 接收器功能只在1.012以上。