mirror of https://github.com/status-im/timbre.git
Merge branch 'dev'
This commit is contained in:
commit
dafa9293d5
|
@ -1,7 +1,7 @@
|
||||||
Current [semantic](http://semver.org/) version:
|
Current [semantic](http://semver.org/) version:
|
||||||
|
|
||||||
```clojure
|
```clojure
|
||||||
[com.taoensso/timbre "0.8.2"]
|
[com.taoensso/timbre "0.8.3"]
|
||||||
```
|
```
|
||||||
|
|
||||||
**Breaking changes** since _0.7.x_:
|
**Breaking changes** since _0.7.x_:
|
||||||
|
@ -35,7 +35,7 @@ Timbre is an attempt to make **simple logging simple** and more **complex loggin
|
||||||
Timbre is still currently *experimental*. It **has not yet been thoroughly tested in production** and its API is subject to change. To run tests against all supported Clojure versions, use:
|
Timbre is still currently *experimental*. It **has not yet been thoroughly tested in production** and its API is subject to change. To run tests against all supported Clojure versions, use:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
lein2 all test
|
lein all test
|
||||||
```
|
```
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
@ -45,7 +45,7 @@ lein2 all test
|
||||||
Depend on Timbre in your `project.clj`:
|
Depend on Timbre in your `project.clj`:
|
||||||
|
|
||||||
```clojure
|
```clojure
|
||||||
[com.taoensso/timbre "0.8.2"]
|
[com.taoensso/timbre "0.8.3"]
|
||||||
```
|
```
|
||||||
|
|
||||||
and `use` the library:
|
and `use` the library:
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
(defproject com.taoensso/timbre "0.8.2"
|
(defproject com.taoensso/timbre "0.8.3"
|
||||||
:description "Simple, flexible, all-Clojure logging. No XML!"
|
:description "Simple, flexible, all-Clojure logging. No XML!"
|
||||||
:url "https://github.com/ptaoussanis/timbre"
|
:url "https://github.com/ptaoussanis/timbre"
|
||||||
:license {:name "Eclipse Public License"}
|
:license {:name "Eclipse Public License"}
|
||||||
|
|
|
@ -81,15 +81,16 @@
|
||||||
;;;; Define and sort logging levels
|
;;;; Define and sort logging levels
|
||||||
|
|
||||||
(def ^:private ordered-levels [:trace :debug :info :warn :error :fatal :report])
|
(def ^:private ordered-levels [:trace :debug :info :warn :error :fatal :report])
|
||||||
(def ^:private scored-levels (zipmap ordered-levels (range)))
|
(def ^:private scored-levels (assoc (zipmap ordered-levels (range)) nil 0))
|
||||||
(defn assert-valid-level
|
|
||||||
[x] (when-not (some #{x} ordered-levels)
|
|
||||||
(throw (Exception. (str "Invalid logging level: " x)))))
|
|
||||||
|
|
||||||
(defn error-level? [x] (boolean (#{:error :fatal} x)))
|
(defn error-level? [level] (boolean (#{:error :fatal} level)))
|
||||||
|
|
||||||
|
(defn- checked-level-score [level]
|
||||||
|
(or (scored-levels level)
|
||||||
|
(throw (Exception. (str "Invalid logging level: " level)))))
|
||||||
|
|
||||||
(def compare-levels
|
(def compare-levels
|
||||||
(memoize (fn [x y] (- (scored-levels x) (scored-levels y)))))
|
(memoize (fn [x y] (- (checked-level-score x) (checked-level-score y)))))
|
||||||
|
|
||||||
(defn sufficient-level?
|
(defn sufficient-level?
|
||||||
[level] (>= (compare-levels level (:current-level @config)) 0))
|
[level] (>= (compare-levels level (:current-level @config)) 0))
|
||||||
|
@ -179,8 +180,7 @@
|
||||||
[level]
|
[level]
|
||||||
(->> (:appenders @config)
|
(->> (:appenders @config)
|
||||||
(filter #(let [{:keys [enabled? min-level]} (val %)]
|
(filter #(let [{:keys [enabled? min-level]} (val %)]
|
||||||
(and enabled? (or (nil? min-level)
|
(and enabled? (>= (compare-levels level min-level) 0))))
|
||||||
(>= (compare-levels level min-level) 0)))))
|
|
||||||
(into {})))
|
(into {})))
|
||||||
|
|
||||||
(comment (relevant-appenders :debug)
|
(comment (relevant-appenders :debug)
|
||||||
|
@ -241,14 +241,12 @@
|
||||||
"Returns true when current logging level is sufficient and current namespace
|
"Returns true when current logging level is sufficient and current namespace
|
||||||
is unfiltered."
|
is unfiltered."
|
||||||
[level]
|
[level]
|
||||||
(assert-valid-level level)
|
|
||||||
`(and (sufficient-level? ~level) (@ns-filter-cache ~*ns*)))
|
`(and (sufficient-level? ~level) (@ns-filter-cache ~*ns*)))
|
||||||
|
|
||||||
(defmacro log*
|
(defmacro log*
|
||||||
"Prepares given arguments for, and then dispatches to all relevant
|
"Prepares given arguments for, and then dispatches to all relevant
|
||||||
appender-fns."
|
appender-fns."
|
||||||
[level base-args & sigs]
|
[level base-args & sigs]
|
||||||
(assert-valid-level level)
|
|
||||||
`(when-let [juxt-fn# (@appenders-juxt-cache ~level)] ; Any relevant appenders?
|
`(when-let [juxt-fn# (@appenders-juxt-cache ~level)] ; Any relevant appenders?
|
||||||
(let [[x1# & xs#] (list ~@sigs)
|
(let [[x1# & xs#] (list ~@sigs)
|
||||||
|
|
||||||
|
@ -274,7 +272,6 @@
|
||||||
appender-fns. Generic form of standard level-loggers (trace, info, etc.)."
|
appender-fns. Generic form of standard level-loggers (trace, info, etc.)."
|
||||||
{:arglists '([level message & more] [level throwable message & more])}
|
{:arglists '([level message & more] [level throwable message & more])}
|
||||||
[level & sigs]
|
[level & sigs]
|
||||||
(assert-valid-level level)
|
|
||||||
`(when (logging-enabled? ~level)
|
`(when (logging-enabled? ~level)
|
||||||
(log* ~level {} ~@sigs)))
|
(log* ~level {} ~@sigs)))
|
||||||
|
|
||||||
|
@ -313,6 +310,8 @@
|
||||||
(log :debug (Exception.))
|
(log :debug (Exception.))
|
||||||
(log :trace "arg1")
|
(log :trace "arg1")
|
||||||
|
|
||||||
|
(log (or nil :info) "Booya")
|
||||||
|
|
||||||
(set-config! [:ns-blacklist] [])
|
(set-config! [:ns-blacklist] [])
|
||||||
(set-config! [:ns-blacklist] ["taoensso.timbre*"])
|
(set-config! [:ns-blacklist] ["taoensso.timbre*"])
|
||||||
|
|
||||||
|
|
|
@ -110,7 +110,6 @@
|
||||||
for db appenders to check for this special key and to log profiling stats to
|
for db appenders to check for this special key and to log profiling stats to
|
||||||
db in a queryable manner."
|
db in a queryable manner."
|
||||||
[level name & body]
|
[level name & body]
|
||||||
(timbre/assert-valid-level level)
|
|
||||||
`(if (timbre/logging-enabled? ~level)
|
`(if (timbre/logging-enabled? ~level)
|
||||||
(profile*
|
(profile*
|
||||||
(fn [name# stats#]
|
(fn [name# stats#]
|
||||||
|
|
Loading…
Reference in New Issue