Minor breaking: renamed 2 "instant" keys

* instant-pattern -> timestamp-pattern
* instant-formatter -> timestamp-fn

Also:
* Updated README.
* A few formatting tweaks.

Signed-off-by: Peter Taoussanis <p.taoussanis@gmail.com>
This commit is contained in:
Peter Taoussanis 2012-05-30 20:07:34 +07:00
parent dde1b89b03
commit fe7e69bf92
2 changed files with 27 additions and 27 deletions

View File

@ -71,10 +71,10 @@ Easily adjust the current logging level:
(timbre/set-level! :warn) (timbre/set-level! :warn)
``` ```
And the default instant formatting for log messages: And the default timestamp formatting for log messages:
```clojure ```clojure
(timbre/set-config! [:shared-appender-config :instant-pattern] (timbre/set-config! [:shared-appender-config :timestamp-pattern]
"yyyy-MMM-dd HH:mm:ss ZZ") "yyyy-MMM-dd HH:mm:ss ZZ")
(timbre/set-config! [:shared-appender-config :locale] (timbre/set-config! [:shared-appender-config :locale]
(java.util.Locale/GERMAN)) (java.util.Locale/GERMAN))
@ -114,7 +114,7 @@ Writing a custom appender is easy:
:enabled? true :enabled? true
:async? false :async? false
:max-message-per-msecs nil ; No rate limiting :max-message-per-msecs nil ; No rate limiting
:fn (fn [{:keys [ap-config level error? instant instant-formatter :fn (fn [{:keys [ap-config level error? instant timestamp-fn
ns message more] :as args}] ns message more] :as args}]
(when-not (:production-mode? ap-config) (when-not (:production-mode? ap-config)
(apply println instant "Hello world!" message more))) (apply println instant "Hello world!" message more)))

View File

@ -10,9 +10,9 @@
;;;; Default configuration and appenders ;;;; Default configuration and appenders
(defn prefixed-message (defn prefixed-message
"<formatted-instant> LEVEL [ns] - message" "timestamp LEVEL [ns] - message"
[{:keys [level instant instant-formatter ns message]}] [{:keys [level instant timestamp-fn ns message]}]
(str (instant-formatter instant) " " (-> level name str/upper-case) (str (timestamp-fn instant) " " (-> level name str/upper-case)
" [" ns "] - " message)) " [" ns "] - " message))
(def config (def config
@ -23,7 +23,7 @@
:doc, :min-level, :enabled?, :async?, :max-message-per-msecs, :fn? :doc, :min-level, :enabled?, :async?, :max-message-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:
:ap-config, :level, :error?, :instant, :instant-formatter, :ns, :ap-config, :level, :error?, :instant, :timestamp-fn, :ns,
:message, :more :message, :more
See source code for examples." See source code for examples."
@ -34,14 +34,14 @@
{:doc "Prints everything to *out*." {:doc "Prints everything to *out*."
:min-level :debug :enabled? false :async? false :min-level :debug :enabled? false :async? false
:max-message-per-msecs nil :max-message-per-msecs nil
:fn (fn [{:keys [level instant ns message more] :as args}] :fn (fn [{:keys [more] :as args}]
(apply println (prefixed-message args) more))} (apply println (prefixed-message args) more))}
:standard-out-or-err :standard-out-or-err
{:doc "Prints to *out* or *err* as appropriate. Enabled by default." {:doc "Prints to *out* or *err* as appropriate. Enabled by default."
:min-level :debug :enabled? true :async? false :min-level :debug :enabled? true :async? false
:max-message-per-msecs nil :max-message-per-msecs nil
:fn (fn [{:keys [level error? instant ns message more] :as args}] :fn (fn [{:keys [error? more] :as args}]
(binding [*out* (if error? *err* *out*)] (binding [*out* (if error? *err* *out*)]
(apply println (prefixed-message args) more)))} (apply println (prefixed-message args) more)))}
@ -50,7 +50,7 @@
"Needs :postal config map in :shared-appender-config.") "Needs :postal config map in :shared-appender-config.")
:min-level :error :enabled? false :async? true :min-level :error :enabled? false :async? true
:max-message-per-msecs (* 60 60 2) :max-message-per-msecs (* 60 60 2)
:fn (fn [{:keys [ap-config level instant ns message more] :as args}] :fn (fn [{:keys [ap-config more] :as args}]
(when-let [postal-config (:postal ap-config)] (when-let [postal-config (:postal ap-config)]
(postal/send-message (postal/send-message
(assoc postal-config (assoc postal-config
@ -59,7 +59,7 @@
"<no additional arguments>")))))}} "<no additional arguments>")))))}}
:shared-appender-config :shared-appender-config
{:instant-pattern "yyyy-MMM-dd HH:mm:ss ZZ" ; SimpleDateFormat pattern {:timestamp-pattern "yyyy-MMM-dd HH:mm:ss ZZ" ; SimpleDateFormat pattern
:locale nil ; A Locale object, or nil :locale nil ; A Locale object, or nil
;; A Postal message map, or nil. ;; A Postal message map, or nil.
;; ^{:host "mail.isp.net" :user "jsmith" :pass "sekrat!!1"} ;; ^{:host "mail.isp.net" :user "jsmith" :pass "sekrat!!1"}
@ -82,16 +82,16 @@
;;;; Appender-fn decoration ;;;; Appender-fn decoration
(defn- make-instant-formatter (defn- make-timestamp-fn
"Returns unary fn to format an instant using given pattern string and optional "Returns a unary fn that formats instants using given pattern string and an
locale." optional locale."
[^String pattern ^Locale locale] [^String pattern ^Locale locale]
(let [format (if locale (let [format (if locale
(SimpleDateFormat. pattern locale) (SimpleDateFormat. pattern locale)
(SimpleDateFormat. pattern))] (SimpleDateFormat. pattern))]
(fn [^Date instant] (.format ^SimpleDateFormat format instant)))) (fn [^Date instant] (.format ^SimpleDateFormat format instant))))
(comment ((make-instant-formatter "yyyy-MMM-dd" nil) (Date.))) (comment ((make-timestamp-fn "yyyy-MMM-dd" nil) (Date.)))
(defn- wrap-appender-fn (defn- wrap-appender-fn
"Wraps compile-time appender fn with additional capabilities controlled by "Wraps compile-time appender fn with additional capabilities controlled by
@ -100,12 +100,12 @@
(-> (->
;; Wrap to add compile-time stuff to runtime appender arguments ;; Wrap to add compile-time stuff to runtime appender arguments
(fn [apfn-args] (fn [apfn-args]
(let [{:keys [instant-pattern locale] :as ap-config} (let [{:keys [timestamp-pattern locale] :as ap-config}
(@config :shared-appender-config)] (@config :shared-appender-config)]
(apfn (assoc apfn-args (apfn (assoc apfn-args
:ap-config ap-config ; Shared appender config map :ap-config ap-config ; Shared appender config map
:instant-formatter :timestamp-fn
(make-instant-formatter instant-pattern locale))))) (make-timestamp-fn timestamp-pattern locale)))))
;; Wrap for asynchronicity support ;; Wrap for asynchronicity support
((fn [apfn] ((fn [apfn]