diff --git a/README.md b/README.md index 16d7726..97b8fcd 100644 --- a/README.md +++ b/README.md @@ -99,12 +99,11 @@ Configuring Timbre couldn't be simpler. Let's check out (some of) the defaults: :appenders {:standard-out { <...> } - :postal { <...> }} + <...> } :shared-appender-config {:timestamp-pattern "yyyy-MMM-dd HH:mm:ss ZZ" - :locale nil - :postal nil}} + :locale nil}} ``` Easily adjust the current logging level: @@ -127,14 +126,27 @@ Filter logging output by namespaces: (timbre/set-config! [:ns-whitelist] ["some.library.core" "my-app.*"]) ``` -Enable the standard [Postal](https://github.com/drewr/postal)-based email appender: +### Email Appender + +To enable the standard [Postal](https://github.com/drewr/postal)-based email appender, add the Postal dependency to your `project.clj`: ```clojure +[com.draines/postal "1.8.0"] +``` + +And add the appender to your `ns` declaration: + +```clojure +(:require [taoensso.timbre.appenders (postal :as postal-appender)]) +``` + +Then adjust your Timbre config: + +```clojure +(timbre/set-config! [:appenders :postal] postal-appender/postal-appender) (timbre/set-config! [:shared-appender-config :postal] ^{:host "mail.isp.net" :user "jsmith" :pass "sekrat!!1"} {:from "me@draines.com" :to "foo@example.com"}) - -(timbre/set-config! [:appenders :postal :enabled?] true) ``` Rate-limit to one email per message per minute: @@ -180,9 +192,7 @@ And these certaily do the job. But as with many Java tools, they can be a little Let's add it to our app's `ns` declaration: ```clojure -(ns my-app - (:use [taoensso.timbre :as timbre :only (trace debug info warn error fatal spy)] - [taoensso.timbre.profiling :as profiling :only (p profile)])) +(:use [taoensso.timbre.profiling :as profiling :only (p profile)]) ``` Wrap forms that you'd like to profile with the `p` macro and give them a name: diff --git a/project.clj b/project.clj index 9a39900..21909a9 100644 --- a/project.clj +++ b/project.clj @@ -3,8 +3,7 @@ :url "https://github.com/ptaoussanis/timbre" :license {:name "Eclipse Public License"} :dependencies [[org.clojure/clojure "1.3.0"] - [clj-stacktrace "0.2.4"] - [com.draines/postal "1.8.0"]] + [clj-stacktrace "0.2.4"]] :profiles {:1.3 {:dependencies [[org.clojure/clojure "1.3.0"]]} :1.4 {:dependencies [[org.clojure/clojure "1.4.0"]]} :1.5 {:dependencies [[org.clojure/clojure "1.5.0-master-SNAPSHOT"]]}} diff --git a/src/taoensso/timbre.clj b/src/taoensso/timbre.clj index 55807d5..1768064 100644 --- a/src/taoensso/timbre.clj +++ b/src/taoensso/timbre.clj @@ -2,8 +2,7 @@ "Simple, flexible, all-Clojure logging. No XML!" {:author "Peter Taoussanis"} (:require [clojure.string :as str] - [clj-stacktrace.repl :as stacktrace] - [postal.core :as postal]) + [clj-stacktrace.repl :as stacktrace]) (:import [java.util Date Locale] [java.text SimpleDateFormat])) @@ -56,29 +55,13 @@ :max-message-per-msecs nil :fn (fn [{:keys [error? more] :as args}] (binding [*out* (if error? *err* *out*)] - (apply str-println (prefixed-message args) more)))} - - :postal - {:doc (str "Sends an email using com.draines/postal.\n" - "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 more] :as args}] - (when-let [postal-config (:postal ap-config)] - (postal/send-message - (assoc postal-config - :subject (prefixed-message args) - :body (if (seq more) (str/join " " more) - "")))))}} + (apply str-println (prefixed-message args) more)))}} ;; Will be given to all appenders via :ap-config key :shared-appender-config {: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"} - ;; {:from "Bob's logger " :to "foo@example.com"} - :postal nil}})) + }})) (defn set-config! [[k & ks] val] (swap! config assoc-in (cons k ks) val)) (defn set-level! [level] (set-config! [:current-level] level)) diff --git a/src/taoensso/timbre/appenders/postal.clj b/src/taoensso/timbre/appenders/postal.clj new file mode 100644 index 0000000..32f1212 --- /dev/null +++ b/src/taoensso/timbre/appenders/postal.clj @@ -0,0 +1,22 @@ +(ns taoensso.timbre.appenders.postal + "Email appender for com.draines/postal. + Ref: https://github.com/drewr/postal." + {:author "Peter Taoussanis"} + (:require [clojure.string :as str] + [postal.core :as postal] + [taoensso.timbre :as timbre])) + +(def postal-appender + {:doc (str "Sends an email using com.draines/postal.\n" + "Needs :postal config map in :shared-appender-config, e.g.: + ^{:host \"mail.isp.net\" :user \"jsmith\" :pass \"sekrat!!1\"} + {:from \"Bob's logger \" :to \"foo@example.com\"}") + :min-level :error :enabled? true :async? true + :max-message-per-msecs (* 60 60 2) + :fn (fn [{:keys [ap-config more] :as args}] + (when-let [postal-config (:postal ap-config)] + (postal/send-message + (assoc postal-config + :subject (timbre/prefixed-message args) + :body (if (seq more) (str/join " " more) + "")))))}) \ No newline at end of file