Add simple file spit appender

This commit is contained in:
Peter Taoussanis 2012-10-19 15:24:46 +07:00
parent dc995c10ad
commit 92e31c7b7c
2 changed files with 14 additions and 1 deletions

View File

@ -109,6 +109,7 @@ Configuring Timbre couldn't be simpler. Let's check out (some of) the defaults:
:appenders
{:standard-out { <...> }
:spit { <...> }
<...> }
:shared-appender-config {}}

View File

@ -61,7 +61,19 @@
:max-message-per-msecs nil
:fn (fn [{:keys [error? prefix message more]}]
(binding [*out* (if error? *err* *out*)]
(apply str-println prefix "-" message more)))}}}))
(apply str-println prefix "-" message more)))}
:spit
{:doc "Spits to (:spit-filename :shared-appender-config) file."
:min-level nil :enabled? false :async? false
:max-message-per-msecs nil
:fn (fn [{:keys [ap-config prefix message more]}]
(when-let [filename (:spit-filename ap-config)]
(try (spit filename
(with-out-str (apply str-println prefix "-"
message more))
:append true)
(catch java.io.IOException _))))}}}))
(defn set-config! [[k & ks] val] (swap! config assoc-in (cons k ks) val))
(defn set-level! [level] (set-config! [:current-level] level))