Created
October 3, 2012 09:31
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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