[#177] Improvements to clojure.tools.logging integration (@MerelyAPseudonym)

This commit is contained in:
Josh Tilles 2016-04-29 21:55:15 -04:00 committed by Peter Taoussanis
parent f399d250cb
commit f9563cc10d
1 changed files with 12 additions and 10 deletions

View File

@ -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 {})))))