Tracing of nested fx handlers on :trace logging level

This commit is contained in:
Roman Volosovskyi 2021-05-25 09:16:00 +03:00
parent 6d43f34cf8
commit 011de1b8ae
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
3 changed files with 24 additions and 3 deletions

View File

@ -10,6 +10,9 @@
(fn [cofx# [_# ~@argsyms]] (~name cofx# ~@argsyms))))
events))
(defn- fully-qualified-name [sym]
(str *ns* "/" (name sym)))
(defmacro defn
"Defines an fx producing function
Takes the same arguments as the defn macro
@ -50,6 +53,18 @@
(clojure.core/defn ~(with-meta name m)
([~@argsyms] (fn [cofx#] (~(with-meta name m) cofx# ~@argsyms)))
([cofx# ~@args]
(when js/goog.DEBUG
(when (taoensso.timbre/level>=
:trace
(:level taoensso.timbre/*config*))
(println
(clojure.string/join
(concat
(repeat
(deref status-im.utils.handlers/handler-nesting-level)
"│ ")
["├─"]))
~(str (clojure.core/name name) " " *ns*))))
(if (and (map? cofx#)
(not (nil? (:db cofx#))))
(let [res# (let [~cofx cofx#] ~@fdecl)]
@ -61,9 +76,9 @@
m#
(when (and (map? k#)
(contains? k# :db))
(throw (js/Error. (str "fx/defn's result is used as fx producing function in " ~name))))
(throw (js/Error. (str "fx/defn's result is used as fx producing function in " ~(fully-qualified-name name)))))
(get m# k# nil)))))
res#)
(throw (js/Error. (str "fx/defn expects a map of cofx as first argument got " cofx# " in function " ~name))))))
(throw (js/Error. (str "fx/defn expects a map of cofx as first argument got " cofx# " in function " ~(fully-qualified-name name)))))))
~@(register-events events interceptors (with-meta name m) argsyms))
(throw (Exception. (str "fx/defn expects a vector of keyword as value for :events key in attr-map in function " name))))))

View File

@ -2,7 +2,7 @@
(:require-macros status-im.utils.fx)
(:require [status-im.ethereum.json-rpc :as json-rpc]
[taoensso.timbre :as log]
status-im.utils.handlers)
[status-im.utils.handlers :as handlers])
(:refer-clojure :exclude [merge reduce]))
(defn- update-db [cofx fx]
@ -47,6 +47,8 @@
:data-source/tx and effects are handled specially and their results
(list of transactions) are compacted to one transactions list (for each effect). "
[{:keys [db] :as cofx} & args]
(when js/goog.DEBUG
(swap! handlers/handler-nesting-level inc))
(let [[first-arg & rest-args] args
initial-fxs? (map? first-arg)
fx-fns (if initial-fxs? rest-args args)]

View File

@ -36,12 +36,16 @@
(let [[first _] (get-coeffect ctx :event)]
first))
(def handler-nesting-level (atom 0))
(def debug-handlers-names
"Interceptor which logs debug information to js/console for each event."
(->interceptor
:id :debug-handlers-names
:before (fn debug-handlers-names-before
[context]
(when js/goog.DEBUG
(reset! handler-nesting-level 0))
(log/debug "Handling re-frame event: " (pretty-print-event context))
context)))