Is there an adapter for log4j2 to work on slf4j?

I have a third-party library (elasticsearch 5.x) that uses log4j2. My application uses slf4j. Is there an adapter for version 2 of log4j similar to adapter of version 1 (log4j-over-slf4j)?

Just to clarify: I don't want to use log4j or log4j2 as the actual implementation (binding). I use logback for this. So I need a log4j2 adapter for slf4j, not a slf4j binding.

I should also note that I found and tried this library (in version 2.0 beta): https://logging.apache.org/log4j/2.0/log4j-to-slf4j/index.html but it gives me this error:

Caused by: java.lang.AbstractMethodError: org.apache.logging.slf4j.SLF4JLoggerContextFactory.getContext(Ljava/lang/String;Ljava/lang/ClassLoader;Ljava/lang/Object;Z)Lorg/apache/logging/log4j/spi/LoggerContext; at org.apache.logging.log4j.LogManager.getContext(LogManager.java:175) at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:426) at org.elasticsearch.common.logging.ESLoggerFactory.getLogger(ESLoggerFactory.java:49) at org.elasticsearch.common.logging.Loggers.getLogger(Loggers.java:105) at org.elasticsearch.common.logging.Loggers.getLogger(Loggers.java:72) at org.elasticsearch.common.component.AbstractComponent.<init>(AbstractComponent.java:37) at org.elasticsearch.plugins.PluginsService.<init>(PluginsService.java:98) at org.elasticsearch.client.transport.TransportClient.newPluginService(TransportClient.java:99) at org.elasticsearch.client.transport.TransportClient.buildTemplate(TransportClient.java:124) at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:258) at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:125) at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:111) at org.elasticsearch.transport.client.PreBuiltTransportClient.<init>(PreBuiltTransportClient.java:101) 

EDIT : Okay .. so I think I was blind yesterday and I saw a beta version of this library. Therefore, the answer is that there is an adapter, and it is here:

https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-to-slf4j https://logging.apache.org/log4j/2.0/log4j-to-slf4j/index.html

The latest version is currently 2.8.2

+5
source share
3 answers

Log4j2 itself binds the slf4j implementation (log4j-slf4j-impl-2.x.jar)

This is one of the cans in the Log4j2 distribution .


Update after clarifying the issue:

Log4j2 includes the log4j -to-slf4j bridge . "This is what you need to route Log4j2 to another slf4j implementation.

The indicated error is probably the problem of incompatible versions, but the issue does not mention version numbers, so it's hard to say.

-1
source

I think you can choose two libraries. You can take it from: http://www.java2s.com/Code/Jar/l/Downloadlog4jjar.htm or https://logging.apache.org/log4j/2.0/download.html or other.

0
source

You must enable log4j-to-slf4j-2.x.jar and ensure that log4j-to-slf4j-2.x.jar is not included . See Log4j to SLF4J Adapter for details .

0
source

Source: https://habr.com/ru/post/1267293/


All Articles