-
-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f9563cc
commit 43f4fdf
Showing
1 changed file
with
27 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
(alter-var-root #'clojure.tools.logging/*logger-factory* | ||
(constantly (LoggerFactory. get-logger-fn))))) |
It looks like
timbre-config
is unused in the body of this arity. Was that deliberate?