aws / aws-sdk-java-v2

The official AWS SDK for Java - Version 2
Apache License 2.0
2.16k stars 840 forks source link

Failure to log with SLF4J #5312

Open janvanbesien-ngdata opened 3 months ago

janvanbesien-ngdata commented 3 months ago

Describe the bug

SLF4J logging does not work.

Expected Behavior

I expect no SLF4J warnings and working logging.

Current Behavior

SLF4J logging fails to initialize with this output:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

Reproduction Steps

The problem can easily be reproduced by triggering the slf4j initialization in jshell with the AWS SDK bundle jar and an SLF4j impl on the classpath:

$ CLASSPATH=~/.m2/repository/software/amazon/awssdk/bundle/2.26.5/bundle-2.26.5.jar:~/.m2/repository/org/slf4j/slf4j-simple/2.0.7/slf4j-simple-2.0.7.jar jshell
|  Welcome to JShell -- Version 21.0.3
|  For an introduction type: /help intro

jshell> software.amazon.awssdk.thirdparty.org.slf4j.impl.StaticLoggerBinder.getSingleton()
|  Exception java.lang.NoClassDefFoundError: software.amazon.awssdk.thirdparty.org.slf4j.impl.StaticLoggerBinder
|        at StaticLoggerBinder.getSingleton (StaticLoggerBinder.java:72)
|        at (#1:1)

jshell> 

Note that the NoClassDefFoundError is thrown by the StaticLoggerBinder (from the bundle-logging-bridge module) because it tries to load "org.slf4j.impl.StaticLoggerBinder", but that was shaded to "software.amazon.awssdk.thirdparty.org.slf4j.impl.StaticLoggerBinder"? Or maybe the intention is to load the actual org.slf4j.impl.StaticLoggerBinder from slf4j, but that doesn't seem to work either (cfr the slf4j-simpler jar on the classpath).

Possible Solution

not sure.

Additional Information/Context

No response

AWS Java SDK version used

2.26.5

JDK version used

21.0.3

Operating System and version

Fedora 40

janvanbesien-ngdata commented 3 months ago

I just realized that there is no StaticLoggerBinder in slf4j 2.0. So the problem is most likely simply that only slf4j 1.7 is supported? Is an upgrade to slf4j 2.0 on the table?

debora-ito commented 3 months ago

@janvanbesien-ngdata @akshat62

Is there a reason you need the slf4j version inside the SDK to be upgraded?

We have some concerns about 2.x backwards compatibility (https://github.com/aws/aws-sdk-java-v2/pull/5105#issuecomment-2073506625), and upgrading needs a deeper investigation work. Can you upgrade it in your project?

janvanbesien-ngdata commented 3 months ago

Our project already uses slf4j 2.x hence we have the slf4j-api and an slf4j 2.x provider/binding/impl on the classpath. However, this provider is incompatible with the older slf4j-api inside the SDK, hence no logging from the SDK.

My jshell example demonstrates that with the slf4j-simple provider but it's the same problem for other providers.

IIUC, the lack of backwards compatibility between slf4j providers and api that you are concerned about in #5105, is exactly what I am running into. So it is annoying either way: (a) if you upgrade, customers will have to upgrade as well. (b) If you don't upgrade, customers can't upgrade either.

You can't postpone the upgrade for ever, so (a) is the only way forward IMHO.

debora-ito commented 3 months ago

We've added a task to our backlog to investigate if it's possible to upgrade to slf4j 2.x without breaking backwards compatibility.

We don't have a timeline for when the task will be prioritized. In the meantime, anyone who'd like to see this feature supported please add a 👍 to the initial description of the issue.