Merge pull request #63 from jameswarren/thread-local-config

Add thread-configurable logging (@jameswarren)
This commit is contained in:
Peter Taoussanis 2014-05-06 13:05:43 +07:00
commit 07d34b0626
1 changed files with 10 additions and 3 deletions

View File

@ -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*)]))