File tree Expand file tree Collapse file tree
main/clojure/clojure/tools/logging
test/clojure/clojure/tools/logging Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66([ despite its flaws] ( https://www.youtube.com/watch?v=oyLBGkS5ICk ) ).
77
88## [ Unreleased]
9+ ### Added
10+ - Add implementation of ` spyf ` to ` clojure.tools.logging.readable ` .
11+
912### Changed
1013- Decreased the per-call overhead when using SLF4J, Commons Logging, and Log4j2.
1114 Previously, their associated ` logger-factory ` implementations were calling
Original file line number Diff line number Diff line change 159159 {:arglists '([fmt & fmt-args] [throwable fmt & fmt-args])}
160160 [& args]
161161 `(logf :fatal ~@args))
162+
163+ (defmacro spyf
164+ " Evaluates expr and may write (logf level fmt result) to the log. Returns the
165+ result of expr. Defaults to :debug log level."
166+ ([fmt expr]
167+ `(spyf :debug ~fmt ~expr))
168+ ([level fmt expr]
169+ `(let [a# ~expr]
170+ (logf ~level ~fmt a#)
171+ a#)))
Original file line number Diff line number Diff line change 188188 (is (logged? " clojure.tools.logging.test-readable" :debug e " hello \" world\" " )))))
189189
190190
191+ (deftest spyf-default
192+ (with-log
193+ (spyf " result: %s" (str " hello" " " " world" ))
194+ (is (logged? " clojure.tools.logging.test-readable" :debug nil " result: \" hello world\" " ))))
195+
196+ (deftest spyf-level
197+ (doseq [level #{:trace :debug :info :warn :error :fatal }]
198+ (with-log
199+ (spyf level " result: %s" (str " hello" " " " world" ))
200+ (is (logged? " clojure.tools.logging.test-readable" level nil " result: \" hello world\" " )))))
201+
202+
191203(deftest println-style
192204 (are [f kw] (with-log
193205 (f " hello" " world" )
You can’t perform that action at this time.
0 commit comments