taoensso / telemere

Structured telemetry library for Clojure/Script
https://www.taoensso.com/telemere
Eclipse Public License 1.0
167 stars 2 forks source link

Failed to load class "org.slf4j.impl.StaticLoggerBinder" #13

Closed socksy closed 2 months ago

socksy commented 2 months ago

Sorry if this question belies my complete lack of a mental model of what is going on — it's because I have a complete lack of a mental model of what is going on.

When using some Java libraries in Clojure, you occasionally get the startup warning:

Failed to load class "org.slf4j.impl.StaticLoggerBinder"

The standard advice for this with most people I know has been — add slf4j-timbre to your deps.edn, and this warning will magically go away. Since almost all serious projects were using timbre anyway, this seemed like a no-brainer. Somehow somewhere including this library presumably meant that we were creating a binder for SLF4J such that it all goes through to timbre, and then we only need to worry about where that goes.

Now telemere is the better library (OpenTelemetry!) , and I'm starting a new project using it, and I'm getting the dreaded StaticLoggerBinder warning. I saw that you have an SLF4J backend for telemere, which I've included in my requires, but I'm still seeing this logger. I guess I'm doing something wrong.

socksy commented 2 months ago

OK, I figured it out.

I was getting SLF4J via Kaocha, see the deps tree:

lambdaisland/kaocha 1.91.1392
 . com.nextjournal/beholder 1.0.2
    . io.methvin/directory-watcher 0.17.3
      . net.java.dev.jna/jna 5.12.1
      . org.slf4j/slf4j-api 1.7.36
full deps tree ``` ❯ clj -X:deps tree :aliases '[:dev :test]' org.clojure/clojure 1.11.1 . org.clojure/spec.alpha 0.3.218 . org.clojure/core.specs.alpha 0.2.62 cider/cider-nrepl 0.45.0 X nrepl/nrepl 1.0.0 :use-top . cider/orchard 0.22.0 . mx.cider/logjam 0.2.0 nrepl/nrepl 0.9.0 refactor-nrepl/refactor-nrepl 3.6.0 X nrepl/nrepl 0.9.0 :use-top com.taoensso/telemere 1.0.0-beta14 . com.taoensso/encore 3.112.0 . org.clojure/tools.reader 1.4.2 . com.taoensso/truss 1.11.0 com.taoensso/slf4j-telemere 1.0.0-beta14 lambdaisland/kaocha 1.91.1392 . lambdaisland/deep-diff2 2.11.216 . fipp/fipp 0.6.26 . org.clojure/core.rrb-vector 0.1.2 . org.clojure/core.rrb-vector 0.1.2 . lambdaisland/clj-diff 1.4.78 . mvxcvi/arrangement 2.1.0 . expound/expound 0.9.0 . org.clojure/tools.cli 1.1.230 . slingshot/slingshot 0.12.2 . com.nextjournal/beholder 1.0.2 . io.methvin/directory-watcher 0.17.3 . net.java.dev.jna/jna 5.12.1 . org.slf4j/slf4j-api 1.7.36 . aero/aero 1.1.6 . lambdaisland/tools.namespace 0.3.256 . org.clojure/java.classpath 1.0.0 X org.clojure/tools.reader 1.3.6 :older-version . progrock/progrock 0.1.2 . org.tcrawley/dynapath 1.1.0 . hawk/hawk 0.2.11 . net.incongru.watchservice/barbary-watchservice 1.0 X net.java.dev.jna/jna 3.2.2 :older-version . meta-merge/meta-merge 1.0.0 lambdaisland/kaocha-cucumber 0.11.100 . com.lambdaisland/kaocha-cucumber 0.11.100 X lambdaisland/kaocha 1.82.1306 :use-top . io.cucumber/cucumber-java 4.2.2 . io.cucumber/cucumber-core 4.2.2 . io.cucumber/cucumber-html 0.2.7 . io.cucumber/gherkin 5.1.0 . io.cucumber/tag-expressions 1.1.1 . io.cucumber/cucumber-expressions 6.2.0 . io.cucumber/datatable 1.1.12 . io.cucumber/datatable-dependencies 1.1.12 ```

as documented in the wiki here, SLF4J-api needs to be 2.0.0 or higher, and it's lower than that. So I had added an explicit include in my :dev alias like so:

  :dev {:extra-deps {org.slf4j/slf4j-api  {:mvn/version "2.0.13"}
                     lambdaisland/kaocha {:mvn/version "1.91.1392"}
                     lambdaisland/kaocha-cucumber {:mvn/version "0.11.100"}}}
  :test {:extra-paths ["test"]
         :extra-deps {lambdaisland/kaocha {:mvn/version "1.91.1392"}
                      lambdaisland/kaocha-cucumber {:mvn/version "0.11.100"}}
         :main-opts ["-m" "kaocha.runner"]}}}

But of course, when using the kaocha runner, it doesn't look into that alias at all, and that's where I was seeing the error. Since I have telemere up in the top level :deps key, I moved the org.slf4j/slf4j-api key up to there, and now the warning has disappeared.

So PEBKAC, as usual

ptaoussanis commented 2 months ago

Hey Ben, good to hear from you!

No problem at all, happy you found a solution.

Thanks for the clear issue description, and for updating on the conclusion - this experience may also be handy for others 🙏

Feel free to ping if you run into anything else.