mirror of https://github.com/status-im/timbre.git
Rename appender argument: :max-message-per-msecs -> :limit-per-msecs (backwards compatible)
This commit is contained in:
parent
c30ae5fbcc
commit
6fc6baee37
|
@ -16,7 +16,7 @@ Timbre is an attempt to make **simple logging simple** and more **complex loggin
|
||||||
* **Decent performance** (low overhead).
|
* **Decent performance** (low overhead).
|
||||||
* Flexible **fn-centric appender model** with **middleware**.
|
* Flexible **fn-centric appender model** with **middleware**.
|
||||||
* Sensible built-in appenders including simple **email appender**.
|
* Sensible built-in appenders including simple **email appender**.
|
||||||
* Tunable **flood control** and **asynchronous** logging support.
|
* Tunable **rate limit** and **asynchronous** logging support.
|
||||||
* Robust **namespace filtering**.
|
* Robust **namespace filtering**.
|
||||||
* Dead-simple, logging-level-aware **logging profiler**.
|
* Dead-simple, logging-level-aware **logging profiler**.
|
||||||
|
|
||||||
|
@ -137,8 +137,8 @@ Filter logging output by namespaces:
|
||||||
^{:host "mail.isp.net" :user "jsmith" :pass "sekrat!!1"}
|
^{:host "mail.isp.net" :user "jsmith" :pass "sekrat!!1"}
|
||||||
{:from "me@draines.com" :to "foo@example.com"})
|
{:from "me@draines.com" :to "foo@example.com"})
|
||||||
|
|
||||||
;; Rate-limit to one email per message per minute
|
;; Rate limit to one email per message per minute
|
||||||
(timbre/set-config! [:appenders :postal :max-message-per-msecs] 60000)
|
(timbre/set-config! [:appenders :postal :limit-per-msecs] 60000)
|
||||||
|
|
||||||
;; Make sure emails are sent asynchronously
|
;; Make sure emails are sent asynchronously
|
||||||
(timbre/set-config! [:appenders :postal :async?] true)
|
(timbre/set-config! [:appenders :postal :async?] true)
|
||||||
|
@ -170,7 +170,7 @@ Writing a custom appender is dead-easy:
|
||||||
:min-level :debug
|
:min-level :debug
|
||||||
:enabled? true
|
:enabled? true
|
||||||
:async? false
|
:async? false
|
||||||
:max-message-per-msecs nil ; No rate limiting
|
:limit-per-msecs nil ; No rate limit
|
||||||
:fn (fn [{:keys [ap-config level prefix message more] :as args}]
|
:fn (fn [{:keys [ap-config level prefix message more] :as args}]
|
||||||
(when-not (:my-production-mode? ap-config)
|
(when-not (:my-production-mode? ap-config)
|
||||||
(apply println prefix "Hello world!" message more)))
|
(apply println prefix "Hello world!" message more)))
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
|
|
||||||
APPENDERS
|
APPENDERS
|
||||||
An appender is a map with keys:
|
An appender is a map with keys:
|
||||||
:doc, :min-level, :enabled?, :async?, :max-message-per-msecs, :fn
|
:doc, :min-level, :enabled?, :async?, :limit-per-msecs, :fn
|
||||||
|
|
||||||
An appender's fn takes a single map argument with keys:
|
An appender's fn takes a single map argument with keys:
|
||||||
:level, :message, :more ; From all logging macros (`info`, etc.)
|
:level, :message, :more ; From all logging macros (`info`, etc.)
|
||||||
|
@ -88,16 +88,14 @@
|
||||||
:appenders
|
:appenders
|
||||||
{:standard-out
|
{:standard-out
|
||||||
{:doc "Prints to *out* or *err* as appropriate. Enabled by default."
|
{:doc "Prints to *out* or *err* as appropriate. Enabled by default."
|
||||||
:min-level nil :enabled? true :async? false
|
:min-level nil :enabled? true :async? false :limit-per-msecs nil
|
||||||
:max-message-per-msecs nil
|
|
||||||
:fn (fn [{:keys [error? prefix message more]}]
|
:fn (fn [{:keys [error? prefix message more]}]
|
||||||
(binding [*out* (if error? *err* *out*)]
|
(binding [*out* (if error? *err* *out*)]
|
||||||
(apply str-println prefix "-" message more)))}
|
(apply str-println prefix "-" message more)))}
|
||||||
|
|
||||||
:spit
|
:spit
|
||||||
{:doc "Spits to (:spit-filename :shared-appender-config) file."
|
{:doc "Spits to (:spit-filename :shared-appender-config) file."
|
||||||
:min-level nil :enabled? false :async? false
|
:min-level nil :enabled? false :async? false :limit-per-msecs nil
|
||||||
:max-message-per-msecs nil
|
|
||||||
:fn (fn [{:keys [ap-config prefix message more]}]
|
:fn (fn [{:keys [ap-config prefix message more]}]
|
||||||
(when-let [filename (:spit-filename ap-config)]
|
(when-let [filename (:spit-filename ap-config)]
|
||||||
(try (spit filename
|
(try (spit filename
|
||||||
|
@ -132,11 +130,13 @@
|
||||||
(defn- wrap-appender-fn
|
(defn- wrap-appender-fn
|
||||||
"Wraps compile-time appender fn with additional runtime capabilities
|
"Wraps compile-time appender fn with additional runtime capabilities
|
||||||
controlled by compile-time config."
|
controlled by compile-time config."
|
||||||
[{apfn :fn :keys [async? max-message-per-msecs prefix-fn] :as appender}]
|
[{apfn :fn :keys [async? limit-per-msecs prefix-fn] :as appender}]
|
||||||
|
(let [limit-per-msecs (or (:max-message-per-msecs appender)
|
||||||
|
limit-per-msecs)] ; Backwards-compatibility
|
||||||
(->> ; Wrapping applies per appender, bottom-to-top
|
(->> ; Wrapping applies per appender, bottom-to-top
|
||||||
apfn
|
apfn
|
||||||
|
|
||||||
;; Prefix-fn support
|
;; Per-appender prefix-fn support (cmp. default prefix-fn)
|
||||||
((fn [apfn]
|
((fn [apfn]
|
||||||
(if-not prefix-fn
|
(if-not prefix-fn
|
||||||
apfn
|
apfn
|
||||||
|
@ -146,7 +146,7 @@
|
||||||
|
|
||||||
;; Rate limit support
|
;; Rate limit support
|
||||||
((fn [apfn]
|
((fn [apfn]
|
||||||
(if-not max-message-per-msecs
|
(if-not limit-per-msecs
|
||||||
apfn
|
apfn
|
||||||
(let [;; {:hash last-appended-time-msecs ...}
|
(let [;; {:hash last-appended-time-msecs ...}
|
||||||
flood-timers (atom {})]
|
flood-timers (atom {})]
|
||||||
|
@ -156,7 +156,7 @@
|
||||||
hash (str ns "/" message)
|
hash (str ns "/" message)
|
||||||
allow? (fn [last-msecs]
|
allow? (fn [last-msecs]
|
||||||
(or (not last-msecs)
|
(or (not last-msecs)
|
||||||
(> (- now last-msecs) max-message-per-msecs)))]
|
(> (- now last-msecs) limit-per-msecs)))]
|
||||||
|
|
||||||
(when (allow? (@flood-timers hash))
|
(when (allow? (@flood-timers hash))
|
||||||
(apfn apfn-args)
|
(apfn apfn-args)
|
||||||
|
@ -178,7 +178,7 @@
|
||||||
(if-not async?
|
(if-not async?
|
||||||
apfn
|
apfn
|
||||||
(let [agent (agent nil :error-mode :continue)]
|
(let [agent (agent nil :error-mode :continue)]
|
||||||
(fn [apfn-args] (send-off agent (fn [_] (apfn apfn-args))))))))))
|
(fn [apfn-args] (send-off agent (fn [_] (apfn apfn-args)))))))))))
|
||||||
|
|
||||||
(defn- make-timestamp-fn
|
(defn- make-timestamp-fn
|
||||||
"Returns a unary fn that formats instants using given pattern string and an
|
"Returns a unary fn that formats instants using given pattern string and an
|
||||||
|
|
|
@ -39,7 +39,6 @@
|
||||||
"Needs :irc config map in :shared-appender-config, e.g.:
|
"Needs :irc config map in :shared-appender-config, e.g.:
|
||||||
{:host \"irc.example.org\" :port 6667 :nick \"logger\"
|
{:host \"irc.example.org\" :port 6667 :nick \"logger\"
|
||||||
:name \"My Logger\" :chan \"#logs\"")
|
:name \"My Logger\" :chan \"#logs\"")
|
||||||
:min-level :info :enabled? true :async? false
|
:min-level :info :enabled? true :async? false :limit-per-msecs nil
|
||||||
:max-message-per-msecs nil ; no rate limit by default
|
|
||||||
:prefix-fn (fn [{:keys [level]}] (-> level name str/upper-case))
|
:prefix-fn (fn [{:keys [level]}] (-> level name str/upper-case))
|
||||||
:fn appender-fn})
|
:fn appender-fn})
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
^{:host \"mail.isp.net\" :user \"jsmith\" :pass \"sekrat!!1\"}
|
^{:host \"mail.isp.net\" :user \"jsmith\" :pass \"sekrat!!1\"}
|
||||||
{:from \"Bob's logger <me@draines.com>\" :to \"foo@example.com\"}")
|
{:from \"Bob's logger <me@draines.com>\" :to \"foo@example.com\"}")
|
||||||
:min-level :error :enabled? true :async? true
|
:min-level :error :enabled? true :async? true
|
||||||
:max-message-per-msecs (* 1000 60 10) ; 1 email per message per 10 mins
|
:limit-per-msecs (* 1000 60 10) ; 1 subject / 10 mins
|
||||||
:fn (fn [{:keys [ap-config prefix message more]}]
|
:fn (fn [{:keys [ap-config prefix message more]}]
|
||||||
(when-let [postal-config (:postal ap-config)]
|
(when-let [postal-config (:postal ap-config)]
|
||||||
(postal/send-message
|
(postal/send-message
|
||||||
|
|
Loading…
Reference in New Issue