I have two jar files in my classpath which has a dependency with slf4j. This causes a warning message in my Java program:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/lib/slf4j-log4j12-1.7.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/lib/myprogram.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
Is there a way to remove this warning message by only changing the gradle file, and without removing any of above jar files from my classpath?
Thanks
Is there a way to remove this warning message by only changing the gradle file, and without removing any of above jar files from my classpath?
No.
The only way to remove that warning is by providing only a single binding for SLF4J. And you really should do so:
Even when multiple bindings are present, SLF4J will pick one logging framework/implementation and bind with it. The way SLF4J picks a binding is determined by the JVM and for all practical purposes should be considered random.
Since you provide a binding in your own jar, the easiest way to restrict yourself to a single binding would be to exclude the slf4j-log4j12-1.7.6.jar.
Related
I need to update the version of JDBC Redshift driver in gradle and it looks like 1.3X has the following problem:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:~/.gradle/caches/modules-2/files-2.1/com.amazon.redshift/redshift-jdbc42/1.2.37.1061/daad21f8637b6ccd2b86307a4f17e1e215df7365/redshift-jdbc42-1.2.37.1061.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:~/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.2.3/7c4f3c474fb2c041d8028740440937705ebb473a/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
I can exclude ch.qos.logback/logback-classic globally, but I'm wondering if there's a better way around that since I'd rather disable the unexpected duplicate logger from com.amazon.redshift/redshift-jdbc42
The sl4j dependency seems to have been added starting at version 1.2.34.1058. You can use any version below that without having the multiple SLF4J bindings.
I hope it helps. :)
I'm running Apache velocity template engine (2 latest)
I keep getting below debug messages from SLF4J
This obstructs the user from viewing important messages, is there a way to suppress these messages?
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/user1/Package/installer/lib/slf4j-simple-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/user1/Package/installer/lib/slf4j-simple-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
Message warns you about multiple SLF4J classes,
You have 2 slf4j jars slf4j-simple-1.7.5.jar and slf4j-simple-1.7.25.jar which both have the same class (StaticLoggerBinder),
Remove one of the jars from dependencies and the debug message will disappear.
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/username/.m2/repository/ch/qos/logback/logback-classic/1.1.9/logback-classic-1.1.9.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/username/.m2/repository/org/slf4j/slf4j-simple/1.7.22/slf4j-simple-1.7.22.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/username/.m2/repository/org/slf4j/slf4j-log4j12/1.7.8/slf4j-log4j12-1.7.8.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
How can I fix this.
Thanks
Slf4j is an interface that can have several implementations. You have three implementations in your dependencies: slf4j-log4j, slf4j-simple and logback-classic. Decide for one and exclude the other dependencies.
You can check solution to slf4j site, search text
"Multiple bindings were found on the classpath"
here
An example given at above site may not be an exact solution, you need to find which all 3rd party library uses slf4j version and exclude them while adding them as a dependency.
.
I'm trying to compile a java program using these jars(screenshot) but getting these errors:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/vanar/workspace/TwitterKafka/logback-classic-1.1.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/vanar/workspace/TwitterKafka/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
Exception in thread "hosebird-client-io-thread-0" java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;Ljava/lang/Throwable;)V
at org.apache.commons.logging.impl.SLF4JLocationAwareLog.debug(SLF4JLocationAwareLog.java:120)
at org.apache.http.impl.conn.PoolingClientConnectionManager.shutdown(PoolingClientConnectionManager.java:276)
at com.twitter.hbc.httpclient.ClientBase.run(ClientBase.java:165)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
how do I ensure all these logging components work together?
I am stumped as to what is compatible with what and do not know a way apart from trial and error which I tried with no luck. please help
You can try to add logging jar files to endorsed directory.
Use latest combination of slf4j-log4j .You are using older version of any one of this jars.
add log4j and sl4j jar in this combination. if any one is missing exception raised while logging.
I am writing server side socket application using Java, but I have no idea what can cause this error
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.
How can I solve this problem?
You are getting this message because slf4j could not find a binding in your classpath. slf4j is like a wrapper over other logging frameworks. It needs the binding library of the logging framework you intend to use to actually log the messages. e.g., for using log4j, add the libraries slf4j-log4j12.jar and log4j.jar.
More details can be found in the SLF4J manual at http://www.slf4j.org/manual.html.
To switch logging frameworks, just replace slf4j bindings on your
class path. For example, to switch from java.util.logging to log4j,
just replace slf4j-jdk14-1.7.10.jar with slf4j-log4j12-1.7.10.jar.
SLF4J does not rely on any special class loader machinery. In fact,
each SLF4J binding is hardwired at compile time to use one and only
one specific logging framework. For example, the
slf4j-log4j12-1.7.10.jar binding is bound at compile time to use
log4j. In your code, in addition to slf4j-api-1.7.10.jar, you simply
drop one and only one binding of your choice onto the appropriate
class path location. Do not place more than one binding on your class
path.