Skip to content

Commit

Permalink
[mod] [#354] Make callsite-id in log! macro deterministic for Clo…
Browse files Browse the repository at this point in the history
…jure (@DerGuteMoritz)

Since the non-deterministic `rand` was used as part of generating
`callsite-id` in the `log!` macro at compile time, the compiler would
produce non-deterministic bytecode as a result. This thwarts
reproducible builds.

Instead, use a RNG with a fixed seed. Unfortunately, both the JS
standard library and Google Closure's library don't seem to provide a
similar facility, so it's only implemented for Clojure.
  • Loading branch information
DerGuteMoritz authored and ptaoussanis committed Oct 20, 2022
1 parent fe5d275 commit 4c01b34
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/taoensso/timbre.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,13 @@

(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 [rand ^java.util.Random (java.util.Random. 715873)]
(defn- deterministic-rand [] (.nextDouble rand))))

(defmacro log! ; Public wrapper around `-log!`
"Core low-level log macro. Useful for tooling/library authors, etc.
Expand Down Expand Up @@ -726,7 +733,7 @@
;; `slf4j-timbre`, etc.):
callsite-id
(hash [level msg-type args ; Unevaluated args (arg forms)
?ns-str ?file ?line (rand)])
?ns-str ?file ?line (deterministic-rand)])

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

0 comments on commit 4c01b34

Please sign in to comment.