Skip to content

Instantly share code, notes, and snippets.

@gertverhoog
Created October 3, 2012 09:31
Show Gist options
  • Save gertverhoog/3826051 to your computer and use it in GitHub Desktop.
Save gertverhoog/3826051 to your computer and use it in GitHub Desktop.
a simple Clojurescript logging function that prints objects with pr-str when appropriate
(defn- printable?
"Returns true if obj is printable with pr-str, false otherwise.
the function `log` uses this"
[obj]
(try
(satisfies? IPrintWithWriter obj)
(catch js/Error e
(satisfies? IPrintable obj))))
(defn log [& more]
(.apply (.-log js/console) js/console
(into-array (map #(if (printable? %)
(pr-str %)
%)
more))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment