Skip to content

Commit

Permalink
[#116] Add :context key to appender data (@mikesperber)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaoussanis committed Jul 29, 2015
1 parent b37ace0 commit 02531eb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,9 @@ This is the biggest win over Java logging IMO. Here's `timbre/example-config` (a
:output-fn ; (fn [data]) -> formatted output string
; (see `default-output-fn` for details)
:context ; *context* value at log time (see `with-context`)
:profile-stats ; From `profile` macro
Also incl. any `*context*` keys (see `with-context`).
MIDDLEWARE
Middleware are simple (fn [data]) -> ?data fns (applied left->right) that
transform the data map dispatched to appender fns. If any middleware returns
Expand Down
15 changes: 9 additions & 6 deletions src/taoensso/timbre.cljx
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,9 @@
:output-fn ; (fn [data]) -> formatted output string
; (see `default-output-fn` for details)
:context ; *context* value at log time (see `with-context`)
:profile-stats ; From `profile` macro
Also incl. any `*context*` keys (see `with-context`).
MIDDLEWARE
Middleware are simple (fn [data]) -> ?data fns (applied left->right) that
transform the data map dispatched to appender fns. If any middleware returns
Expand Down Expand Up @@ -298,8 +297,8 @@
)

(def ^:dynamic *context*
"General-purpose dynamic logging context. Context will be merged into
appender data map at logging time." nil)
"General-purpose dynamic logging context. Context will be included in appender
data map at logging time." nil)
(defmacro with-context [context & body] `(binding [*context* ~context] ~@body))

(declare get-hostname)
Expand Down Expand Up @@ -327,9 +326,13 @@
vargs*_ (delay (vsplit-err1 (force vargs_)))
?err_ (delay (get @vargs*_ 0))
vargs_ (delay (get @vargs*_ 1))
data (merge ?base-data *context*
context *context*
data (merge ?base-data
;; No, better nest than merge (appenders may want to pass
;; along arb context w/o knowing context keys, etc.):
(when (map? context) context) ; DEPRECATED, for back compat
{:config config ; Entire config!
;; :context *context* ; Extra destructure's a nuisance
:context context
:instant instant
:level level
:?ns-str ?ns-str
Expand Down

0 comments on commit 02531eb

Please sign in to comment.