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)
```
And the default instant formatting for log messages:
And the default timestamp formatting for log messages:
```clojure
(timbre/set-config! [:shared-appender-config :instant-pattern]
(timbre/set-config! [:shared-appender-config :timestamp-pattern]
"yyyy-MMM-dd HH:mm:ss ZZ")
(timbre/set-config! [:shared-appender-config :locale]
(java.util.Locale/GERMAN))
@ -114,7 +114,7 @@ Writing a custom appender is easy:
:enabled? true
:async? false
: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}]
(when-not (:production-mode? ap-config)
(apply println instant "Hello world!" message more)))

View File

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