tkowalcz / tjahzi

Java clients, log4j2 and logback appenders for Grafana Loki
MIT License
106 stars 18 forks source link

java.lang.NoSuchMethodError: pl.tkowalcz.tjahzi.log4j2.LokiAppenderBuilder.getConfiguration() - Unable to Resolve #119

Closed janskwr closed 11 months ago

janskwr commented 1 year ago

Hi! I'm encountering the following issue in my project:

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run (AbstractRunMojo.java:517)
    at java.lang.Thread.run (Thread.java:750)
Caused by: java.lang.NoSuchMethodError: pl.tkowalcz.tjahzi.log4j2.LokiAppenderBuilder.getConfiguration()Lorg/apache/logging/log4j/core/config/Configuration;

I've attempted to diagnose and resolve this issue, but I'm currently unable to find a solution (not a Java user though :c). If you have any suggestions, workarounds, or similar experiences, please share them. Thanks in advance!

tkowalcz commented 1 year ago

Hi! It seems to be a conflict of log4j2 versions. Can you check which versions of log4j2 are on your classpath?

tkowalcz commented 1 year ago

It seems that this is due to issue described here: https://stackoverflow.com/a/40389834.

Tjahzi is built against log4j2 2.17.2. If you use log4j2 2.6 then these two are not compatible. I don't see how this could be resolved on the library side, you should probably upgrade Spring Boot and or log4j2 dependency.

janskwr commented 1 year ago

Firstly, thank you so much for responding. I forgot to look inside parent's pom.xml (new to Java). I'm using versions:

According to the stackoverflow link you provided, everything should work fine I guess, but I'm getting this error anyway. Is Tjahzi compatible with log4j2 version 2.7?

tkowalcz commented 1 year ago

That makes sense. The 0.9.17 version of Tjahzi is very old and it indeed used log4j2 2.6. It uses log4j2 2.7 since version 0.9.20 while current version of Tjahzi is 0.9.31. Please upgrade to newest version and it should work correctly.

janskwr commented 1 year ago

Unfortunately, it didn't help. I'm getting the same error (tried 0.9.20 version and 0.9.31 version).

tkowalcz commented 1 year ago

Are you using maven to build your app? If yes then can you paste the output of mvn dependency:tree?

janskwr commented 1 year ago

Yes, I'm using Maven. Actually, I'm working at the Big Tech company, and it would probably be considered as a data leakage. I can send some fragments, though. What parts of mvn dependency:tree would you like to see?

tkowalcz commented 1 year ago

Sure, I am only looking for lines containing log4j2 or tjahzi with associated versions. In case something is fishy you might spot it yourself, otherwise it should help pinpointing the issue.

janskwr commented 1 year ago

Thanks for help!

Tjahzi:

[INFO] +- pl.tkowalcz.tjahzi:log4j2-appender-nodep:jar:0.9.20:compile
[INFO] |  \- org.apache.logging.log4j:log4j-api:jar:2.7:compile

Log4j2:

[INFO] +- org.springframework.boot:spring-boot-starter-log4j2:jar:2.7.9:compile
[INFO] |  +- org.apache.logging.log4j:log4j-slf4j-impl:jar:2.7:compile
[INFO] |  +- org.apache.logging.log4j:log4j-core:jar:2.7:compile
[INFO] |  +- org.apache.logging.log4j:log4j-jul:jar:2.7:compile
[INFO] |  \- org.slf4j:jul-to-slf4j:jar:1.7.26:compile

Let me know if you spot something! I will try to resolve it today using trial-and-error method :))

tkowalcz commented 1 year ago

Were you able to fixe the issue? I created a simple project with dependencies that you use and it seems to work correctly.