Allow no-message throwable logging, use `str` for ex-data printing

This commit is contained in:
Peter Taoussanis 2013-06-07 20:45:33 +07:00
parent 5d4e5f2739
commit 71218f7086
3 changed files with 10 additions and 8 deletions

View File

@ -1,7 +1,7 @@
Current [semantic](http://semver.org/) version: Current [semantic](http://semver.org/) version:
```clojure ```clojure
[com.taoensso/timbre "2.1.1"] ; See commit history for breaking changes since 1.x [com.taoensso/timbre "2.1.2"] ; See commit history for breaking changes since 1.x
``` ```
# Timbre, a (sane) Clojure logging & profiling library # Timbre, a (sane) Clojure logging & profiling library
@ -26,7 +26,7 @@ Logging with Java can be maddeningly, unnecessarily hard. Particularly if all yo
Add the necessary dependency to your [Leiningen](http://leiningen.org/) `project.clj` and `require` the library in your ns: Add the necessary dependency to your [Leiningen](http://leiningen.org/) `project.clj` and `require` the library in your ns:
```clojure ```clojure
[com.taoensso/timbre "2.1.1"] ; project.clj [com.taoensso/timbre "2.1.2"] ; project.clj
(ns my-app (:require [taoensso.timbre :as timbre (ns my-app (:require [taoensso.timbre :as timbre
:refer (trace debug info warn error fatal spy)])) ; ns :refer (trace debug info warn error fatal spy)])) ; ns
``` ```

View File

@ -1,4 +1,4 @@
(defproject com.taoensso/timbre "2.1.1" (defproject com.taoensso/timbre "2.1.2"
: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"

View File

@ -13,7 +13,7 @@
"Like `println` but prints all objects to output stream as a single "Like `println` but prints all objects to output stream as a single
atomic string. This is faster and avoids interleaving race conditions." atomic string. This is faster and avoids interleaving race conditions."
[& xs] [& xs]
(print (str (str/join \space xs) \newline)) (print (str/join \space (filter identity xs)) \newline)
(flush)) (flush))
(defn color-str [color & xs] (defn color-str [color & xs]
@ -40,8 +40,8 @@
(defn stacktrace [throwable & [separator]] (defn stacktrace [throwable & [separator]]
(when throwable (when throwable
(str separator (when-let [d (ex-data throwable)] (str d " ")) (str separator throwable ; (str throwable) incl. ex-data for Clojure 1.4+
(stacktrace/pst-str throwable)))) "\n\n" (stacktrace/pst-str throwable))))
;;;; Default configuration and appenders ;;;; Default configuration and appenders
@ -326,14 +326,16 @@
([base-appender-args level log-args message-fn] ([base-appender-args level log-args message-fn]
`(when-let [juxt-fn# (@appenders-juxt-cache ~level)] `(when-let [juxt-fn# (@appenders-juxt-cache ~level)]
(let [[x1# & xn# :as xs#] (vector ~@log-args) (let [[x1# & xn# :as xs#] (vector ~@log-args)
has-throwable?# (and xn# (instance? Throwable x1#)) has-throwable?# (instance? Throwable x1#)
log-vargs# (vec (if has-throwable?# xn# xs#))] log-vargs# (vec (if has-throwable?# xn# xs#))]
(log* ~base-appender-args (log* ~base-appender-args
~level ~level
log-vargs# log-vargs#
~(str *ns*) ~(str *ns*)
(when has-throwable?# x1#) (when has-throwable?# x1#)
(when-let [mf# ~message-fn] (apply mf# log-vargs#)) (when-let [mf# ~message-fn]
(when-not (empty? log-vargs#)
(apply mf# log-vargs#)))
juxt-fn#))))) juxt-fn#)))))
(defmacro log (defmacro log