[#207] BREAKING: simplify impl., middleware no longer receive :msg_ or :hash_

These weren't used often (ever?) in middleware, and the removal allows
for a simpler+faster implementation here.
This commit is contained in:
Peter Taoussanis 2016-12-17 17:20:44 +01:00
parent e4f33c5341
commit 9b9dd210cc
1 changed files with 33 additions and 38 deletions

View File

@ -19,8 +19,8 @@
[taoensso.timbre :as timbre-macros :refer ()])) [taoensso.timbre :as timbre-macros :refer ()]))
(if (vector? taoensso.encore/encore-version) (if (vector? taoensso.encore/encore-version)
(enc/assert-min-encore-version [2 67 2]) (enc/assert-min-encore-version [2 87 0])
(enc/assert-min-encore-version 2.67)) (enc/assert-min-encore-version 2.87))
;;;; Config ;;;; Config
@ -348,29 +348,10 @@
(when (may-log? level ?ns-str config) (when (may-log? level ?ns-str config)
(let [instant (enc/now-dt) (let [instant (enc/now-dt)
context *context* context *context*
vargs1 @vargs_ vargs @vargs_
[?err ?meta ?msg-fmt vargs1] (parse-vargs ?err msg-type vargs1) [?err ?meta ?msg-fmt vargs]
(parse-vargs ?err msg-type vargs)
final-vargs_ (atom vargs1) ; Allow middleware to influece msg_
msg_
(case msg-type
nil ""
:p (delay (str-join @final-vargs_))
:f (do
(have? string? ?msg-fmt)
(delay (enc/format* @final-vargs_))))
;; Uniquely identifies a particular logging call for purposes of
;; rate limiting, etc.
hash_
(delay
(hash
;; Nb excl. instant
[callsite-id ; Only useful for direct macro calls
?msg-fmt
(get ?meta :hash ; Explicit hash provided
@final-vargs_)]))
data ; Pre-middleware data ; Pre-middleware
(conj (conj
@ -384,18 +365,11 @@
:?line ?line :?line ?line
#+clj :hostname_ #+clj (delay (get-hostname)) #+clj :hostname_ #+clj (delay (get-hostname))
:error-level? (#{:error :fatal} level) :error-level? (#{:error :fatal} level)
:?err_ (delay ?err) ; Deprecated
:vargs_ (delay @final-vargs_) ; ''
:?err ?err :?err ?err
:?meta ?meta ; TODO Undocumented (experimental) :?err_ (delay ?err) ; Deprecated
:?msg-fmt ?msg-fmt ; '' :?meta ?meta ; Undocumented
:hash_ hash_ ; '' :?msg-fmt ?msg-fmt ; Undocumented
:vargs vargs1 :vargs vargs})
:msg_ msg_})
?middleware (:middleware config)
?data ; Post middleware ?data ; Post middleware
(reduce ; Apply middleware: data->?data (reduce ; Apply middleware: data->?data
@ -405,11 +379,32 @@
(reduced nil) (reduced nil)
result))) result)))
data data
?middleware)] (:middleware config))]
(when-let [data ?data] ; Not filtered by middleware (when-let [data ?data] ; Not filtered by middleware
(reset! final-vargs_ (:vargs data)) (let [{:keys [vargs]} data
(let [;; Optimization: try maximize output+timestamp sharing data (assoc data :vargs_ (delay vargs)) ; Deprecated
data
(enc/assoc-nx data
:msg_
(delay
(case msg-type
nil ""
:p (str-join vargs)
:f (enc/format* (have string? ?msg-fmt) vargs)))
;; Uniquely identifies a particular logging call for
;; rate limiting, etc.
:hash_
(delay
(hash
;; Nb excl. instant
[callsite-id ; Only useful for direct macro calls
?msg-fmt
(get ?meta :hash ; Explicit hash provided
vargs)])))
;; Optimization: try maximize output+timestamp sharing
;; between appenders ;; between appenders
output-fn1 (enc/memoize_ (get config :output-fn default-output-fn)) output-fn1 (enc/memoize_ (get config :output-fn default-output-fn))
#+clj timestamp-opts1 #+clj (conj default-timestamp-opts (get config :timestamp-opts)) #+clj timestamp-opts1 #+clj (conj default-timestamp-opts (get config :timestamp-opts))