Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cljs] Add support for console.group? #204

Open
seantempesta opened this issue Nov 21, 2016 · 3 comments
Open

[Cljs] Add support for console.group? #204

seantempesta opened this issue Nov 21, 2016 · 3 comments

Comments

@seantempesta
Copy link

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)))
@ptaoussanis
Copy link
Member

ptaoussanis commented Dec 17, 2016

Hi Sean,

Is there a reason you wouldn't want something like this?:

(trace "database state" {:conn conn :port port :host host})

@ptaoussanis
Copy link
Member

Oh, I see- you're specifically asking about console.group. Yeah, sorry- that's not something Timbre currently has support for.

Not familiar with console.group myself: it's capabilities, support, etc. Would be open to a an API suggestion, etc. with motivation.

Thanks! :-)

@ptaoussanis
Copy link
Member

BTW please ping/upvote if there's general demand for this feature. Again, motivations/examples would be especially useful- cheers! :-)

@ptaoussanis ptaoussanis changed the title Is it possible to get the symbol names for passed logging params in CLJS? [Cljs] Add support for console.group? Dec 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants