mirror of https://github.com/status-im/timbre.git
Add `with-log-level` for thread-local logging levels
This commit is contained in:
parent
f5a507765c
commit
ce9ea0ac76
|
@ -1,3 +1,7 @@
|
|||
## v2.2.0 → v2.3.0
|
||||
* Added `with-log-level` for thread-local logging levels: `(with-level :trace (trace "This will log!"))`. Esp. useful for developing & unit tests, etc.
|
||||
|
||||
|
||||
## v2.1.2 → v2.2.0
|
||||
* Add socket, MongoDB appenders (thanks to emlyn).
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
**[API docs](http://ptaoussanis.github.io/timbre/)** | **[CHANGELOG](https://github.com/ptaoussanis/timbre/blob/master/CHANGELOG.md)** | [contact & contributing](#contact--contributing) | [other Clojure libs](https://www.taoensso.com/clojure-libraries) | [Twitter](https://twitter.com/#!/ptaoussanis) | current [semantic](http://semver.org/) version:
|
||||
|
||||
```clojure
|
||||
[com.taoensso/timbre "2.2.0"] ; See CHANGELOG for breaking changes since 1.x
|
||||
[com.taoensso/timbre "2.3.0"] ; See CHANGELOG for breaking changes since 1.x
|
||||
```
|
||||
|
||||
# Timbre, a (sane) Clojure logging & profiling library
|
||||
|
@ -26,9 +26,9 @@ 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:
|
||||
|
||||
```clojure
|
||||
[com.taoensso/timbre "2.2.0"] ; project.clj
|
||||
[com.taoensso/timbre "2.3.0"] ; project.clj
|
||||
(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 with-log-level)])) ; ns
|
||||
```
|
||||
|
||||
### Logging
|
||||
|
@ -171,6 +171,7 @@ netcat localhost 9000
|
|||
(timbre/set-config! [:shared-appender-config :socket]
|
||||
{:listen-addr :all
|
||||
:port 9000})
|
||||
```
|
||||
|
||||
#### MongoDB ([congomongo](https://github.com/aboekhoff/congomongo)) appender
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
(defproject com.taoensso/timbre "2.2.0"
|
||||
(defproject com.taoensso/timbre "2.3.0"
|
||||
:description "Clojure logging & profiling library"
|
||||
:url "https://github.com/ptaoussanis/timbre"
|
||||
:license {:name "Eclipse Public License"
|
||||
|
|
|
@ -45,6 +45,11 @@
|
|||
|
||||
;;;; Default configuration and appenders
|
||||
|
||||
(def ^:dynamic *current-level* nil)
|
||||
(defmacro with-log-level
|
||||
"Allows thread-local config logging level override. Useful for dev & testing."
|
||||
[level & body] `(binding [*current-level* ~level] ~@body))
|
||||
|
||||
(utils/defonce* config
|
||||
"This map atom controls everything about the way Timbre operates.
|
||||
|
||||
|
@ -68,7 +73,7 @@
|
|||
|
||||
See source code for examples. See `set-config!`, `merge-config!`, `set-level!`
|
||||
for convenient config editing."
|
||||
(atom {:current-level :debug
|
||||
(atom {:current-level :debug ; See also `with-log-level`
|
||||
|
||||
;;; Control log filtering by namespace patterns (e.g. ["my-app.*"]).
|
||||
;;; Useful for turning off logging in noisy libraries, etc.
|
||||
|
@ -132,7 +137,7 @@
|
|||
(memoize (fn [x y] (- (checked-level-score x) (checked-level-score y)))))
|
||||
|
||||
(defn sufficient-level?
|
||||
[level] (>= (compare-levels level (:current-level @config)) 0))
|
||||
[level] (>= (compare-levels level (or *current-level* (:current-level @config))) 0))
|
||||
|
||||
;;;; Appender-fn decoration
|
||||
|
||||
|
@ -435,6 +440,9 @@
|
|||
(info (Exception. "noes!") "bar")
|
||||
(spy (/ 4 0))
|
||||
|
||||
(with-log-level :trace (trace "foo"))
|
||||
(with-log-level :debug (trace "foo"))
|
||||
|
||||
;; Middleware
|
||||
(info {:name "Robert Paulson" :password "Super secret"})
|
||||
(set-config!
|
||||
|
|
Loading…
Reference in New Issue