Open
Description
During development it's super useful to do something like this:
(trace "database state" conn port host)
and get back:
console.group("database state")
console.log("conn", conn)
console.log("port", port)
console.log("host", host)
console.groupEnd();
as it's easily readable on the Chrome console what variable is what. Is there a way to get the symbol names (strings are fine) so I can print them? I created a macro to do this, but this feels hacky.
(defmacro trace [& args]
(let [first-arg (first args)
string-arg (if (string? first-arg) first-arg "Trace")
rest-args (if (string? first-arg) (rest args) args)
group-start `(oops.core/ocall js/console "group" ~string-arg)
groups (cons 'do (map (fn [arg] `(oops.core/ocall js/console "log" (quote ~arg) ~arg)) rest-args))
group-end `(oops.core/ocall js/console "groupEnd")
group-call (cons 'do [group-start groups group-end])
normal-call `(taoensso.timbre/trace ~args)
current-ns (str (ns-name *ns*))]
`(if (and js/goog.DEBUG (= :trace (:level taoensso.timbre/*config*)) (some #(= ~current-ns %) (:ns-whitelist taoensso.timbre/*config*)))
~group-call
~normal-call)))