mirror of https://github.com/status-im/timbre.git
Misc housekeeping
This commit is contained in:
parent
e6fe2bac4b
commit
2452041296
|
@ -111,7 +111,7 @@
|
|||
#+clj :timestamp-opts
|
||||
#+clj default-timestamp-opts ; {:pattern _ :locale _ :timezone _}
|
||||
|
||||
:output-fn default-output-fn ; (fn [data]) -> string
|
||||
:output-fn default-output-fn ; (fn [data & [opts]]) -> string
|
||||
|
||||
:appenders
|
||||
#+clj
|
||||
|
@ -202,8 +202,8 @@
|
|||
;;;; Levels
|
||||
|
||||
(def ordered-levels [:trace :debug :info :warn :error :fatal :report])
|
||||
(def ^:private scored-levels (zipmap ordered-levels (next (range))))
|
||||
(def ^:private valid-levels (set ordered-levels))
|
||||
(def ^:private scored-levels (zipmap ordered-levels (next (range))))
|
||||
(def ^:private valid-levels (set ordered-levels))
|
||||
(def ^:private valid-level
|
||||
(fn [level]
|
||||
(or (valid-levels level)
|
||||
|
@ -222,12 +222,6 @@
|
|||
(keyword (or (env-val "TIMBRE_LEVEL")
|
||||
(env-val "TIMBRE_LOG_LEVEL")))))
|
||||
|
||||
(defn get-active-level [& [config]] (or (:level (or config *config*)) :report))
|
||||
|
||||
(comment
|
||||
(qb 10000 (get-active-level))
|
||||
(binding [*config* {:level :trace}] (level>= :trace (get-active-level))))
|
||||
|
||||
;;;; ns filter
|
||||
|
||||
(def ^:private compile-ns-filters
|
||||
|
@ -311,15 +305,24 @@
|
|||
|
||||
(defn log?
|
||||
"Would Timbre currently log at the given logging level?
|
||||
* ns filtering requires a compile-time `?ns-str` to be provided.
|
||||
* Non-global config requires an explicit `config` to be provided."
|
||||
* Compile-time `?ns-str` arg required to support ns filtering.
|
||||
* `config` arg required to support non-global config."
|
||||
[level & [?ns-str config]]
|
||||
(let [config (or config *config*)]
|
||||
(and (level>= level (get-active-level config))
|
||||
(let [config (or config *config*)
|
||||
active-level (or (:level config) :report)]
|
||||
(and (level>= level active-level)
|
||||
(ns-filter (:ns-whitelist config) (:ns-blacklist config) (or ?ns-str ""))
|
||||
true)))
|
||||
|
||||
(comment (log? :trace))
|
||||
(comment
|
||||
(set-level! :debug)
|
||||
(log? :trace)
|
||||
(with-level :trace (log? :trace))
|
||||
(qb 10000 (log? :trace)) ; ~2.5ms
|
||||
(qb 10000 (log? :trace "foo")) ; ~6ms
|
||||
(qb 10000 (tracef "foo")) ; ~7.5ms
|
||||
(qb 10000 (when false "foo")) ; ~0.5ms
|
||||
)
|
||||
|
||||
(def ^:dynamic *context*
|
||||
"General-purpose dynamic logging context. Context will be merged into
|
||||
|
@ -330,7 +333,7 @@
|
|||
|
||||
(defn log1-fn
|
||||
"Core fn-level logger. Implementation detail!"
|
||||
[config level ?ns-str ?file ?line msg-type vargs_ & [?base-data]]
|
||||
[config level ?ns-str ?file ?line msg-type vargs_ ?base-data]
|
||||
(when (log? level ?ns-str config)
|
||||
(let [instant (enc/now-dt)
|
||||
vargs*_ (delay (vsplit-err1 (force vargs_)))
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
(ns taoensso.timbre.appenders.example-appender
|
||||
"An example of how Timbre appenders should be written.
|
||||
Please mention any requirements/dependencies in this docstring."
|
||||
{:author "Peter Taoussanis"} ; <- Your name here
|
||||
"An example of how Timbre library-style appenders should be written for
|
||||
bundling with Timbre. Please mention any requirements/dependencies in this
|
||||
docstring, thanks!"
|
||||
{:author "Your name here"}
|
||||
(:require [clojure.string :as str]
|
||||
[taoensso.timbre :as timbre]
|
||||
[taoensso.encore :as encore]))
|
||||
|
@ -45,8 +46,8 @@
|
|||
;; provided for you under the :output-fn key. Prefer using this fn
|
||||
;; to your own formatter when possible, since the user can
|
||||
;; configure the :output-fn formatter in a standard way that'll
|
||||
;; influence all participating appenders. It may help to look at
|
||||
;; the source code for `taoensso.timbre/default-output-fn`!
|
||||
;; influence all participating appenders. Take a look at the
|
||||
;; `taoensso.timbre/default-output-fn` source for details.
|
||||
;;
|
||||
any-special-output-fn-opts {} ; Output-fn can use these opts
|
||||
output-string (output-fn data any-special-output-fn-opts)]
|
||||
|
|
Loading…
Reference in New Issue