[java] Logging framework incompatibility

I'm building a small Java app and hoping to use logback for logging.

My app has a dependency on an older project that does its logging via

org.apache.commons | com.springsource.org.apache.commons.logging | 1.1.1

...so my plan was to use

org.slf4j | jcl-over-slf4j | 1.5.6

...to redirect the JCL logging to

org.slf4j | slf4j-api | 1.6.0

...and ultimately to

ch.qos.logback | logback-classic | 0.9.22
ch.qos.logback | logback-core | 0.9.22

so my app can log through logback via its slf4j API while the old library code can log into the same location via the redirection.

Alas, this results in

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.info(SLF4JLocationAwareLog.java:141)

I've tried higher and lower verision numbers on some of these jars and also digging through API documentation and such... but I'm unable to find and solve the problem.

Help, please?

Although logback is considered the "strategic" logging framework, I have some leeway in which logging mechanism I ultimately use. I'd hope to use either logback or log4j, though, and I definitely want to merge the old project's logging into whatever the "new" logging framework ends up being, via a common configuration.

This question is related to java compatibility apache-commons slf4j logback

The answer is


Just to help those in a similar situation to myself...

This can be caused when a dependent library has accidentally bundled an old version of slf4j. In my case, it was tika-0.8. See https://issues.apache.org/jira/browse/TIKA-556

The workaround is exclude the component and then manually depends on the correct, or patched version.

EG.

<dependency>
    <groupId>org.apache.tika</groupId>
    <artifactId>tika-parsers</artifactId>
    <version>0.8</version>
    <exclusions>
        <exclusion>
            <!-- NOTE: Version 4.2 has bundled slf4j -->
            <groupId>edu.ucar</groupId>
            <artifactId>netcdf</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <!-- Patched version 4.2-min does not bundle slf4j -->
    <groupId>edu.ucar</groupId>
    <artifactId>netcdf</artifactId>
    <version>4.2-min</version>
</dependency>

SLF4J 1.5.11 and 1.6.0 versions are not compatible (see compatibility report) because the argument list of org.slf4j.spi.LocationAwareLogger.log method has been changed (added Object[] p5):

SLF4J 1.5.11:

LocationAwareLogger.log ( org.slf4j.Marker p1, String p2, int p3,
                          String p4, Throwable p5 )

SLF4J 1.6.0:

LocationAwareLogger.log ( org.slf4j.Marker p1, String p2, int p3,
                          String p4, Object[] p5, Throwable p6 )

See compatibility reports for other SLF4J versions on this page.

You can generate such reports by the japi-compliance-checker tool.

enter image description here


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to compatibility

Which TensorFlow and CUDA version combinations are compatible? IE11 Document mode defaults to IE7. How to reset? Internet Explorer 11 disable "display intranet sites in compatibility view" via meta tag not working Possible to restore a backup of SQL Server 2014 on SQL Server 2012? How to set IE11 Document mode to edge as default? Is it possible to run a .NET 4.5 app on XP? I want to get Year, Month, Day, etc from Java Date to compare with Gregorian Calendar date in Java. Is this possible? Fragments onResume from back stack Uninitialized constant ActiveSupport::Dependencies::Mutex (NameError) How to run multiple Python versions on Windows

Examples related to apache-commons

What does the arrow operator, '->', do in Java? Bi-directional Map in Java? How can I generate a list or array of sequential integers in Java? How can I get an HTTP response body as a string? How can I convert byte size into a human-readable format in Java? Logging framework incompatibility Http Basic Authentication in Java using HttpClient? How to Serialize a list in java? What is the best Java email address validation method?

Examples related to slf4j

Where does the slf4j log file get saved? Building with Lombok's @Slf4j and Intellij: Cannot find symbol log How to configure slf4j-simple SLF4J: Class path contains multiple SLF4J bindings SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". in a Maven Project SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". error java.lang.ClassNotFoundException: org.apache.log4j.Level Logger slf4j advantages of formatting with {} instead of string concatenation ClassNotFoundException: org.slf4j.LoggerFactory Configuring Log4j Loggers Programmatically

Examples related to logback

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". error Logging levels - Logback - rule-of-thumb to assign log levels How can I configure Logback to log different levels for a logger to different destinations? How to change root logging level programmatically for logback Logging framework incompatibility log4j vs logback