mirror of https://github.com/status-im/timbre.git
[#177] Improvements to clojure.tools.logging integration (@MerelyAPseudonym)
This commit is contained in:
parent
f399d250cb
commit
f9563cc10d
|
@ -6,31 +6,33 @@
|
||||||
Timbre through tools.logging unless you absolutely must (e.g. you're
|
Timbre through tools.logging unless you absolutely must (e.g. you're
|
||||||
working with a legacy codebase)."
|
working with a legacy codebase)."
|
||||||
|
|
||||||
(:require [clojure.tools.logging]
|
(:require clojure.tools.logging
|
||||||
[taoensso.encore :as enc]
|
|
||||||
[taoensso.timbre :as timbre]))
|
[taoensso.timbre :as timbre]))
|
||||||
|
|
||||||
(deftype Logger [logger-ns]
|
(deftype Logger [logger-ns config]
|
||||||
clojure.tools.logging.impl/Logger
|
clojure.tools.logging.impl/Logger
|
||||||
|
|
||||||
(enabled? [_ level]
|
(enabled? [_ level]
|
||||||
;; No support for explicit config, nor ns filtering:
|
(timbre/log? level (str logger-ns) config))
|
||||||
(timbre/log? level))
|
|
||||||
|
|
||||||
(write! [_ level throwable message]
|
(write! [_ level throwable message]
|
||||||
(timbre/log! level :p
|
(timbre/log! level :p
|
||||||
[message] ; No support for pre-msg raw args
|
[message] ; No support for pre-msg raw args
|
||||||
{:config timbre/*config* ; No support for explicit config
|
{:config config
|
||||||
:?ns-str nil ; Not provided by tools.logging API
|
:?ns-str (str logger-ns)
|
||||||
:?file nil ; ''
|
:?file nil ; ''
|
||||||
:?line nil ; ''
|
:?line nil ; ''
|
||||||
:?err throwable})))
|
:?err throwable})))
|
||||||
|
|
||||||
(deftype LoggerFactory []
|
(deftype LoggerFactory [cache]
|
||||||
clojure.tools.logging.impl/LoggerFactory
|
clojure.tools.logging.impl/LoggerFactory
|
||||||
(name [_] "Timbre")
|
(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 []
|
(defn use-timbre []
|
||||||
(alter-var-root (var clojure.tools.logging/*logger-factory*)
|
(alter-var-root (var clojure.tools.logging/*logger-factory*)
|
||||||
(constantly (LoggerFactory.))))
|
(constantly (LoggerFactory. (atom {})))))
|
||||||
|
|
Loading…
Reference in New Issue