Per-appender prefix-fns

This commit is contained in:
Emlyn Corrin 2013-04-19 18:01:55 +01:00
parent 3eee832a63
commit 3302d17af6
2 changed files with 12 additions and 5 deletions

View File

@ -132,10 +132,18 @@
(defn- wrap-appender-fn
"Wraps compile-time appender fn with additional runtime capabilities
controlled by compile-time config."
[{apfn :fn :keys [async? max-message-per-msecs] :as appender}]
[{apfn :fn :keys [async? max-message-per-msecs prefix-fn] :as appender}]
(->> ; Wrapping applies capabilities bottom-to-top
apfn
;; Wrap for per-appender prefix-fn support
((fn [apfn]
(if-not prefix-fn
apfn
(fn [apfn-args]
(apfn (assoc apfn-args
:prefix (prefix-fn apfn-args)))))))
;; Wrap for runtime flood-safety support
((fn [apfn]
(if-not max-message-per-msecs
@ -407,4 +415,4 @@
(if (contains? message :password)
(assoc args :message (assoc message :password "*****"))
args)
:else args))]))
:else args))]))

View File

@ -32,9 +32,7 @@
(when-let [irc-config (:irc ap-config)]
(send-message
(assoc irc-config
:prefix (if-let [prefix-fn (:prefix-fn irc-config)]
(prefix-fn prefix)
prefix)
:prefix prefix
:message message))))
(def irc-appender
@ -44,4 +42,5 @@
:name \"My Logger\" :chan \"#logs\"")
:min-level :info :enabled? true :async? false
:max-message-per-msecs nil ; no rate limit by default
:prefix-fn (fn [{:keys [level]}] (-> level name str/upper-case))
:fn appender-fn})