Logger conflicts

237 views
Skip to first unread message

Eric in San Diego

unread,
Jul 23, 2012, 6:04:24 PM7/23/12
to clo...@googlegroups.com
I'm in the process of upgrading some oldish code, and I'm encountering some compatibility problems with the loggers required by various libraries.

See the *appendix* below for my project.clj, which loads a number of libraries and to which I've recently added statements like this:

         [com.hp.hpl.jena/jena "2.6.4"
          :exclusions [org.slf4j/slf4j-log4j12
                   org.slf4j/slf4j-api
                   ]
          ]

I added these exclusions to turn off this error:

java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V

Which I gather from reading things like this:

<http://stackoverflow.com/questions/3519978/logging-framework-incompatibility>

- stem from incompatible logging libraries.

Excluding these dependencies  seems to turn off this error, but now when I try load my code, I'm getting this error:

org.slf4j.LoggerFactory
  [Thrown class java.lang.ClassNotFoundException]

See the appendix for a stack trace.

I'm including org.clojure/tools.logging in the project.clj, but it's not clear to me how to keep the logger associated with my 'jena' library happy without re-introducing my compatibility error.

Up to this point, my logging has 'just worked', so I guess this is an opportunity to learn about this stuff. Is there a good way to deal with the fact that different supporting libraries will use different logging regimes?

Thanks for any help.


* appendix *

(defproject MyProject "1.0.0-SNAPSHOT"

  :jvm-opts ["-Xmx8g" "-XX:+HeapDumpOnOutOfMemoryError" "-XX:+UseSerialGC"]


  :dependencies [[org.clojure/clojure "1.3.0"]
         [org.clojure/math.numeric-tower "0.0.1"]
         [org.clojure/tools.trace "0.7.1"]
         [org.clojure/tools.logging "0.2.3"]
         [org.clojure/algo.generic "0.1.0"]
         [clojure-csv "1.3.2"]
         ;;statistics...
         [incanter/incanter-core "1.3.0-SNAPSHOT"]
         [incanter/incanter-charts "1.3.0-SNAPSHOT"]
         [incanter/incanter-processing "1.3.0-SNAPSHOT"]

         ;;web
         [compojure "1.1.1"]
         [hiccup "1.0.0"]
         [ring "1.1.1"]

         ;;jena ...
         [com.hp.hpl.jena/jena "2.6.4"
          :exclusions [org.slf4j/slf4j-log4j12
                   org.slf4j/slf4j-api
                   ]
          ]
         ;;TDB
         [com.hp.hpl.jena/arq "2.8.8"
          :exclusions [org.slf4j/slf4j-api]
          ]
         [com.hp.hpl.jena/iri "0.8"]
         [com.ibm.icu/icu4j "3.4.4"]
         [com.hp.hpl.jena/tdb "0.8.10"
          :exclusions [org.slf4j/slf4j-api]
          ]
         ;;lucene
         [org.apache.lucene/lucene-core "2.3.1"]
          ]
  :dev-dependencies [
               [swank-clojure "1.3.2"
                :exclusions [org.clojure/clojure]]
             [lein-autodoc "0.9.0"]
              
               ]
 
)

-- stack trace:

org.slf4j.LoggerFactory
  [Thrown class java.lang.ClassNotFoundException]
Backtrace:
  0: java.net.URLClassLoader$1.run(URLClassLoader.java:217)
  1: java.security.AccessController.doPrivileged(Native Method)
  2: java.net.URLClassLoader.findClass(URLClassLoader.java:205)
  3: java.lang.ClassLoader.loadClass(ClassLoader.java:321)
  4: sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
  5: java.lang.ClassLoader.loadClass(ClassLoader.java:266)
  6: com.hp.hpl.jena.util.Metadata.<clinit>(Metadata.java:26)
  7: com.hp.hpl.jena.JenaRuntime.<clinit>(JenaRuntime.java:25)
  8: com.hp.hpl.jena.rdf.model.impl.RDFReaderFImpl.<clinit>(RDFReaderFImpl.java:85)
  9: com.hp.hpl.jena.rdf.model.impl.ModelCom.<clinit>(ModelCom.java:42)



Peter Taoussanis

unread,
Jul 24, 2012, 1:51:49 AM7/24/12
to clo...@googlegroups.com
Hi Eric,

I can't offer any advice on resolving this particular incompatibility, but I would say that Java logging config difficulties are frustratingly common in my experience.

If the opportunity ever arises, I'd suggest you take a look at Timbre as an alternative: https://github.com/ptaoussanis/timbre

It's an all-Clojure logging lib I'm working on that's particularly easy to configure and that doesn't interfere with or depend on any of the Java logging nonsense.

May or may not be a fit for what you need, but it might be worth taking a look.

Best of luck!

- Peter Taoussanis (@ptaoussanis)

Eric in San Diego

unread,
Jul 24, 2012, 2:12:31 PM7/24/12
to clo...@googlegroups.com
Thanks for your response. I look forward to trying out your lib. 

As it happens, my problem seems magically to have vanished on its own, and I can't think of anything I did that might have shaken it loose.  Gotta love problems that magically fix themselves (until they magically unfix themselves).


Reply all
Reply to author
Forward
0 new messages