|
10 | 10 |
|
11 | 11 | (def ^:dynamic ^:private innermost-exception)
|
12 | 12 |
|
13 |
| -(def ^:dynamic *log-traces* "A boolean to control the whether traces are logged at :trace level as they are created" false) |
| 13 | +(def ^:dynamic *log-traces* |
| 14 | + "A boolean to control the whether traces are logged at :trace level as they are created." |
| 15 | + false) |
14 | 16 |
|
15 | 17 | (defn- trace-to-string
|
16 | 18 | "Converts a trace to a string; a trace may be a function which is invoked."
|
|
29 | 31 | (defn track*
|
30 | 32 | "Tracks the execution of a function of no arguments. The trace macro converts into a call to track*.
|
31 | 33 |
|
32 |
| - logger - SLF4J Logger where logging should occur |
33 |
| - trace-message - String, object, or function. Function evaulation is deferred until an exception is actually thrown. |
34 |
| - f - function to invoke." |
| 34 | + logger |
| 35 | + : SLF4J Logger where logging should occur |
| 36 | +
|
| 37 | + trace-message |
| 38 | + : String, object, or function. If a function, the function will only be evaluated if the message |
| 39 | + needs to be printed (when an exception occurs, or when logging traces via [[*log-traces*]]). |
| 40 | +
|
| 41 | + f |
| 42 | + : function to invoke. track* returns the result from this function." |
35 | 43 | [logger trace f]
|
36 | 44 | (if (bound? #'operation-traces)
|
37 | 45 | (try
|
38 | 46 | (swap! operation-traces conj trace)
|
39 |
| - (when *log-traces* (l/log* logger :trace nil trace)) |
| 47 | + (when *log-traces* (l/log* logger :trace nil (trace-to-string trace))) |
40 | 48 | (f)
|
41 | 49 | (catch Throwable e
|
42 | 50 | (if @innermost-exception
|
|
67 | 75 | point of the exception will be logged (the logger is determined from the current namespace); thus logging only occurs at the
|
68 | 76 | most deeply nested trace. The exception thrown is formatted and logged as well.
|
69 | 77 |
|
70 |
| - trace may be a string, or a function that returns a string; execution of the function is deferred until needed. " |
| 78 | + trace may be a string, an object, or a function that returns a string; execution of the function is deferred until needed." |
71 | 79 | [trace & body]
|
72 | 80 | `(track* (get-logger ~*ns*) ~trace #(do ~@body)))
|
73 | 81 |
|
|
0 commit comments