Skip to content

Commit

Permalink
[new] Add :output-opts support to top-level and appender config
Browse files Browse the repository at this point in the history
Provides a flexible, convenient, and data-oriented way of controlling
behaviour of default or custom output fns.
  • Loading branch information
ptaoussanis committed Oct 23, 2022
1 parent 2823c47 commit baaf138
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/taoensso/timbre.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@
:timestamp-opts ; Config map, see `default-timestamp-opts`
:output-fn ; (fn [data]) -> string output_, see `default-output-fn`
:output-opts ; Optional map added to data sent to output-fn
:appenders ; {<appender-id> <appender-map>}
Expand Down Expand Up @@ -277,8 +278,10 @@
; (timbre/infof ^:meta {:id \"my-limiter-call-id\"} ...)
;
:output-fn ; Optional override for inherited (fn [data]) -> string output_
:timestamp-opts ; Optional override for inherited config map
:timestamp-opts ; Optional appender-specific override for top-level option
:output-fn ; Optional appender-specific override for top-level option
:output-opts ; Optional appender-specific override for top-level option
:fn ; (fn [data]) -> side-effects, with keys described below
LOG DATA
Expand Down Expand Up @@ -799,7 +802,9 @@
)

base-fn
?appender-fn)))]
?appender-fn)))

base-output-opts (get config :output-opts)]

(reduce-kv
(fn [_ id appender]
Expand All @@ -815,16 +820,21 @@
(when rate-limit-okay?
(let [{:keys [async?] apfn :fn} appender

timestamp_ (get-timestamp-delay (get appender :timestamp-opts))
output-fn (get-output-fn (get appender :output-fn))
timestamp_ (get-timestamp-delay (get appender :timestamp-opts))
output-fn (get-output-fn (get appender :output-fn))
output-opts (or (get appender :output-opts) base-output-opts)
output_
(delay
(output-fn (assoc data :timestamp_ timestamp_)))
(output-fn
(assoc data
:timestamp_ timestamp_
:output-opts output-opts)))

data
(conj data
{:appender-id id
:appender appender
:output-opts output-opts
:output-fn output-fn
:output_ output_
:timestamp_ timestamp_})
Expand Down

0 comments on commit baaf138

Please sign in to comment.