Handlebars-proto 和 logstash-logback-encoder slf4j 冲突

Handlebars-proto and logstash-logback-encoder slf4j conflict

我的项目使用 handlebars-proto 将模板绑定到 json。此外,我正在尝试使用 logstash-logback-encoder 以 Json 的形式登录 logstash。以下是我的编译依赖项(以及其他依赖项)

   compile 'net.logstash.logback:logstash-logback-encoder:4.6'
   compile 'com.github.jknack:handlebars-proto:4.0.5'

如果我删除 handlebars 依赖项日志记录工作正常。如果存在车把,我会收到以下警告:

SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/C:/Users/manish/.gradle/caches/modules-2/files-2.1/com.github.jknack/handlebars-proto/4.0.5/5979737344d99e0d8b482e828f247ae86fd0113/handlebars-proto-4.0.5.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/Users/manish/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.1.6/665e3de72f19ec66ac67d82612d7b8e6b3de3cd0/logback-classic-1.1.6.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

后跟错误:

Failed to instantiate [ch.qos.logback.classic.LoggerContext] Reported exception: java.lang.NoSuchMethodError: ch.qos.logback.core.spi.ContextAwareBase.(Lch/qos/logback/core/spi/ContextAware;)V at net.logstash.logback.composite.CompositeJsonFormatter.(CompositeJsonFormatter.java:106) at net.logstash.logback.composite.loggingevent.LoggingEventCompositeJsonFormatter.(LoggingEventCompositeJsonFormatter.java:28) at net.logstash.logback.LogstashFormatter.(LogstashFormatter.java:122) at net.logstash.logback.LogstashFormatter.(LogstashFormatter.java:118) at net.logstash.logback.LogstashFormatter.(LogstashFormatter.java:114) at net.logstash.logback.encoder.LogstashEncoder.createFormatter(LogstashEncoder.java:31) at net.logstash.logback.encoder.CompositeJsonEncoder.(CompositeJsonEncoder.java:48) at net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder.(LoggingEventCompositeJsonEncoder.java:23) at net.logstash.logback.encoder.LogstashEncoder.(LogstashEncoder.java:27) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at java.lang.Class.newInstance(Class.java:379) at ch.qos.logback.core.joran.action.NestedComplexPropertyIA.begin(NestedComplexPropertyIA.java:122) at ch.qos.logback.core.joran.spi.Interpreter.callBeginAction(Interpreter.java:276) at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:148) at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:130) at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:50)

我尝试将 slf4j 排除在车把的传递依赖之外,但是 它没有帮助。

compile
 ('com.github.jknack:handlebars-proto:4.0.5'){

 exclude module: 'slf4j-api' 

 }

在此先感谢您的帮助。如果需要更多详细信息,请告诉我。

错误消息是因为 handlebars-proto jar 包含 org.slf4j.impl.StaticLoggerBinder 的实现,这意味着它具有日志记录实现。您还试图添加您自己的 Logback 日志记录实现,并且由于 SLF4J 不能同时使用两个日志记录系统,它正在抱怨。

我不熟悉 handlebars 项目,但我猜你那里的库是一个包含日志系统的完整应用程序,并不是真正设计为被另一个项目用作依赖项。也许有一个不同的版本可用,它只是库,并没有尝试包含它自己的日志记录实现?