diff --git a/src/taoensso/timbre/tools/logging.clj b/src/taoensso/timbre/tools/logging.clj index ec630f5..c09b7d0 100644 --- a/src/taoensso/timbre/tools/logging.clj +++ b/src/taoensso/timbre/tools/logging.clj @@ -6,31 +6,33 @@ Timbre through tools.logging unless you absolutely must (e.g. you're working with a legacy codebase)." - (:require [clojure.tools.logging] - [taoensso.encore :as enc] + (:require clojure.tools.logging [taoensso.timbre :as timbre])) -(deftype Logger [logger-ns] +(deftype Logger [logger-ns config] clojure.tools.logging.impl/Logger (enabled? [_ level] - ;; No support for explicit config, nor ns filtering: - (timbre/log? level)) + (timbre/log? level (str logger-ns) config)) (write! [_ level throwable message] (timbre/log! level :p [message] ; No support for pre-msg raw args - {:config timbre/*config* ; No support for explicit config - :?ns-str nil ; Not provided by tools.logging API + {:config config + :?ns-str (str logger-ns) :?file nil ; '' :?line nil ; '' :?err throwable}))) -(deftype LoggerFactory [] +(deftype LoggerFactory [cache] clojure.tools.logging.impl/LoggerFactory (name [_] "Timbre") - (get-logger [_ logger-ns] (Logger. logger-ns))) + (get-logger [_ logger-ns] + (or (get @cache logger-ns) + (let [logger (Logger. logger-ns timbre/*config*)] + (swap! cache assoc logger-ns logger) + logger)))) (defn use-timbre [] (alter-var-root (var clojure.tools.logging/*logger-factory*) - (constantly (LoggerFactory.)))) + (constantly (LoggerFactory. (atom {})))))