diff --git a/src/taoensso/timbre.clj b/src/taoensso/timbre.clj index aada6e7..00ba307 100644 --- a/src/taoensso/timbre.clj +++ b/src/taoensso/timbre.clj @@ -397,6 +397,11 @@ })) nil)) +(def ^:dynamic *config-dynamic* nil) +(defmacro with-logging-config + "Allows thread-local logging config override. Useful for dev & testing." + [config & body] `(binding [*config-dynamic* ~config] ~@body)) + (defmacro log* "Implementation detail." {:arglists '([base-appender-args msg-type level & log-args] [base-appender-args msg-type config level & log-args])} @@ -412,7 +417,7 @@ `(let [;;; Support [level & log-args], [config level & log-args] sigs: s1# ~s1 default-config?# (levels-scored s1#) - config# (if default-config?# @config s1#) + config# (if default-config?# (or *config-dynamic* @config) s1#) level# (if default-config?# s1# ~s2) compile-time-ns# ~(str *ns*)] ;; (println "DEBUG: Runtime level check") @@ -495,7 +500,8 @@ '[taoensso.timbre :as timbre :refer (log trace debug info warn error fatal report logf tracef debugf infof warnf errorf fatalf reportf - spy logged-future with-log-level sometimes)]) + spy logged-future with-log-level with-logging-config + sometimes)]) (require '[taoensso.timbre.profiling :as profiling :refer (pspy pspy* profile defnp p p*)])" @@ -504,7 +510,8 @@ '[taoensso.timbre :as timbre :refer (log trace debug info warn error fatal report logf tracef debugf infof warnf errorf fatalf reportf - spy logged-future with-log-level sometimes)]) + spy logged-future with-log-level with-logging-config + sometimes)]) (require '[taoensso.timbre.profiling :as profiling :refer (pspy pspy* profile defnp p p*)]))