mirror of
https://github.com/status-im/timbre.git
synced 2025-02-18 06:36:23 +00:00
Fix namespace filtering (mlb-)
This commit is contained in:
parent
ea0f43f03c
commit
b766013031
@ -371,13 +371,14 @@
|
|||||||
|
|
||||||
;;;; Logging macros
|
;;;; Logging macros
|
||||||
|
|
||||||
(defn ns-unfiltered? [config & [ns]] ((:ns-filter (compile-config config))
|
(defn ns-unfiltered? [config ns] ((:ns-filter (compile-config config)) ns))
|
||||||
(or ns *ns*)))
|
|
||||||
|
|
||||||
(defn logging-enabled? "For 3rd-party utils, etc."
|
(defn logging-enabled? "For 3rd-party utils, etc."
|
||||||
[level] (let [config' @config]
|
[level & [compile-time-ns]]
|
||||||
(and (level-sufficient? level config')
|
(let [config' @config]
|
||||||
(ns-unfiltered? config'))))
|
(and (level-sufficient? level config')
|
||||||
|
(or (nil? compile-time-ns)
|
||||||
|
(ns-unfiltered? config' compile-time-ns)))))
|
||||||
|
|
||||||
(defn send-to-appenders! "Implementation detail."
|
(defn send-to-appenders! "Implementation detail."
|
||||||
[;; Args provided by both Timbre, tools.logging:
|
[;; Args provided by both Timbre, tools.logging:
|
||||||
@ -417,10 +418,11 @@
|
|||||||
s1# ~s1
|
s1# ~s1
|
||||||
default-config?# (levels-scored s1#)
|
default-config?# (levels-scored s1#)
|
||||||
config# (if default-config?# @config s1#)
|
config# (if default-config?# @config s1#)
|
||||||
level# (if default-config?# s1# ~s2)]
|
level# (if default-config?# s1# ~s2)
|
||||||
|
compile-time-ns# ~(str *ns*)]
|
||||||
;; (println "DEBUG: Runtime level check")
|
;; (println "DEBUG: Runtime level check")
|
||||||
(when (and (level-sufficient? level# config#)
|
(when (and (level-sufficient? level# config#)
|
||||||
(ns-unfiltered? config#))
|
(ns-unfiltered? config# compile-time-ns#))
|
||||||
(when-let [juxt-fn# (get-in (compile-config config#)
|
(when-let [juxt-fn# (get-in (compile-config config#)
|
||||||
[:appenders-juxt level#])]
|
[:appenders-juxt level#])]
|
||||||
(let [[x1# & xn# :as xs#] (if default-config?#
|
(let [[x1# & xn# :as xs#] (if default-config?#
|
||||||
@ -432,7 +434,7 @@
|
|||||||
level#
|
level#
|
||||||
~base-appender-args
|
~base-appender-args
|
||||||
log-vargs#
|
log-vargs#
|
||||||
~(str *ns*)
|
compile-time-ns#
|
||||||
(when has-throwable?# x1#)
|
(when has-throwable?# x1#)
|
||||||
nil ; Timbre generates msg only after middleware
|
nil ; Timbre generates msg only after middleware
|
||||||
juxt-fn#
|
juxt-fn#
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
(declare pdata-stats format-pdata)
|
(declare pdata-stats format-pdata)
|
||||||
|
|
||||||
(defmacro with-pdata [level & body]
|
(defmacro with-pdata [level & body]
|
||||||
`(if-not (timbre/logging-enabled? ~level)
|
`(if-not (timbre/logging-enabled? ~level ~(str *ns*))
|
||||||
{:result (do ~@body)}
|
{:result (do ~@body)}
|
||||||
(binding [*pdata* (atom {})]
|
(binding [*pdata* (atom {})]
|
||||||
{:result (p ::clock-time ~@body)
|
{:result (p ::clock-time ~@body)
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
(ns taoensso.timbre.tools.logging
|
(ns taoensso.timbre.tools.logging
|
||||||
"clojure.tools.logging.impl/Logger implementation"
|
"clojure.tools.logging.impl/Logger implementation.
|
||||||
|
|
||||||
|
Limitations:
|
||||||
|
* No support for zero-overhead compile-time logging levels (`enabled?`
|
||||||
|
called as a fn).
|
||||||
|
* No support for ns filtering (`write!` called as a fn and w/o compile-time
|
||||||
|
ns info).
|
||||||
|
* Limited raw `:args` support (`write!` called w/o raw args)."
|
||||||
(:require [clojure.tools.logging]
|
(:require [clojure.tools.logging]
|
||||||
[taoensso.timbre :as timbre]))
|
[taoensso.timbre :as timbre]))
|
||||||
|
|
||||||
@ -8,10 +15,8 @@
|
|||||||
(enabled? [_ level] (timbre/logging-enabled? level))
|
(enabled? [_ level] (timbre/logging-enabled? level))
|
||||||
(write! [_ level throwable message]
|
(write! [_ level throwable message]
|
||||||
;; tools.logging message may be a string (for `logp`/`logf` calls) or raw
|
;; tools.logging message may be a string (for `logp`/`logf` calls) or raw
|
||||||
;; argument (for `log` calls). Note that without an :args equivalent for
|
;; argument (for `log` calls). The best we can do for :args is therefore
|
||||||
;; `write!`, the best we can do is `[message]`. This inconsistency means
|
;; `[message]`:
|
||||||
;; that :args consumers will necessarily behave differently under
|
|
||||||
;; tools.logging.
|
|
||||||
(timbre/send-to-appenders! level {} [message] logger-ns throwable
|
(timbre/send-to-appenders! level {} [message] logger-ns throwable
|
||||||
(when (string? message) message))))
|
(when (string? message) message))))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user