From 3068ccf8d7e0e41d664c80787370d44629fe2126 Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Mon, 26 Aug 2024 11:19:45 +0200 Subject: [PATCH] [new] Simplify signal expansion --- src/taoensso/telemere/impl.cljc | 55 +++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/src/taoensso/telemere/impl.cljc b/src/taoensso/telemere/impl.cljc index 07f53efe..c280a7ef 100644 --- a/src/taoensso/telemere/impl.cljc +++ b/src/taoensso/telemere/impl.cljc @@ -550,7 +550,12 @@ :sf-arity 4 :ct-sig-filter ct-sig-filter :*rt-sig-filter* `*rt-sig-filter*} - opts)] + + (assoc opts :bound-forms + {:kind '__kind + :ns '__ns + :id '__id + :level '__level}))] (if elide? run-form @@ -716,33 +721,35 @@ ;; (run-fn-form) ;; (let [...])))) - `(enc/if-not ~allow? ; Allow to throw at call - ~run-form - (let [;;; Allow to throw at call - ~'__inst ~inst-form - ~'__level ~level-form - ~'__kind ~kind-form - ~'__id ~id-form - ~'__ns ~ns-form - ~'__thread ~thread-form - ~'__root0 ~root-form0 ; ?{:keys [id uid]} - - ~@into-let-form ; Inject conditional bindings - signal# ~signal-delay-form] - - (dispatch-signal! - ;; Unconditionally send same wrapped signal to all handlers. - ;; Each handler will use wrapper for handler filtering, - ;; unwrapping (realizing) only allowed signals. - (WrappedSignal. ~'__ns ~'__kind ~'__id ~'__level signal#)) - - (if ~'__run-result - ( ~'__run-result signal#) - true)))))))) + ;; Unless otherwise specified, allow errors to throw on call + `(let [~'__kind ~kind-form + ~'__ns ~ns-form + ~'__id ~id-form + ~'__level ~level-form] + + (enc/if-not ~allow? + ~run-form + (let [~'__inst ~inst-form + ~'__thread ~thread-form + ~'__root0 ~root-form0 ; ?{:keys [id uid]} + + ~@into-let-form ; Inject conditional bindings + signal# ~signal-delay-form] + + (dispatch-signal! + ;; Unconditionally send same wrapped signal to all handlers. + ;; Each handler will use wrapper for handler filtering, + ;; unwrapping (realizing) only allowed signals. + (WrappedSignal. ~'__ns ~'__kind ~'__id ~'__level signal#)) + + (if ~'__run-result + ( ~'__run-result signal#) + true))))))))) (comment (with-signal (signal! {:level :warn :let [x :x] :msg ["Test" "message" x] :data {:a :A :x x} :run (+ 1 2)})) (macroexpand '(signal! {:level :warn :let [x :x] :msg ["Test" "message" x] :data {:a :A :x x} :run (+ 1 2)})) + (macroexpand '(signal! {:level :info})) (do (println "---")