8000 [Cljs] Add support for console.group? · Issue #204 · taoensso/timbre · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
[Cljs] Add support for console.group? #204
Open
@seantempesta

Description

@seantempesta

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)))

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0