From b1d60d1beed0233735996ac4c266914e7461cc3f Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Thu, 24 Jan 2013 21:58:28 +0700 Subject: [PATCH 1/3] Swap `utils/round-to` arg order --- src/taoensso/timbre/profiling.clj | 4 ++-- src/taoensso/timbre/utils.clj | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/taoensso/timbre/profiling.clj b/src/taoensso/timbre/profiling.clj index af1d838..82ad42f 100644 --- a/src/taoensso/timbre/profiling.clj +++ b/src/taoensso/timbre/profiling.clj @@ -29,7 +29,7 @@ (defn plog-stats "{::pname [time1 time2 ...] ...} => {::pname {:min ...} ...}" [plog] - (reduce (fn [m [pname times]] + (reduce (fn [m [pname times]] ; TODO reduce-kv for Clojure 1.4+ (let [count (count times) time (reduce + times) mean (long (/ time count)) @@ -68,7 +68,7 @@ ft (fn [nanosecs] (let [pow #(Math/pow 10 %) ok-pow? #(>= nanosecs (pow %)) - to-pow #(utils/round-to (/ nanosecs (pow %1)) %2)] + to-pow #(utils/round-to %2 (/ nanosecs (pow %1)))] (cond (ok-pow? 9) (str (to-pow 9 1) "s") (ok-pow? 6) (str (to-pow 6 0) "ms") (ok-pow? 3) (str (to-pow 3 0) "μs") diff --git a/src/taoensso/timbre/utils.clj b/src/taoensso/timbre/utils.clj index 8268721..b2632b2 100644 --- a/src/taoensso/timbre/utils.clj +++ b/src/taoensso/timbre/utils.clj @@ -47,11 +47,11 @@ (defn round-to "Rounds argument to given number of decimal places." - [x places] + [places x] (if (zero? places) (Math/round (double x)) (let [modifier (Math/pow 10.0 places)] (/ (Math/round (* x modifier)) modifier)))) -(comment (round-to 10 0) - (round-to 10.123 2)) \ No newline at end of file +(comment (round-to 0 10) + (round-to 2 10.123)) \ No newline at end of file From 75778694ffeae7ba85a49c365b3c0ce1c91fcc8d Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Tue, 29 Jan 2013 16:49:17 +0700 Subject: [PATCH 2/3] Add `with-default-outs`, `with-err-as-out`, `log-errors`, `log-and-rethrow-errors` --- src/taoensso/timbre.clj | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/taoensso/timbre.clj b/src/taoensso/timbre.clj index d1865fa..af6295f 100644 --- a/src/taoensso/timbre.clj +++ b/src/taoensso/timbre.clj @@ -7,7 +7,7 @@ (:import [java.util Date Locale] [java.text SimpleDateFormat])) -;;;; Public str utils +;;;; Public utils (defn str-println "Like `println` but prints all objects to output stream as a single @@ -27,6 +27,17 @@ (def green (partial color-str :green)) (def yellow (partial color-str :yellow)) +(def default-out (java.io.OutputStreamWriter. System/out)) +(def default-err (java.io.PrintWriter. System/err)) + +(defmacro with-default-outs + "Executes body with Clojure's default *out* and *err* bindings." + [& body] `(binding [*out* default-out *err* default-err] ~@body)) + +(defmacro with-err-as-out + "Executes body with *err* bound to *out*." + [& body] `(binding [*err* *out*] ~@body)) + ;;;; Default configuration and appenders (utils/defonce* config @@ -316,6 +327,15 @@ (def-loggers) ; Actually define a logger for each logging level +(defmacro log-errors + [& body] `(try ~@body (catch Exception e# (error e#)))) + +(defmacro log-and-rethrow-errors + [& body] `(try ~@body (catch Exception e# (error e#) (throw e#)))) + +(comment (log-errors (/ 0)) + (log-and-rethrow-errors (/ 0))) + ;;;; Dev/tests (comment From c6340d9b13c87964c2a003bfe4c9722329e5b1de Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Tue, 29 Jan 2013 16:51:34 +0700 Subject: [PATCH 3/3] Bump version (1.3.0) --- README.md | 4 ++-- project.clj | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 63d3320..618c4f0 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Current [semantic](http://semver.org/) version: ```clojure -[com.taoensso/timbre "1.2.0"] +[com.taoensso/timbre "1.3.0"] ``` # Timbre, a (sane) Clojure logging & profiling library @@ -27,7 +27,7 @@ Timbre is an attempt to make **simple logging simple** and more **complex loggin Depend on Timbre in your `project.clj`: ```clojure -[com.taoensso/timbre "1.2.0"] +[com.taoensso/timbre "1.3.0"] ``` and `use` the library: diff --git a/project.clj b/project.clj index 6afacfe..f6730ce 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject com.taoensso/timbre "1.2.0" +(defproject com.taoensso/timbre "1.3.0" :description "Clojure logging & profiling library" :url "https://github.com/ptaoussanis/timbre" :license {:name "Eclipse Public License"}