From b7660130318c6df42a3f676dc9b1af2fada2ab90 Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Tue, 17 Dec 2013 15:45:09 +0700 Subject: [PATCH] Fix namespace filtering (mlb-) --- src/taoensso/timbre.clj | 18 ++++++++++-------- src/taoensso/timbre/profiling.clj | 2 +- src/taoensso/timbre/tools/logging.clj | 15 ++++++++++----- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/taoensso/timbre.clj b/src/taoensso/timbre.clj index 237039f..0db7b42 100644 --- a/src/taoensso/timbre.clj +++ b/src/taoensso/timbre.clj @@ -371,13 +371,14 @@ ;;;; Logging macros -(defn ns-unfiltered? [config & [ns]] ((:ns-filter (compile-config config)) - (or ns *ns*))) +(defn ns-unfiltered? [config ns] ((:ns-filter (compile-config config)) ns)) (defn logging-enabled? "For 3rd-party utils, etc." - [level] (let [config' @config] - (and (level-sufficient? level config') - (ns-unfiltered? config')))) + [level & [compile-time-ns]] + (let [config' @config] + (and (level-sufficient? level config') + (or (nil? compile-time-ns) + (ns-unfiltered? config' compile-time-ns))))) (defn send-to-appenders! "Implementation detail." [;; Args provided by both Timbre, tools.logging: @@ -417,10 +418,11 @@ s1# ~s1 default-config?# (levels-scored 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") (when (and (level-sufficient? level# config#) - (ns-unfiltered? config#)) + (ns-unfiltered? config# compile-time-ns#)) (when-let [juxt-fn# (get-in (compile-config config#) [:appenders-juxt level#])] (let [[x1# & xn# :as xs#] (if default-config?# @@ -432,7 +434,7 @@ level# ~base-appender-args log-vargs# - ~(str *ns*) + compile-time-ns# (when has-throwable?# x1#) nil ; Timbre generates msg only after middleware juxt-fn# diff --git a/src/taoensso/timbre/profiling.clj b/src/taoensso/timbre/profiling.clj index edf3ae3..0f3969d 100644 --- a/src/taoensso/timbre/profiling.clj +++ b/src/taoensso/timbre/profiling.clj @@ -24,7 +24,7 @@ (declare pdata-stats format-pdata) (defmacro with-pdata [level & body] - `(if-not (timbre/logging-enabled? ~level) + `(if-not (timbre/logging-enabled? ~level ~(str *ns*)) {:result (do ~@body)} (binding [*pdata* (atom {})] {:result (p ::clock-time ~@body) diff --git a/src/taoensso/timbre/tools/logging.clj b/src/taoensso/timbre/tools/logging.clj index 4ee1fff..7ac5c0d 100644 --- a/src/taoensso/timbre/tools/logging.clj +++ b/src/taoensso/timbre/tools/logging.clj @@ -1,5 +1,12 @@ (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] [taoensso.timbre :as timbre])) @@ -8,10 +15,8 @@ (enabled? [_ level] (timbre/logging-enabled? level)) (write! [_ level throwable message] ;; tools.logging message may be a string (for `logp`/`logf` calls) or raw - ;; argument (for `log` calls). Note that without an :args equivalent for - ;; `write!`, the best we can do is `[message]`. This inconsistency means - ;; that :args consumers will necessarily behave differently under - ;; tools.logging. + ;; argument (for `log` calls). The best we can do for :args is therefore + ;; `[message]`: (timbre/send-to-appenders! level {} [message] logger-ns throwable (when (string? message) message))))