postal appender: use first 150 chars as subject

This commit is contained in:
Peter Taoussanis 2013-11-29 22:58:10 +07:00
parent 5ac604d66d
commit 706f16b11c
1 changed files with 12 additions and 8 deletions

View File

@ -5,6 +5,12 @@
[postal.core :as postal]
[taoensso.timbre :as timbre]))
(defn- str-trunc [^String s max-len]
(if (<= (.length s) max-len) s
(.substring s 0 max-len)))
(comment (str-trunc "Hello this is a long string" 5))
(def postal-appender
{:doc (str "Sends an email using com.draines/postal.\n"
"Needs :postal config map in :shared-appender-config, e.g.:
@ -12,12 +18,10 @@
{:from \"Bob's logger <me@draines.com>\" :to \"foo@example.com\"}")
:min-level :error :enabled? true :async? true
:rate-limit [5 (* 1000 60 2)] ; 5 calls / 2 mins
:fn (fn [{:keys [ap-config prefix throwable args]}]
:fn (fn [{:keys [ap-config default-output]}]
(when-let [postal-config (:postal ap-config)]
(let [[subject & body] args]
(postal/send-message
(assoc postal-config
;; TODO Better to just use trunc'd message as subject?
:subject (str prefix " - " (or subject throwable))
:body (str (str/join \space body)
(timbre/stacktrace throwable "\n")))))))})
(postal/send-message
(assoc postal-config
:subject (-> default-output (str/trim) (str-trunc 150)
(str/replace #"\s+" " "))
:body default-output))))})