Merge branch 'dev'

This commit is contained in:
Peter Taoussanis 2013-01-29 16:56:05 +07:00
commit e4104ef61d
5 changed files with 29 additions and 9 deletions

View File

@ -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:

View File

@ -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"}

View File

@ -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

View File

@ -29,7 +29,7 @@
(defn plog-stats
"{::pname [time1 time2 ...] ...} => {::pname {:min <min-time> ...} ...}"
[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")

View File

@ -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))
(comment (round-to 0 10)
(round-to 2 10.123))