Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ns-log-level to set a log level on a specific namespace/pattern #255

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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