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