File tree Expand file tree Collapse file tree 3 files changed +25
-0
lines changed
main/clojure/clojure/tools/logging
test/clojure/clojure/tools/logging Expand file tree Collapse file tree 3 files changed +25
-0
lines changed 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.
6
6
([ despite its flaws] ( https://www.youtube.com/watch?v=oyLBGkS5ICk ) ).
7
7
8
8
## [ Unreleased]
9
+ ### Added
10
+ - Add implementation of ` spyf ` to ` clojure.tools.logging.readable ` .
11
+
9
12
### Changed
10
13
- Decreased the per-call overhead when using SLF4J, Commons Logging, and Log4j2.
11
14
Previously, their associated ` logger-factory ` implementations were calling
Original file line number Diff line number Diff line change 159
159
{:arglists '([fmt & fmt-args] [throwable fmt & fmt-args])}
160
160
[& args]
161
161
`(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 188
188
(is (logged? " clojure.tools.logging.test-readable" :debug e " hello \" world\" " )))))
189
189
190
190
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
+
191
203
(deftest println-style
192
204
(are [f kw] (with-log
193
205
(f " hello" " world" )
You can’t perform that action at this time.
0 commit comments