taoensso / timbre

Pure Clojure/Script logging library
https://www.taoensso.com/timbre
Eclipse Public License 1.0
1.44k stars 171 forks source link

Seeing a lot of deprecation warnings in our log #379

Closed finalfantasia closed 4 months ago

finalfantasia commented 8 months ago

We updated Timbre from 6.2.1 to 6.3.1 and started seeing these deprecation warnings in our log, which, I think, are logged by Shadow-CLJS/Closure compiler. I found some articles about globally disabling these deprecation warnings at the compiler level but I'm not sure that's the right thing to do here (i.e., we would still like to keep that feature for our own deprecated functions):

------ WARNING #1 - :fn-deprecated ---------------------------------------------
 Resource: taoensso/encore.cljc:6125:30
--------------------------------------------------------------------------------
6122 |   ;; Used by old versions of Timbre, Tufte
6123 |   (let [nolist? #(contains? #{nil [] #{}} %)]
6124 |     (defn ^:no-doc ^:deprecated compile-ns-filter
6125 |       ([ns-pattern         ] (compile-ns-filter ns-pattern nil))
------------------------------------^-------------------------------------------
 taoensso.encore/compile-ns-filter is deprecated
--------------------------------------------------------------------------------
6126 |       ([whitelist blacklist]
6127 | 
6128 |        (if (and (nolist? whitelist) (nolist? blacklist))
6129 |          (fn [_] true) ; Unfortunate API choice
--------------------------------------------------------------------------------

------ WARNING #2 - :fn-deprecated ---------------------------------------------
 Resource: taoensso/encore.cljc:6202:14
--------------------------------------------------------------------------------
6199 |              backoff-ms)))))
6200 | 
6201 |   (defn ^:no-doc ^:deprecated rate-limit [spec f]
6202 |     (let [rl (rate-limiter* spec)]
--------------------^-----------------------------------------------------------
 taoensso.encore/rate-limiter* is deprecated
--------------------------------------------------------------------------------
6203 |       (fn [& args]
6204 |         (if-let [backoff (rl)]
6205 |           [nil backoff]
6206 |           [(f) nil]))))
--------------------------------------------------------------------------------

------ WARNING #3 - :fn-deprecated ---------------------------------------------
 Resource: taoensso/encore.cljc:6209:69
--------------------------------------------------------------------------------
6206 |           [(f) nil]))))
6207 | 
6208 |   ;; API changed for greater flexibility:
6209 |   (defn ^:no-doc ^:deprecated rate-limiter [ncalls-limit window-ms] (rate-limiter* [[ncalls-limit window-ms]]))
---------------------------------------------------------------------------^----
 taoensso.encore/rate-limiter* is deprecated
--------------------------------------------------------------------------------
6210 |   (defn ^:no-doc ^:deprecated rate-limited [ncalls-limit window-ms f]
6211 |     (let [rl (rate-limiter* [[ncalls-limit window-ms]])]
6212 |       (fn [& args]
6213 |         (if-let [backoff-ms (rl)]
--------------------------------------------------------------------------------

------ WARNING #4 - :fn-deprecated ---------------------------------------------
 Resource: taoensso/encore.cljc:6211:14
--------------------------------------------------------------------------------
6208 |   ;; API changed for greater flexibility:
6209 |   (defn ^:no-doc ^:deprecated rate-limiter [ncalls-limit window-ms] (rate-limiter* [[ncalls-limit window-ms]]))
6210 |   (defn ^:no-doc ^:deprecated rate-limited [ncalls-limit window-ms f]
6211 |     (let [rl (rate-limiter* [[ncalls-limit window-ms]])]
--------------------^-----------------------------------------------------------
 taoensso.encore/rate-limiter* is deprecated
--------------------------------------------------------------------------------
6212 |       (fn [& args]
6213 |         (if-let [backoff-ms (rl)]
6214 |           {:backoff-ms backoff-ms}
6215 |           {:result     (f)}))))
--------------------------------------------------------------------------------

------ WARNING #5 - :fn-deprecated ---------------------------------------------
 Resource: taoensso/encore.cljc:6266:19
--------------------------------------------------------------------------------
6263 | 
6264 |   (defn ^:no-doc ^:deprecated distinctv
6265 |     "Prefer `xdistinct`."
6266 |     ([      coll] (distinctv identity coll))
-------------------------^------------------------------------------------------
 taoensso.encore/distinctv is deprecated
--------------------------------------------------------------------------------
6267 |     ([keyfn coll]
6268 |      (let [tr (reduce (fn [[v seen] in]
6269 |                         (let [in* (keyfn in)]
6270 |                           (if-not (contains? seen in*)
--------------------------------------------------------------------------------

------ WARNING #6 - :fn-deprecated ---------------------------------------------
 Resource: taoensso/encore.cljc:6306:8
--------------------------------------------------------------------------------
6303 |   (defn ^:no-doc ^:deprecated memoized [cache f & args]
6304 |     (if-not cache ; {<args> <delay-val>}
6305 |       (apply f args)
6306 |       @(-swap-val! cache args (fn [?dv] (if ?dv ?dv (delay (apply f args)))))))
--------------^-----------------------------------------------------------------
 taoensso.encore/-swap-val! is deprecated
--------------------------------------------------------------------------------
6307 | 
6308 |   (defn- translate-signed-idx [^long signed-idx ^long max-idx]
6309 |     (if (>= signed-idx 0)
6310 |       (min      signed-idx max-idx)
--------------------------------------------------------------------------------

------ WARNING #7 - :fn-deprecated ---------------------------------------------
 Resource: taoensso/encore.cljc:6334:33
--------------------------------------------------------------------------------
6331 |   (defn ^:no-doc ^:deprecated substr
6332 |     "Prefer `get-substr-by-idx` or `get-substr-by-len`"
6333 |     [s start-idx & [?max-len]]
6334 |     (let [[start-idx* end-idx*] (sub-indexes s start-idx :max-len ?max-len)]
---------------------------------------^----------------------------------------
 taoensso.encore/sub-indexes is deprecated
--------------------------------------------------------------------------------
6335 |       #?(:clj  (.substring ^String s start-idx* end-idx*)
6336 |          :cljs (.substring         s start-idx* end-idx*))))
6337 | 
6338 |   (comment (substr "hello" -1 1))
--------------------------------------------------------------------------------

------ WARNING #8 - :fn-deprecated ---------------------------------------------
 Resource: taoensso/encore.cljc:6343:33
--------------------------------------------------------------------------------
6340 |   (defn ^:no-doc ^:deprecated subvec*
6341 |     "Prefer `get-subvec` or `get-subvector`"
6342 |     [v start-idx & [?max-len]]
6343 |     (let [[start-idx* end-idx*] (sub-indexes v start-idx :max-len ?max-len)]
---------------------------------------^----------------------------------------
 taoensso.encore/sub-indexes is deprecated
--------------------------------------------------------------------------------
6344 |       (subvec v start-idx* end-idx*)))
6345 | 
6346 |   (def  ^:no-doc ^:deprecated sentinel (new-object))
6347 |   (defn ^:no-doc ^:deprecated sentinel?     [x] (identical? x sentinel))
--------------------------------------------------------------------------------

------ WARNING #9 - :fn-deprecated ---------------------------------------------
 Resource: taoensso/encore.cljc:6349:53
--------------------------------------------------------------------------------
6346 |   (def  ^:no-doc ^:deprecated sentinel (new-object))
6347 |   (defn ^:no-doc ^:deprecated sentinel?     [x] (identical? x sentinel))
6348 |   (defn ^:no-doc ^:deprecated nil->sentinel [x] (if (nil? x) sentinel x))
6349 |   (defn ^:no-doc ^:deprecated sentinel->nil [x] (if (sentinel? x) nil x))
-----------------------------------------------------------^--------------------
 taoensso.encore/sentinel? is deprecated
--------------------------------------------------------------------------------
6350 | 
6351 |   (defn ^:no-doc ^:deprecated  singleton? [coll] (if (counted? coll) (= (count coll) 1) (not (next coll))))
6352 |   (defn ^:no-doc ^:deprecated ->?singleton [coll] (when (singleton? coll) (let [[c1] coll] c1)))
6353 |   (defn ^:no-doc ^:deprecated ->vec [x] (cond (vector? x) x (sequential? x) (vec x) :else [x]))
--------------------------------------------------------------------------------

------ WARNING #10 - :fn-deprecated --------------------------------------------
 Resource: taoensso/encore.cljc:6352:57
--------------------------------------------------------------------------------
6349 |   (defn ^:no-doc ^:deprecated sentinel->nil [x] (if (sentinel? x) nil x))
6350 | 
6351 |   (defn ^:no-doc ^:deprecated  singleton? [coll] (if (counted? coll) (= (count coll) 1) (not (next coll))))
6352 |   (defn ^:no-doc ^:deprecated ->?singleton [coll] (when (singleton? coll) (let [[c1] coll] c1)))
---------------------------------------------------------------^----------------
 taoensso.encore/singleton? is deprecated
--------------------------------------------------------------------------------
6353 |   (defn ^:no-doc ^:deprecated ->vec [x] (cond (vector? x) x (sequential? x) (vec x) :else [x]))
6354 | 
6355 |   (defn ^:no-doc ^:deprecated fzipmap [ks vs]
6356 |     (loop [m  (transient {})
--------------------------------------------------------------------------------
[:test] Build completed. (981 files, 980 compiled, 10 warnings, 32.75s)

------ WARNING #1 - :fn-deprecated ---------------------------------------------
 Resource: taoensso/encore.cljc:6125:30
--------------------------------------------------------------------------------
6122 |   ;; Used by old versions of Timbre, Tufte
6123 |   (let [nolist? #(contains? #{nil [] #{}} %)]
6124 |     (defn ^:no-doc ^:deprecated compile-ns-filter
6125 |       ([ns-pattern         ] (compile-ns-filter ns-pattern nil))
------------------------------------^-------------------------------------------
 taoensso.encore/compile-ns-filter is deprecated
--------------------------------------------------------------------------------
6126 |       ([whitelist blacklist]
6127 | 
6128 |        (if (and (nolist? whitelist) (nolist? blacklist))
6129 |          (fn [_] true) ; Unfortunate API choice
--------------------------------------------------------------------------------

------ WARNING #2 - :fn-deprecated ---------------------------------------------
 Resource: taoensso/encore.cljc:6202:14
--------------------------------------------------------------------------------
6199 |              backoff-ms)))))
6200 | 
6201 |   (defn ^:no-doc ^:deprecated rate-limit [spec f]
6202 |     (let [rl (rate-limiter* spec)]
--------------------^-----------------------------------------------------------
 taoensso.encore/rate-limiter* is deprecated
--------------------------------------------------------------------------------
6203 |       (fn [& args]
6204 |         (if-let [backoff (rl)]
6205 |           [nil backoff]
6206 |           [(f) nil]))))
--------------------------------------------------------------------------------

------ WARNING #3 - :fn-deprecated ---------------------------------------------
 Resource: taoensso/encore.cljc:6209:69
--------------------------------------------------------------------------------
6206 |           [(f) nil]))))
6207 | 
6208 |   ;; API changed for greater flexibility:
6209 |   (defn ^:no-doc ^:deprecated rate-limiter [ncalls-limit window-ms] (rate-limiter* [[ncalls-limit window-ms]]))
---------------------------------------------------------------------------^----
 taoensso.encore/rate-limiter* is deprecated
--------------------------------------------------------------------------------
6210 |   (defn ^:no-doc ^:deprecated rate-limited [ncalls-limit window-ms f]
6211 |     (let [rl (rate-limiter* [[ncalls-limit window-ms]])]
6212 |       (fn [& args]
6213 |         (if-let [backoff-ms (rl)]
--------------------------------------------------------------------------------

------ WARNING #4 - :fn-deprecated ---------------------------------------------
 Resource: taoensso/encore.cljc:6211:14
--------------------------------------------------------------------------------
6208 |   ;; API changed for greater flexibility:
6209 |   (defn ^:no-doc ^:deprecated rate-limiter [ncalls-limit window-ms] (rate-limiter* [[ncalls-limit window-ms]]))
6210 |   (defn ^:no-doc ^:deprecated rate-limited [ncalls-limit window-ms f]
6211 |     (let [rl (rate-limiter* [[ncalls-limit window-ms]])]
--------------------^-----------------------------------------------------------
 taoensso.encore/rate-limiter* is deprecated
--------------------------------------------------------------------------------
6212 |       (fn [& args]
6213 |         (if-let [backoff-ms (rl)]
6214 |           {:backoff-ms backoff-ms}
6215 |           {:result     (f)}))))
--------------------------------------------------------------------------------

------ WARNING #5 - :fn-deprecated ---------------------------------------------
 Resource: taoensso/encore.cljc:6266:19
--------------------------------------------------------------------------------
6263 | 
6264 |   (defn ^:no-doc ^:deprecated distinctv
6265 |     "Prefer `xdistinct`."
6266 |     ([      coll] (distinctv identity coll))
-------------------------^------------------------------------------------------
 taoensso.encore/distinctv is deprecated
--------------------------------------------------------------------------------
6267 |     ([keyfn coll]
6268 |      (let [tr (reduce (fn [[v seen] in]
6269 |                         (let [in* (keyfn in)]
6270 |                           (if-not (contains? seen in*)
--------------------------------------------------------------------------------

------ WARNING #6 - :fn-deprecated ---------------------------------------------
 Resource: taoensso/encore.cljc:6306:8
--------------------------------------------------------------------------------
6303 |   (defn ^:no-doc ^:deprecated memoized [cache f & args]
6304 |     (if-not cache ; {<args> <delay-val>}
6305 |       (apply f args)
6306 |       @(-swap-val! cache args (fn [?dv] (if ?dv ?dv (delay (apply f args)))))))
--------------^-----------------------------------------------------------------
 taoensso.encore/-swap-val! is deprecated
--------------------------------------------------------------------------------
6307 | 
6308 |   (defn- translate-signed-idx [^long signed-idx ^long max-idx]
6309 |     (if (>= signed-idx 0)
6310 |       (min      signed-idx max-idx)
--------------------------------------------------------------------------------

------ WARNING #7 - :fn-deprecated ---------------------------------------------
 Resource: taoensso/encore.cljc:6334:33
--------------------------------------------------------------------------------
6331 |   (defn ^:no-doc ^:deprecated substr
6332 |     "Prefer `get-substr-by-idx` or `get-substr-by-len`"
6333 |     [s start-idx & [?max-len]]
6334 |     (let [[start-idx* end-idx*] (sub-indexes s start-idx :max-len ?max-len)]
---------------------------------------^----------------------------------------
 taoensso.encore/sub-indexes is deprecated
--------------------------------------------------------------------------------
6335 |       #?(:clj  (.substring ^String s start-idx* end-idx*)
6336 |          :cljs (.substring         s start-idx* end-idx*))))
6337 | 
6338 |   (comment (substr "hello" -1 1))
--------------------------------------------------------------------------------

------ WARNING #8 - :fn-deprecated ---------------------------------------------
 Resource: taoensso/encore.cljc:6343:33
--------------------------------------------------------------------------------
6340 |   (defn ^:no-doc ^:deprecated subvec*
6341 |     "Prefer `get-subvec` or `get-subvector`"
6342 |     [v start-idx & [?max-len]]
6343 |     (let [[start-idx* end-idx*] (sub-indexes v start-idx :max-len ?max-len)]
---------------------------------------^----------------------------------------
 taoensso.encore/sub-indexes is deprecated
--------------------------------------------------------------------------------
6344 |       (subvec v start-idx* end-idx*)))
6345 | 
6346 |   (def  ^:no-doc ^:deprecated sentinel (new-object))
6347 |   (defn ^:no-doc ^:deprecated sentinel?     [x] (identical? x sentinel))
--------------------------------------------------------------------------------

------ WARNING #9 - :fn-deprecated ---------------------------------------------
 Resource: taoensso/encore.cljc:6349:53
--------------------------------------------------------------------------------
6346 |   (def  ^:no-doc ^:deprecated sentinel (new-object))
6347 |   (defn ^:no-doc ^:deprecated sentinel?     [x] (identical? x sentinel))
6348 |   (defn ^:no-doc ^:deprecated nil->sentinel [x] (if (nil? x) sentinel x))
6349 |   (defn ^:no-doc ^:deprecated sentinel->nil [x] (if (sentinel? x) nil x))
-----------------------------------------------------------^--------------------
 taoensso.encore/sentinel? is deprecated
--------------------------------------------------------------------------------
6350 | 
6351 |   (defn ^:no-doc ^:deprecated  singleton? [coll] (if (counted? coll) (= (count coll) 1) (not (next coll))))
6352 |   (defn ^:no-doc ^:deprecated ->?singleton [coll] (when (singleton? coll) (let [[c1] coll] c1)))
6353 |   (defn ^:no-doc ^:deprecated ->vec [x] (cond (vector? x) x (sequential? x) (vec x) :else [x]))
--------------------------------------------------------------------------------

------ WARNING #10 - :fn-deprecated --------------------------------------------
 Resource: taoensso/encore.cljc:6352:57
--------------------------------------------------------------------------------
6349 |   (defn ^:no-doc ^:deprecated sentinel->nil [x] (if (sentinel? x) nil x))
6350 | 
6351 |   (defn ^:no-doc ^:deprecated  singleton? [coll] (if (counted? coll) (= (count coll) 1) (not (next coll))))
6352 |   (defn ^:no-doc ^:deprecated ->?singleton [coll] (when (singleton? coll) (let [[c1] coll] c1)))
---------------------------------------------------------------^----------------
 taoensso.encore/singleton? is deprecated
--------------------------------------------------------------------------------
6353 |   (defn ^:no-doc ^:deprecated ->vec [x] (cond (vector? x) x (sequential? x) (vec x) :else [x]))
6354 | 
6355 |   (defn ^:no-doc ^:deprecated fzipmap [ks vs]
6356 |     (loop [m  (transient {})
--------------------------------------------------------------------------------
ptaoussanis commented 8 months ago

@finalfantasia Hi Salam, thanks for letting me know about this.

It seems that Shadow-CLJS is warning about the use of deprecated vars, even by other deprecated vars. That seems wrong to me, especially since it seems to include warnings about a deprecated var calling itself with a different arity.

Anyway, depending on what other Taoensso libs you're using - it may be possible to eliminate the warnings with one of the following:

  1. Set the taoensso.elide-deprecated JVM property to "true", or
  2. Set the TAOENSSO_ELIDE_DEPRECATED ENV var to "true"

One easy way to do (1) is by adding a :jvm-opts ["-Dtaoensso.elide-deprecated=true"] key to your Leiningen project.clj or equivalent.

That'll cause all deprecated Taoensso vars to be completely elided at compile-time.

Please let me know if that helps, otherwise I'll see about filing an issue against Shadow-CLJS since I suspect that the current behaviour isn't intentional.

finalfantasia commented 8 months ago

@finalfantasia Hi Salam, thanks for letting me know about this.

It seems that Shadow-CLJS is warning about the use of deprecated vars, even by other deprecated vars. That seems wrong to me, especially since it seems to include warnings about a deprecated var calling itself with a different arity.

Anyway, depending on what other Taoensso libs you're using - it may be possible to eliminate the warnings with one of the following:

  1. Set the taoensso.elide-deprecated JVM property to "true", or

  2. Set the TAOENSSO_ELIDE_DEPRECATED ENV var to "true"

One easy way to do (1) is by adding a :jvm-opts ["-Dtaoensso.elide-deprecated=true"] key to your Leiningen project.clj or equivalent.

That'll cause all deprecated Taoensso vars to be completely elided at compile-time.

Please let me know if that helps, otherwise I'll see about filing an issue against Shadow-CLJS since I suspect that the current behaviour isn't intentional.

Will do. Thanks for the prompt response!

finalfantasia commented 8 months ago

Closing this issue as we were able to suppress these warnings by disabling a ClojureScript compiler flag (:fn-deprecated) in our shadow-cljs.edn

oakmac commented 7 months ago

we were able to suppress these warnings by disabling a ClojureScript compiler flag (:fn-deprecated) in our shadow-cljs.edn

Thank you @finalfantasia! 🤓

EDIT: Please see this comment below for the recommended fix.

ptaoussanis commented 7 months ago

Thanks Chris, Salam! 👍

Though just a heads-up that completely disabling deprecated var warnings might not be something you want long-term. It's easy to forget about, and could cause you to miss important warnings later.

Ideally the irrelevant warnings should be stopped upstream, Eric created a shadow-cljs issue here.

And in case there's still any bothersome Encore warnings after that (and after updating your Taoensso dependencies), you could selectively suppress any remaining warnings with the method I mentioned above.

I believe that might also be a safer choice in the meantime (while waiting for a possible shadow-cljs fix) since it's more selective.

oakmac commented 7 months ago

Though just a heads-up that completely disabling deprecated var warnings might not be something you want long-term. It's easy to forget about, and could cause you to miss important warnings later.

Here is what an example shadow-cljs.edn file might look like with the JVM option set:

{:dependencies [...]
 :source-paths [...]

 :jvm-opts ["-Dtaoensso.elide-deprecated=true"]

 :builds
 {:app {:target :browser
        :output-dir "public/assets/app/js"
        :asset-path "/assets/app/js"
        :modules {:main {:entries [my.app]}}}}}
ptaoussanis commented 5 months ago

Re-opening until the shadow-cljs issue is fixed.

For anyone running into this in the meantime, please see here for the recommended workaround.

Sorry for the trouble!

p-himik commented 5 months ago

@ptaoussanis That fix doesn't work with at least Encore 3.74.1 and Timbre 6.3.1 because the latter relies on enc/limiter, which is deprecated.

ptaoussanis commented 5 months ago

@p-himik Thanks for the heads-up Eugene 🙏

@everyone I've just pushed Encore v3.74.2 to Clojars that just removes the deprecation metadata in the meantime until shadow-cljs can be fixed.

Again apologies for all the trouble on this.

yenda commented 5 months ago

@ptaoussanis actually it is not an issue in shadow-cljs but in clojurescript itself:

deps.edn

{:deps {org.clojure/clojurescript {:mvn/version "1.11.54"}
com.taoensso/timbre {:mvn/version "6.3.1"}
}}

src/hello_world/core.cljs

(ns hello-world.core
  (:require [taoensso.timbre :as log]))

(log/info "Hello")
(println "Hello world!")
yenda@project2503:~/test-warning$ clj -M -m cljs.main -c hello-world.core
WARNING: taoensso.encore/compile-ns-filter is deprecated at line 6125 /home/yenda/.cljs/.aot_cache/1.11.54/02F6365/taoensso/encore.cljc
WARNING: taoensso.encore/rate-limiter* is deprecated at line 6202 /home/yenda/.cljs/.aot_cache/1.11.54/02F6365/taoensso/encore.cljc
WARNING: taoensso.encore/rate-limiter* is deprecated at line 6209 /home/yenda/.cljs/.aot_cache/1.11.54/02F6365/taoensso/encore.cljc
WARNING: taoensso.encore/rate-limiter* is deprecated at line 6211 /home/yenda/.cljs/.aot_cache/1.11.54/02F6365/taoensso/encore.cljc
WARNING: taoensso.encore/distinctv is deprecated at line 6266 /home/yenda/.cljs/.aot_cache/1.11.54/02F6365/taoensso/encore.cljc
WARNING: taoensso.encore/-swap-val! is deprecated at line 6306 /home/yenda/.cljs/.aot_cache/1.11.54/02F6365/taoensso/encore.cljc
WARNING: taoensso.encore/sub-indexes is deprecated at line 6334 /home/yenda/.cljs/.aot_cache/1.11.54/02F6365/taoensso/encore.cljc
WARNING: taoensso.encore/sub-indexes is deprecated at line 6343 /home/yenda/.cljs/.aot_cache/1.11.54/02F6365/taoensso/encore.cljc
WARNING: taoensso.encore/sentinel? is deprecated at line 6349 /home/yenda/.cljs/.aot_cache/1.11.54/02F6365/taoensso/encore.cljc
WARNING: taoensso.encore/singleton? is deprecated at line 6352 /home/yenda/.cljs/.aot_cache/1.11.54/02F6365/taoensso/encore.cljc
yenda commented 5 months ago

@ptaoussanis could be related to this 6 years old issue that will likely never be fixed. The workaround could be to add ^:deprecation-nowarn as mentionned in the issue https://clojure.atlassian.net/browse/CLJS-2000

ptaoussanis commented 5 months ago

@yenda Thanks for investigating Eric! I'll add the suggested workaround to the next Encore release. Much appreciated! Cheers :-)

ptaoussanis commented 4 months ago

Closing, should now be resolved with https://github.com/taoensso/timbre/releases/tag/v6.4.0.

Again, apologies for all the noise on this issue.