Skip to content

Commit

Permalink
[#255] :ns-log-level feature to set a log level on a specific names…
Browse files Browse the repository at this point in the history
…pace/pattern (@mikekap)
  • Loading branch information
mikekap authored and ptaoussanis committed Apr 15, 2018
1 parent 645dff3 commit 7e87b10
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/taoensso/timbre.cljx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
;; logging in noisy libraries, etc.:
:ns-whitelist [] #_["my-app.foo-ns"]
:ns-blacklist [] #_["taoensso.*"]
:ns-log-level [] #_[["taoensso.*" :info]]

:middleware [] ; (fns [data]) -> ?data, applied left->right

Expand Down Expand Up @@ -237,6 +238,14 @@
(not (string? ns-str-form)) ; Not a compile-time ns-str const
(compile-time-ns-filter ns-str-form)))))

(def ns-log-level
(enc/memoize_
(fn [min-level ns-log-level ?ns-str]
(or (some (fn [[pattern level]]
(when (ns-filter [pattern] [] ?ns-str)
level)) ns-log-level)
min-level))))

(defn #+clj may-log? #+cljs ^boolean may-log?
"Runtime check: would Timbre currently log at the given logging level?
* `?ns-str` arg required to support ns filtering
Expand All @@ -245,7 +254,10 @@
([level ?ns-str ] (may-log? level ?ns-str nil))
([level ?ns-str ?config]
(let [config (or ?config *config*)
min-level (get config :level :report)]
min-level (ns-log-level
(get config :level :report)
(get config :ns-log-level)
?ns-str)]
(and
(level>= level min-level)
(boolean ; Resolves #206 (issue with slf4j-timbre)
Expand Down

0 comments on commit 7e87b10

Please sign in to comment.