使用标记的logstash-logback-encoder错误

时间:2018-03-31 09:59:54

标签: java logging wildfly logback logstash-logback-encoder

使用slf4j.Marker时,我收到了java.lang.IncompatibleClassChangeError。看来我在classpath中有几个slf4j版本。但是当执行maven依赖时:树它说只有slf4j 1.7.25。你们有什么想法可能是什么问题吗?依赖关系如下:

  • logback 1.2.3
  • slf4j 1.7.25
  • logstash-logback-encoder 5.0

该应用程序部署在WildFlly 8.2.1 AS上。

> -ERROR in net.logstash.logback.appender.LogstashTcpSocketAppender[stash] - Unable to process event: Class net.logstash.logback.marker.ObjectAppendingMarker does not implement the requested interface org.slf4j.Marker java.lang.IncompatibleClassChangeError: Class net.logstash.logback.marker.ObjectAppendingMarker does not implement the requested interface org.slf4j.Marker
> 
> 2018-03-31 00:17:03,287 INFO  [stdout] (logback-appender-stash-127.0.0.1:4560-2)  at java.lang.IncompatibleClassChangeError: Class net.logstash.logback.marker.ObjectAppendingMarker does not implement the requested interface org.slf4j.Marker
> 
> 2018-03-31 00:17:03,287 INFO  [stdout] (logback-appender-stash-127.0.0.1:4560-2)  at  at net.logstash.logback.composite.loggingevent.JsonMessageJsonProvider.writeTo(JsonMessageJsonProvider.java:52)
> 
> 2018-03-31 00:17:03,287 INFO  [stdout] (logback-appender-stash-127.0.0.1:4560-2)  at  at net.logstash.logback.composite.loggingevent.JsonMessageJsonProvider.writeTo(JsonMessageJsonProvider.java:31)
> 
> 2018-03-31 00:17:03,287 INFO  [stdout] (logback-appender-stash-127.0.0.1:4560-2)  at  at net.logstash.logback.composite.JsonProviders.writeTo(JsonProviders.java:77)
> 
> 2018-03-31 00:17:03,287 INFO  [stdout] (logback-appender-stash-127.0.0.1:4560-2)  at  at net.logstash.logback.composite.CompositeJsonFormatter.writeEventToGenerator(CompositeJsonFormatter.java:175)
> 
> 2018-03-31 00:17:03,288 INFO  [stdout] (logback-appender-stash-127.0.0.1:4560-2)  at  at net.logstash.logback.composite.CompositeJsonFormatter.writeEventToOutputStream(CompositeJsonFormatter.java:152)
> 
> 2018-03-31 00:17:03,288 INFO  [stdout] (logback-appender-stash-127.0.0.1:4560-2)  at  at net.logstash.logback.encoder.CompositeJsonEncoder.encode(CompositeJsonEncoder.java:114)
> 
> 2018-03-31 00:17:03,288 INFO  [stdout] (logback-appender-stash-127.0.0.1:4560-2)  at  at net.logstash.logback.encoder.CompositeJsonEncoder.encode(CompositeJsonEncoder.java:32)
> 
> 2018-03-31 00:17:03,288 INFO  [stdout] (logback-appender-stash-127.0.0.1:4560-2)  at  at net.logstash.logback.appender.AbstractLogstashTcpSocketAppender$TcpSendingEventHandler.onEvent(AbstractLogstashTcpSocketAppender.java:454)
> 
> 2018-03-31 00:17:03,288 INFO  [stdout] (logback-appender-stash-127.0.0.1:4560-2)  at  at net.logstash.logback.appender.AbstractLogstashTcpSocketAppender$TcpSendingEventHandler.onEvent(AbstractLogstashTcpSocketAppender.java:264)
> 
> 2018-03-31 00:17:03,288 INFO  [stdout] (logback-appender-stash-127.0.0.1:4560-2)  at  at net.logstash.logback.appender.AsyncDisruptorAppender$EventClearingEventHandler.onEvent(AsyncDisruptorAppender.java:330)
> 
> 2018-03-31 00:17:03,288 INFO  [stdout] (logback-appender-stash-127.0.0.1:4560-2)  at  at net.logstash.logback.appender.AsyncDisruptorAppender$EventClearingEventHandler.onEvent(AsyncDisruptorAppender.java:318)
> 
> 2018-03-31 00:17:03,288 INFO  [stdout] (logback-appender-stash-127.0.0.1:4560-2) 

1 个答案:

答案 0 :(得分:1)

嗯,你是对的,因为classpath中的几个slf4j版本出现了这个问题

现在我们需要了解它是如何发生的

案例1:

当我查看logback 1.2.3的maven reporitory时,我发现它已经依赖于slf4j。

因此,当您加载logback 1.2.3时,将自动添加slf4j

所以你不需要在pom中添加额外的slf4j,如果你这样做,请将其删除。

有关详细信息,请参阅link - 编译Depencencies:

案例2:

查看wildfly/modules/system/layers/base/org/slf4j

文件夹查看是否已添加任何slf4j罐子。如果是这样,你只需要编译

就需要slf4j

添加<scope>compile</scope>