Skip to content

Commit

Permalink
[nop] [#360] Simplify callsite id entropy
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaoussanis committed Nov 18, 2022
1 parent 4858d4b commit d99dc6f
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/taoensso/timbre.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -749,12 +749,9 @@

(defn- fline [and-form] (:line (meta and-form)))

;; Try enable reproducible builds by ensuring that `log!` macro expansion
;; produces deterministic callsite-ids, Ref. #354
#?(:cljs (def ^:private deterministic-rand rand) ; Dummy, non-deterministic
:clj (let [;; Must be delayed for GraalVM compatibility, Ref. #360
rand_ (delay (java.util.Random. 715873))]
(defn- deterministic-rand [] (.nextDouble ^java.util.Random @rand_))))
(enc/defonce ^:private callsite-counter
"Simple counter, used to uniquely identify each log macro expansion."
(enc/counter))

(defmacro log! ; Public wrapper around `-log!`
"Core low-level log macro. Useful for tooling/library authors, etc.
Expand Down Expand Up @@ -786,12 +783,9 @@

?file (when (not= ?file "NO_SOURCE_PATH") ?file)

;; Identifies this particular macro expansion; note that this'll
;; be fixed for any fns wrapping `log!` (notably `tools.logging`,
;; `slf4j-timbre`, etc.):
callsite-id
(hash [level msg-type args ; Unevaluated args (arg forms)
?ns-str ?file ?line (deterministic-rand)])
;; Note that this'll be const for any fns wrapping `log!`
;; (notably `tools.logging`, `slf4j-timbre`, etc.)
callsite-id (callsite-counter)

vargs-form
(if (symbol? args)
Expand Down

0 comments on commit d99dc6f

Please sign in to comment.