Skip to content

Commit

Permalink
[#172] Housekeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaoussanis committed Jun 16, 2016
1 parent 81e779b commit 02c8fef
Showing 1 changed file with 40 additions and 30 deletions.
70 changes: 40 additions & 30 deletions src/taoensso/timbre.cljx
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))))

(comment (stacktrace (Exception. "Boo") {:stacktrace-fonts nil}))
#+clj
(def ^:private default-stacktrace-fonts
(or (sys-val "TIMBRE_DEFAULT_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]
Expand Down

0 comments on commit 02c8fef

Please sign in to comment.