This commit is contained in:
Michiel Borkent 2024-03-15 18:02:58 +01:00
parent b2b16783ed
commit e1588e663e
4 changed files with 22 additions and 47 deletions

View file

@ -7,6 +7,10 @@ A preview of the next release can be installed from
[Babashka](https://github.com/babashka/babashka): Native, fast starting Clojure interpreter for scripting
## Unreleased
- Fix #1679: fix wrapping `timbre/log!`
## 1.3.189 (2024-02-22)
- [#1660](https://github.com/babashka/babashka/issues/1660): add `:deps-root` as part of hash to avoid caching issue with `deps.clj`

View file

@ -70,58 +70,21 @@
:level level, :msg-type msg-type, :args args)]
`(taoensso.timbre/log! ~opts))))
#_(defmacro log! ; Public wrapper around `-log!`
"Core low-level log macro. Useful for tooling, etc.
* `level` - must eval to a valid logging level
* `msg-type` - must eval to e/o #{:p :f nil}
* `opts` - ks e/o #{:config :?err :?ns-str :?file :?line :?base-data :spying?}
Supports compile-time elision when compile-time const vals
provided for `level` and/or `?ns-str`."
[level msg-type args & [opts]]
#_(have [:or nil? sequential?] args) ; To allow -> (delay [~@args])
(let [{:keys [?ns-str] :or {?ns-str (str @sci/ns)}} opts]
(prn :duuu2)
;; level, ns may/not be compile-time consts:
(when-not (timbre/-elide? level ?ns-str)
(let [{:keys [config ?err ?file ?line ?base-data spying?]
:or {config 'taoensso.timbre/*config*
?err :auto ; => Extract as err-type v0
?file @sci/file
;; NB waiting on CLJ-865:
?line (fline &form)}} opts
?file (when (not= ?file "NO_SOURCE_PATH") ?file)
;; Identifies this particular macro expansion; note that this'll
;; be fixed for any fns wrapping `log!` (notably `tools.logging`,
;; `slf4j-timbre`, etc.):
callsite-id
(hash [level msg-type args ; Unevaluated args (arg forms)
?ns-str ?file ?line (rand)])]
(prn :dude :args args)
`(taoensso.timbre/-log! ~config ~level ~?ns-str ~?file ~?line ~msg-type ~?err
(delay [~@args]) ~?base-data ~callsite-id ~spying?)))))
(defn make-ns [ns sci-ns ks]
(reduce (fn [ns-map [var-name var]]
(let [m (meta var)
no-doc (:no-doc m)
doc (:doc m)
arglists (:arglists m)]
(if no-doc ns-map
(assoc ns-map var-name
(sci/new-var (symbol var-name) @var
(cond-> {:ns sci-ns
:name (:name m)}
(:macro m) (assoc :macro true)
doc (assoc :doc doc)
arglists (assoc :arglists arglists)))))))
arglists (assoc :arglists arglists))))))
{}
(select-keys (ns-publics ns) ks)))
(def atomic-println @#'enc/println-atomic)
(defn println-appender
"Returns a simple `println` appender for Clojure/Script.
Use with ClojureScript requires that `cljs.core/*print-fn*` be set.
@ -151,7 +114,7 @@
:*err* @sci/err
stream)]
(binding [*out* stream]
(atomic-println (force output_)))))}))
(enc/println-atomic (force output_)))))}))
(def default-config (assoc-in timbre/*config* [:appenders :println]
(println-appender {:stream :auto})))

View file

@ -45,7 +45,7 @@
hiccup/hiccup {:mvn/version "2.0.0-RC1"}
rewrite-clj/rewrite-clj {:mvn/version "1.1.47"}
selmer/selmer {:mvn/version "1.12.59"}
com.taoensso/timbre {:mvn/version "6.0.1"}
com.taoensso/timbre {:mvn/version "6.5.0"}
org.clojure/tools.logging {:mvn/version "1.1.0"}
org.clojure/data.priority-map {:mvn/version "1.1.0"}
insn/insn {:mvn/version "0.5.2"}

View file

@ -44,7 +44,7 @@
(deftest logging-test
(let [res (tu/bb nil (pr-str program))]
(is (= 17 (count (re-seq #"\[dude:.\]" res))))
(is (= 8 (count (re-seq #"\[dude:.\]" res))))
(is (= 6 (count (re-seq #"DEBUG" res))))
(is (= 11 (count (re-seq #"INFO" res)))))
(testing "println appender works with with-out-str"
@ -110,3 +110,11 @@
(is (= 3 (count (re-seq #"\"test warn\"" res)))))
(testing "lists are printed readably"
(is (= 2 (count (re-seq #"\(\\a \\b\)" res)))))))
(deftest timbre-log!-test
(is (str/includes? (tu/bb nil
(pr-str '(do (require '[taoensso.timbre :as timbre])
(defn log-wrapper [& args]
(timbre/log! :info :p args))
(log-wrapper "hallo"))))
"hallo")))