Skip to content

Commit

Permalink
[#177] PR housekeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaoussanis committed Jul 4, 2016
1 parent f9563cc commit 43f4fdf
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions src/taoensso/timbre/tools/logging.clj
Original file line number Diff line number Diff line change
@@ -1,38 +1,48 @@
(ns taoensso.timbre.tools.logging
"clojure.tools.logging.impl/Logger implementation.
"`clojure.tools.logging.impl/Logger` implementation.
Please note that the tools.logging API has some significant limits
that native Timbre does not. Would strongly recommend against using
Timbre through tools.logging unless you absolutely must (e.g. you're
working with a legacy codebase)."

(:require clojure.tools.logging
(:require [clojure.tools.logging]
[taoensso.encore :as enc]
[taoensso.timbre :as timbre]))

(deftype Logger [logger-ns config]
(deftype Logger [logger-ns-str timbre-config]
clojure.tools.logging.impl/Logger

(enabled? [_ level]
(timbre/log? level (str logger-ns) config))
;; No support for per-call config
(timbre/log? level logger-ns-str timbre-config))

(write! [_ level throwable message]
(timbre/log! level :p
[message] ; No support for pre-msg raw args
{:config config
:?ns-str (str logger-ns)
:?file nil ; ''
{:config ; No support for per-call config
(if (var? timbre-config)
@timbre-config ; Support dynamic vars, etc.
timbre-config)
:?ns-str logger-ns-str
:?file nil ; No support
:?line nil ; ''
:?err throwable})))

(deftype LoggerFactory [cache]
(deftype LoggerFactory [get-logger-fn]
clojure.tools.logging.impl/LoggerFactory
(name [_] "Timbre")
(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. (atom {})))))
(get-logger [_ logger-ns] (get-logger-fn logger-ns)))

(defn use-timbre
"Sets the root binding of `clojure.tools.logging/*logger-factory*`
to use Timbre."
([ ] (use-timbre #'timbre/*config*))
([timbre-config]
(use-timbre timbre-config
(enc/memoize_
(fn [logger-ns] (Logger. (str logger-ns) timbre-config)))))

([timbre-config get-logger-fn]

This comment has been minimized.

Copy link
@Josh-Tilles

Josh-Tilles Jul 4, 2016

Contributor

It looks like timbre-config is unused in the body of this arity. Was that deliberate?

This comment has been minimized.

Copy link
@ptaoussanis

ptaoussanis Jul 5, 2016

Author Member

Oh, not deliberate - thanks for the catch!

(alter-var-root #'clojure.tools.logging/*logger-factory*
(constantly (LoggerFactory. get-logger-fn)))))

0 comments on commit 43f4fdf

Please sign in to comment.