[#172] Housekeeping

This commit is contained in:
Peter Taoussanis 2016-06-16 23:05:30 +07:00
parent 81e779b630
commit 02c8fef812
1 changed files with 39 additions and 29 deletions

View File

@ -23,6 +23,12 @@
;;;; Config
#+clj
(defn- sys-val [id]
(when-let [s (or (System/getProperty id)
(System/getenv id))]
(enc/read-edn s)))
#+clj
(def default-timestamp-opts
"Controls (:timestamp_ data)"
@ -112,9 +118,7 @@
#+clj :timestamp-opts
#+clj default-timestamp-opts ; {:pattern _ :locale _ :timezone _}
; (fn [data]) -> string
:output-fn #(let [env (System/getenv "TIMBRE_NO_STACKTRACE_FONTS")]
(default-output-fn (if env {:stacktrace-fonts {}}) %))
:output-fn default-output-fn ; (fn [data]) -> string
:appenders
#+clj
@ -165,17 +169,15 @@
(comment (qb 10000 (level>= :info :debug)))
#+clj
(defn- sys-val [id]
(when-let [s (or (System/getProperty id)
(System/getenv id))]
(enc/read-edn s)))
#+clj
(def ^:private compile-time-level
;; Will stack with runtime level
(have [:or nil? valid-level]
(keyword (or (sys-val "TIMBRE_LEVEL")
(sys-val "TIMBRE_LOG_LEVEL")))))
(when-let [level (keyword ; For back compatibility
(or (sys-val "TIMBRE_LEVEL")
(sys-val "TIMBRE_LOG_LEVEL")))]
(println (str "Compile-time (elision) Timbre level: " level))
level)))
;;;; ns filter
@ -222,16 +224,11 @@
#+clj
(def ^:private compile-time-ns-filter
;; Will stack with runtime ns filters
(let [whitelist (have [:or nil? vector?] (sys-val "TIMBRE_NS_WHITELIST"))
blacklist (have [:or nil? vector?] (sys-val "TIMBRE_NS_BLACKLIST"))]
(when compile-time-level
(println (str "Compile-time (elision) Timbre level: " compile-time-level)))
(when whitelist
(println (str "Compile-time (elision) Timbre ns whitelist: " whitelist)))
(when blacklist
(println (str "Compile-time (elision) Timbre ns blacklist: " blacklist)))
(when whitelist (println (str "Compile-time (elision) Timbre ns whitelist: " whitelist)))
(when blacklist (println (str "Compile-time (elision) Timbre ns blacklist: " blacklist)))
(fn [ns] (ns-filter whitelist blacklist ns))))
;;;; Utils
@ -670,17 +667,30 @@
(comment (get-hostname))
(defn stacktrace [err & [{:keys [stacktrace-fonts] :as opts}]]
#+cljs (str err) ; TODO Alternatives?
#+clj
(let [stacktrace-fonts (if (and (nil? stacktrace-fonts)
(contains? opts :stacktrace-fonts))
{} stacktrace-fonts)]
(if-let [fonts stacktrace-fonts]
(binding [aviso-ex/*fonts* fonts] (aviso-ex/format-exception err))
(aviso-ex/format-exception err))))
#+clj
(def ^:private default-stacktrace-fonts
(or (sys-val "TIMBRE_DEFAULT_STACKTRACE_FONTS")
nil))
(comment (stacktrace (Exception. "Boo") {:stacktrace-fonts nil}))
(defn stacktrace
([err ] (stacktrace err nil))
([err opts]
#+cljs (str err) ; TODO Alternatives?
#+clj
(let [stacktrace-fonts ; {:stacktrace-fonts nil->{}}
(if-let [e (find opts :stacktrace-fonts)]
(let [st-fonts (val e)]
(if (nil? st-fonts)
{}
st-fonts))
default-stacktrace-fonts)]
(if-let [fonts stacktrace-fonts]
(binding [aviso-ex/*fonts* fonts]
(do (aviso-ex/format-exception err)))
(do (aviso-ex/format-exception err))))))
(comment (stacktrace (Exception. "Boo") {:stacktrace-fonts {}}))
(defmacro sometimes "Handy for sampled logging, etc."
[probability & body]