mirror of
https://github.com/status-im/timbre.git
synced 2025-02-27 10:30:38 +00:00
Add with-default-outs
, with-err-as-out
, log-errors
, log-and-rethrow-errors
This commit is contained in:
parent
b1d60d1bee
commit
75778694ff
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user