Created
June 22, 2017 13:41
-
-
Save rarous/57f4b43bfe99b6cb9d29cdfbbb36dd5c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(ns methyl.console | |
"Helper functions for logging. | |
Logging is enebled only when `goog.DEBUG` symbol is defined with value equal to `true`." | |
(:refer-clojure :exclude [time])) | |
(def | |
^{:docs | |
"Displays a message in the console. Pass one or more objects to this method. | |
Each object is evaluated and concatenated into a space-delimited string. | |
``` | |
console.log('Hello, Logs!'); | |
``` | |
## Format specifiers | |
The first object you pass can contain one or more format specifiers. | |
A format specifier is composed of the percent sign (%) followed by a letter that indicates the formatting to apply."} | |
log | |
(if js/goog.DEBUG (.bind js/console.log js/console) (constantly nil))) | |
(def | |
^{:docs "Prints a message like `log` but also shows an icon (blue circle with white “i”) next to the output."} | |
info | |
(if js/goog.DEBUG (.bind js/console.info js/console) (constantly nil))) | |
(def | |
^{:docs "Prints a message like `log`, but also displays a yellow warning icon next to the logged message."} | |
warn | |
(if js/goog.DEBUG (.bind js/console.warn js/console) (constantly nil))) | |
(def | |
^{:docs | |
"Prints a message similar to `log`, styles the message like an error, | |
and includes a stack trace from where the method was called."} | |
error | |
(if js/goog.DEBUG (.bind js/console.error js/console) (constantly nil))) | |
(def | |
^{:docs | |
"Starts a new logging group with an optional title. All console output that occurs after `group` | |
and before `group-end` is visually grouped together."} | |
group | |
(if js/goog.DEBUG (.bind js/console.group js/console) (constantly nil))) | |
(def | |
^{:docs "Closes a logging group."} | |
group-end | |
(if js/goog.DEBUG (.bind js/console.groupEnd js/console) (constantly nil))) | |
(def | |
^{:docs | |
"Starts a new timer with an associated label. When `time-end` is called with the same label, | |
the timer is stopped and the elapsed time is displayed in the console. Timer values are accurate | |
to the sub-millisecond. The strings passed to `time` and `time-end` must match | |
or else the timer will not finish."} | |
time | |
(if js/goog.DEBUG (.bind js/console.time js/console) (constantly nil))) | |
(def | |
^{:docs | |
"Stops the current timer if one is in progress and prints the timer label followed by | |
the elapsed time to the Console."} | |
time-end | |
(if js/goog.DEBUG (.bind js/console.timeEnd js/console) (constantly nil))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment