qos-ch/slf4j

slf4j doesn't work on the docker

nodece opened this issue · 4 comments

Right now, I'm working on the Apache Pulsar project, and migrating the slf4j to 2.0.12 from 1.7.36, but it always prints the following log:

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.

please see apache/pulsar#22391, the GHA env is Ubuntu, we are using the testcontainers to run the integration test, and the test image is based on the alpine 3.9:

  • When running this image on ubuntu, it always prints the above log.
  • When running this image on the MacOS, it works fine.

I'm not sure where the problem is, thanks for your time!

How to reproduce

docker run -it nodece/java-test-image bin/pulsar proxy
  • Ubuntu 22
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.
2024-04-07T14:35:25,623Z [jdk.internal.loader.ClassLoaders$AppClassLoader@63c12fb0] error Uncaught exception in thread main: java.lang.IllegalArgumentException: metadataStoreUrl must be provided
org.apache.pulsar.broker.PulsarServerException: java.lang.IllegalArgumentException: metadataStoreUrl must be provided
        at org.apache.pulsar.proxy.server.ProxyServiceStarter.<init>(ProxyServiceStarter.java:205)
        at org.apache.pulsar.proxy.server.ProxyServiceStarter.main(ProxyServiceStarter.java:215)
Caused by: java.lang.IllegalArgumentException: metadataStoreUrl must be provided
        at com.google.common.base.Preconditions.checkArgument(Preconditions.java:143)
        at org.apache.pulsar.proxy.server.ProxyServiceStarter.<init>(ProxyServiceStarter.java:193)
        ... 1 more
  • MacOS 14.1.1, it works fine.
2024-04-07T14:46:00,668+0000 [main] ERROR org.apache.pulsar.proxy.server.ProxyServiceStarter - Failed to start pulsar proxy service. error msg metadataStoreUrl must be provided
java.lang.IllegalArgumentException: metadataStoreUrl must be provided
	at com.google.common.base.Preconditions.checkArgument(Preconditions.java:143) ~[com.google.guava-guava-32.1.2-jre.jar:?]
	at org.apache.pulsar.proxy.server.ProxyServiceStarter.<init>(ProxyServiceStarter.java:193) [org.apache.pulsar-pulsar-proxy-3.3.0-SNAPSHOT.jar:3.3.0-SNAPSHOT]
	at org.apache.pulsar.proxy.server.ProxyServiceStarter.main(ProxyServiceStarter.java:215) [org.apache.pulsar-pulsar-proxy-3.3.0-SNAPSHOT.jar:3.3.0-SNAPSHOT]
2024-04-07T14:46:00,699Z [jdk.internal.loader.ClassLoaders$AppClassLoader@63c12fb0] error Uncaught exception in thread main: java.lang.IllegalArgumentException: metadataStoreUrl must be provided
org.apache.pulsar.broker.PulsarServerException: java.lang.IllegalArgumentException: metadataStoreUrl must be provided
	at org.apache.pulsar.proxy.server.ProxyServiceStarter.<init>(ProxyServiceStarter.java:205)
	at org.apache.pulsar.proxy.server.ProxyServiceStarter.main(ProxyServiceStarter.java:215)
Caused by: java.lang.IllegalArgumentException: metadataStoreUrl must be provided
	at com.google.common.base.Preconditions.checkArgument(Preconditions.java:143)
	at org.apache.pulsar.proxy.server.ProxyServiceStarter.<init>(ProxyServiceStarter.java:193)
	... 1 more
ceki commented

@nodece Please refer to https://www.slf4j.org/codes.html#StaticLoggerBinder

The first phrase is quite relevant:

This warning message is reported by slf4j-api version 1.7.x and earlier when the org.slf4j.impl.StaticLoggerBinder class could not be loaded into memory.

and also

If you are seeing this message, then you are NOT using slf4j-api version 2.0 or later but slf4j-api version 1.7.x or earlier.

In any case, this looks like a packaging issue and not an SLF4J issue.

From the logs, it does seem like what you said, I know this log looks like we are using the slf4j2-api 1.7.x or earlier, I ensure the lib includes slf4j2-api 2.0.12, not 1.7.x.

I'm using the same image running on a different OS, it has a different log, how to explain this behavior?

In the MacOS, which prints 2024-04-07T14:46:00,668+0000 [main] ERROR org.apache.pulsar.proxy.server.ProxyServiceStarter - Failed to start pulsar proxy service. error msg metadataStoreUrl must be provided, it works fine.

In the Ubuntu, Failed to start pulsar proxy service wasn't printed.

Add -verbose:class to the java command, and you can find where slf4j2 loads from.

There are some strange differences in the jars loaded on different platforms.

Thanks.

ceki commented

From the logs, it does seem like what you said, I know this log looks like we are using the slf4j2-api 1.7.x or earlier, I ensure the lib includes slf4j2-api 2.0.12, not 1.7.x.

It does not seem, it is that you are using slf4j 1.7 or earlier.

I'm using the same image running on a different OS, it has a different log, how to explain this behavior?

You have a copy of slf4j-api version 1.7 somewhere else on you class path. As slf4j developers, we cannot investigate issues specific to your environment.