mirror of
https://github.com/status-im/timbre.git
synced 2025-01-16 23:11:21 +00:00
Merge branch 'dev'
This commit is contained in:
commit
e4104ef61d
@ -1,7 +1,7 @@
|
|||||||
Current [semantic](http://semver.org/) version:
|
Current [semantic](http://semver.org/) version:
|
||||||
|
|
||||||
```clojure
|
```clojure
|
||||||
[com.taoensso/timbre "1.2.0"]
|
[com.taoensso/timbre "1.3.0"]
|
||||||
```
|
```
|
||||||
|
|
||||||
# Timbre, a (sane) Clojure logging & profiling library
|
# 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`:
|
Depend on Timbre in your `project.clj`:
|
||||||
|
|
||||||
```clojure
|
```clojure
|
||||||
[com.taoensso/timbre "1.2.0"]
|
[com.taoensso/timbre "1.3.0"]
|
||||||
```
|
```
|
||||||
|
|
||||||
and `use` the library:
|
and `use` the library:
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
(defproject com.taoensso/timbre "1.2.0"
|
(defproject com.taoensso/timbre "1.3.0"
|
||||||
:description "Clojure logging & profiling library"
|
:description "Clojure logging & profiling library"
|
||||||
:url "https://github.com/ptaoussanis/timbre"
|
:url "https://github.com/ptaoussanis/timbre"
|
||||||
:license {:name "Eclipse Public License"}
|
:license {:name "Eclipse Public License"}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
(:import [java.util Date Locale]
|
(:import [java.util Date Locale]
|
||||||
[java.text SimpleDateFormat]))
|
[java.text SimpleDateFormat]))
|
||||||
|
|
||||||
;;;; Public str utils
|
;;;; Public utils
|
||||||
|
|
||||||
(defn str-println
|
(defn str-println
|
||||||
"Like `println` but prints all objects to output stream as a single
|
"Like `println` but prints all objects to output stream as a single
|
||||||
@ -27,6 +27,17 @@
|
|||||||
(def green (partial color-str :green))
|
(def green (partial color-str :green))
|
||||||
(def yellow (partial color-str :yellow))
|
(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
|
;;;; Default configuration and appenders
|
||||||
|
|
||||||
(utils/defonce* config
|
(utils/defonce* config
|
||||||
@ -316,6 +327,15 @@
|
|||||||
|
|
||||||
(def-loggers) ; Actually define a logger for each logging level
|
(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
|
;;;; Dev/tests
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
(defn plog-stats
|
(defn plog-stats
|
||||||
"{::pname [time1 time2 ...] ...} => {::pname {:min <min-time> ...} ...}"
|
"{::pname [time1 time2 ...] ...} => {::pname {:min <min-time> ...} ...}"
|
||||||
[plog]
|
[plog]
|
||||||
(reduce (fn [m [pname times]]
|
(reduce (fn [m [pname times]] ; TODO reduce-kv for Clojure 1.4+
|
||||||
(let [count (count times)
|
(let [count (count times)
|
||||||
time (reduce + times)
|
time (reduce + times)
|
||||||
mean (long (/ time count))
|
mean (long (/ time count))
|
||||||
@ -68,7 +68,7 @@
|
|||||||
ft (fn [nanosecs]
|
ft (fn [nanosecs]
|
||||||
(let [pow #(Math/pow 10 %)
|
(let [pow #(Math/pow 10 %)
|
||||||
ok-pow? #(>= nanosecs (pow %))
|
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")
|
(cond (ok-pow? 9) (str (to-pow 9 1) "s")
|
||||||
(ok-pow? 6) (str (to-pow 6 0) "ms")
|
(ok-pow? 6) (str (to-pow 6 0) "ms")
|
||||||
(ok-pow? 3) (str (to-pow 3 0) "μs")
|
(ok-pow? 3) (str (to-pow 3 0) "μs")
|
||||||
|
@ -47,11 +47,11 @@
|
|||||||
|
|
||||||
(defn round-to
|
(defn round-to
|
||||||
"Rounds argument to given number of decimal places."
|
"Rounds argument to given number of decimal places."
|
||||||
[x places]
|
[places x]
|
||||||
(if (zero? places)
|
(if (zero? places)
|
||||||
(Math/round (double x))
|
(Math/round (double x))
|
||||||
(let [modifier (Math/pow 10.0 places)]
|
(let [modifier (Math/pow 10.0 places)]
|
||||||
(/ (Math/round (* x modifier)) modifier))))
|
(/ (Math/round (* x modifier)) modifier))))
|
||||||
|
|
||||||
(comment (round-to 10 0)
|
(comment (round-to 0 10)
|
||||||
(round-to 10.123 2))
|
(round-to 2 10.123))
|
Loading…
x
Reference in New Issue
Block a user