Add library for simple logging, specifically for debugging.
This commit is contained in:
parent
eca862057a
commit
7d882ac01b
3 changed files with 41 additions and 1 deletions
|
@ -13,7 +13,8 @@ Breaking Changes:
|
||||||
|
|
||||||
Improvements:
|
Improvements:
|
||||||
|
|
||||||
* Support Trampolining (thanks to @maxsnew and @timthelion)
|
* Add Trampoline library (thanks to @maxsnew and @timthelion)
|
||||||
|
* Add Debug library (inspired by @timthelion)
|
||||||
* Drastically improved performance on markdown parsing (thanks to @Dandandan)
|
* Drastically improved performance on markdown parsing (thanks to @Dandandan)
|
||||||
* Add Date.fromTime function
|
* Add Date.fromTime function
|
||||||
* Use pointer-events to detect hovers on layered elements (thanks to @Xashili)
|
* Use pointer-events to detect hovers on layered elements (thanks to @Xashili)
|
||||||
|
|
17
libraries/Debug.elm
Normal file
17
libraries/Debug.elm
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
module Debug where
|
||||||
|
{-| This library is for investigating bugs or performance problems. It should
|
||||||
|
*not* be used in production code.
|
||||||
|
-}
|
||||||
|
|
||||||
|
import Native.Debug
|
||||||
|
|
||||||
|
{-| Log a tagged value on the developer console, and then return the value.
|
||||||
|
|
||||||
|
1 + log "number" 1 -- equals 2, logs "number: 1"
|
||||||
|
length (log "start" []) -- equals 0, logs "start: []"
|
||||||
|
|
||||||
|
Notice that `log` is not a pure function! It should *only* be used for
|
||||||
|
investigating bugs or performance problems.
|
||||||
|
-}
|
||||||
|
log : String -> a -> a
|
||||||
|
log = Native.Debug.log
|
22
libraries/Native/Debug.js
Normal file
22
libraries/Native/Debug.js
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
Elm.Native.Debug = {};
|
||||||
|
Elm.Native.Debug.make = function(elm) {
|
||||||
|
elm.Native = elm.Native || {};
|
||||||
|
elm.Native.Debug = elm.Native.Debug || {};
|
||||||
|
if (elm.Native.Debug.values) return elm.Native.Debug.values;
|
||||||
|
|
||||||
|
var show = Elm.Native.Show.make(elm).show;
|
||||||
|
|
||||||
|
function log(tag,value) {
|
||||||
|
if (process && process.stdout) {
|
||||||
|
process.stdout.write(tag + ': ' + show(value));
|
||||||
|
} else {
|
||||||
|
console.log(tag + ': ' + show(value));
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return elm.Native.Debug.values = {
|
||||||
|
log: F2(log)
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
Loading…
Reference in a new issue