|
7 | 7 | [clojure.tools.logging.test :as log-test :refer [logged? |
8 | 8 | matches]])) |
9 | 9 |
|
10 | | -; TODO: Improve tools.logging.test so that the ability to check the thread is |
11 | | -; not so hacky/out-of-band from the normal flow. |
12 | 10 |
|
13 | | - |
14 | | -(defn log-entry-with-thread [logger-ns level throwable message] |
| 11 | +(defn log-entry-with-thread |
| 12 | + "Returns a log entry that also captures the current thread." |
| 13 | + [logger-ns level throwable message] |
15 | 14 | (assoc (log-test/->LogEntry logger-ns level throwable message) |
16 | 15 | ::thread (Thread/currentThread))) |
17 | 16 |
|
18 | | -(defn same-thread? [log-entry] |
| 17 | +(defn same-thread? |
| 18 | + "Returns true if the thread that created the log entry is the current thread." |
| 19 | + [log-entry] |
| 20 | + (when-not (::thread log-entry) |
| 21 | + (throw (ex-info "Log entry does not have a thread." log-entry))) |
19 | 22 | (identical? (::thread log-entry) |
20 | 23 | (Thread/currentThread))) |
21 | 24 |
|
22 | | -(defn direct-logged? [logger-ns level throwable message] |
| 25 | +(defn direct-logged? |
| 26 | + "Returns true if there is a matching entry that also was created with the |
| 27 | + current thread, i.e., not via an agent." |
| 28 | + [logger-ns level throwable message] |
23 | 29 | (->> (log-test/matches logger-ns level throwable message) |
24 | 30 | (filter same-thread?) |
25 | 31 | seq |
26 | 32 | boolean)) |
27 | 33 |
|
28 | | -(defn agent-logged? [logger-ns level throwable message] |
| 34 | +(defn agent-logged? |
| 35 | + "Returns true if there is a matching entry that also was created with a thread |
| 36 | + other than the current thread, i.e., via an agent." |
| 37 | + [logger-ns level throwable message] |
29 | 38 | (->> (log-test/matches logger-ns level throwable message) |
30 | 39 | (remove same-thread?) |
31 | 40 | seq |
32 | 41 | boolean)) |
33 | 42 |
|
34 | | -(defmacro with-log [& body] |
| 43 | +(defmacro with-log |
| 44 | + [& body] |
35 | 45 | `(let [stateful-log# (log-test/atomic-log log-entry-with-thread) |
36 | 46 | logger-factory# (log-test/logger-factory stateful-log# (constantly true))] |
37 | 47 | (binding [log-test/*stateful-log* stateful-log# |
|
0 commit comments