Add library for simple logging, specifically for debugging.
commit7d882ac01b981c31729c9193ba8829beed2a4f06
authorEvan Czaplicki <info@elm-lang.org>
dateFri 21 Feb 2014, 11:57 (13 years ago)
parenteca8620
changelog.txt+2−1
@@ -13,7 +13,8 @@ Breaking Changes:
1313
1414Improvements:
1515
16− * Support Trampolining (thanks to @maxsnew and @timthelion)
16+ * Add Trampoline library (thanks to @maxsnew and @timthelion)
17+ * Add Debug library (inspired by @timthelion)
1718 * Drastically improved performance on markdown parsing (thanks to @Dandandan)
1819 * Add Date.fromTime function
1920 * Use pointer-events to detect hovers on layered elements (thanks to @Xashili)
libraries/Debug.elmnew file+17
@@ -0,0 +1,17 @@
1+module Debug where
2+{-| This library is for investigating bugs or performance problems. It should
3+*not* be used in production code.
4+-}
5+
6+import Native.Debug
7+
8+{-| Log a tagged value on the developer console, and then return the value.
9+
10+ 1 + log "number" 1 -- equals 2, logs "number: 1"
11+ length (log "start" []) -- equals 0, logs "start: []"
12+
13+Notice that `log` is not a pure function! It should *only* be used for
14+investigating bugs or performance problems.
15+-}
16+log : String -> a -> a
17+log = Native.Debug.log
libraries/Native/Debug.jsnew file+22
@@ -0,0 +1,22 @@
1+Elm.Native.Debug = {};
2+Elm.Native.Debug.make = function(elm) {
3+ elm.Native = elm.Native || {};
4+ elm.Native.Debug = elm.Native.Debug || {};
5+ if (elm.Native.Debug.values) return elm.Native.Debug.values;
6+
7+ var show = Elm.Native.Show.make(elm).show;
8+
9+ function log(tag,value) {
10+ if (process && process.stdout) {
11+ process.stdout.write(tag + ': ' + show(value));
12+ } else {
13+ console.log(tag + ': ' + show(value));
14+ }
15+ return value;
16+ }
17+
18+ return elm.Native.Debug.values = {
19+ log: F2(log)
20+ };
21+
22+};