From ad2dad11560f3e5075e911fd3770f622e5edc195 Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Tue, 2 Oct 2012 17:44:31 +0700 Subject: [PATCH 1/5] Housekeeping --- README.md | 3 +-- src/taoensso/timbre.clj | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5b46390..6f220d8 100644 --- a/README.md +++ b/README.md @@ -51,8 +51,7 @@ Depend on Timbre in your `project.clj`: and `use` the library: ```clojure -(ns my-app - (:use [taoensso.timbre :as timbre :only (trace debug info warn error fatal spy)])) +(ns my-app (:use [taoensso.timbre :as timbre :only (trace debug info warn error fatal spy)])) ``` ### Start Logging diff --git a/src/taoensso/timbre.clj b/src/taoensso/timbre.clj index bba959c..f3a1791 100644 --- a/src/taoensso/timbre.clj +++ b/src/taoensso/timbre.clj @@ -186,7 +186,7 @@ (apply juxt)))))))) (reset! appenders-juxt-cache))) -;;; Namespace filter +;;; Namespace filter ; TODO Generalize to arbitrary fn filters? (def ns-filter-cache "@ns-filter-cache => (fn relevant-ns? [ns] ...)" (atom (constantly true))) From 5750fc7c8b4f150c6693ada8cf18f1fa51204a2f Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Fri, 19 Oct 2012 15:04:42 +0700 Subject: [PATCH 2/5] Fix `ap-config` bug --- src/taoensso/timbre.clj | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/taoensso/timbre.clj b/src/taoensso/timbre.clj index f3a1791..581391d 100644 --- a/src/taoensso/timbre.clj +++ b/src/taoensso/timbre.clj @@ -104,9 +104,10 @@ [{apfn :fn :keys [async? max-message-per-msecs] :as appender}] (-> ;; Wrap to add compile-time stuff to runtime appender arguments - (let [{:keys [timestamp-pattern timestamp-locale prefix-fn] :as ap-config} - @config - timestamp-fn (make-timestamp-fn timestamp-pattern timestamp-locale)] + (let [{ap-config :shared-appender-config + :keys [timestamp-pattern timestamp-locale prefix-fn]} @config + + timestamp-fn (make-timestamp-fn timestamp-pattern timestamp-locale)] (fn [{:keys [instant] :as apfn-args}] (let [apfn-args (merge apfn-args {:ap-config ap-config From dc995c10add8e66a8d9136ba5d2af17feb5b0478 Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Fri, 19 Oct 2012 15:05:24 +0700 Subject: [PATCH 3/5] Add `utils/deep-merge` --- src/taoensso/timbre.clj | 3 ++- src/taoensso/timbre/utils.clj | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/taoensso/timbre.clj b/src/taoensso/timbre.clj index 581391d..72a3bfe 100644 --- a/src/taoensso/timbre.clj +++ b/src/taoensso/timbre.clj @@ -32,7 +32,8 @@ Other keys include: :instant, :timestamp, :hostname, :ns, :error? - See source code for examples."} + See source code for examples and `utils/deep-merge` for a convenient way + to reconfigure appenders."} (atom {:current-level :debug ;;; Control log filtering by namespace patterns (e.g. ["my-app.*"]). diff --git a/src/taoensso/timbre/utils.clj b/src/taoensso/timbre/utils.clj index 38f1a5c..abef478 100644 --- a/src/taoensso/timbre/utils.clj +++ b/src/taoensso/timbre/utils.clj @@ -14,4 +14,24 @@ @d-result (let [d-result (delay (apply f args))] (swap! cache assoc args {:time-cached now :d-result d-result}) - @d-result)))))) \ No newline at end of file + @d-result)))))) + +(defn deep-merge-with ; From clojure.contrib.map-utils + "Like `merge-with` but merges maps recursively, applying the given fn + only when there's a non-map at a particular level. + + (deepmerge-with + {:a {:b {:c 1 :d {:x 1 :y 2}} :e 3} :f 4} + {:a {:b {:c 2 :d {:z 9} :z 3} :e 100}}) + => {:a {:b {:z 3, :c 3, :d {:z 9, :x 1, :y 2}}, :e 103}, :f 4}" + [f & maps] + (apply + (fn m [& maps] + (if (every? map? maps) + (apply merge-with m maps) + (apply f maps))) + maps)) + +(defn deep-merge + "Partial of `deep-merge-with`." + [& maps] + (apply deep-merge-with (fn [x y] y) maps)) \ No newline at end of file From 92e31c7b7cceb92c98904b8439a6f371c457ad50 Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Fri, 19 Oct 2012 15:24:46 +0700 Subject: [PATCH 4/5] Add simple file spit appender --- README.md | 1 + src/taoensso/timbre.clj | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6f220d8..586f028 100644 --- a/README.md +++ b/README.md @@ -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 {}} diff --git a/src/taoensso/timbre.clj b/src/taoensso/timbre.clj index 72a3bfe..99a5c9d 100644 --- a/src/taoensso/timbre.clj +++ b/src/taoensso/timbre.clj @@ -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)) From 734d5983637747b42e48d606d9ad612d7012cc1b Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Fri, 19 Oct 2012 15:06:00 +0700 Subject: [PATCH 5/5] Bump version (minor) --- README.md | 4 ++-- project.clj | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 586f028..3942e1e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Current [semantic](http://semver.org/) version: ```clojure -[com.taoensso/timbre "0.8.1"] +[com.taoensso/timbre "0.8.2"] ``` **Breaking changes** since _0.7.x_: @@ -45,7 +45,7 @@ lein2 all test Depend on Timbre in your `project.clj`: ```clojure -[com.taoensso/timbre "0.8.1"] +[com.taoensso/timbre "0.8.2"] ``` and `use` the library: diff --git a/project.clj b/project.clj index 90d47aa..de487ee 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject com.taoensso/timbre "0.8.1" +(defproject com.taoensso/timbre "0.8.2" :description "Simple, flexible, all-Clojure logging. No XML!" :url "https://github.com/ptaoussanis/timbre" :license {:name "Eclipse Public License"}