Last active
April 19, 2019 18:58
-
-
Save samrocksc/2b9639c99538848be7bb80f99ca63f83 to your computer and use it in GitHub Desktop.
Revisions
-
samrocksc revised this gist
Apr 19, 2019 . 1 changed file with 15 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -51,4 +51,18 @@ const debug = { warning: msg => w(msg, buildStack()), }; function bar() { debug.verbose('name->bar'); baz(); } const foo = thing => { debug.verbose('name->foo') thing(); } const baz = () => { debug.verbose('name->baz'); } foo(bar); -
samrocksc revised this gist
Apr 19, 2019 . 1 changed file with 13 additions and 13 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,41 +4,41 @@ const w = require('debug')('warning'); const buildStack = () => { const depth = 3; if (!this.stackIs) { Object.defineProperty(this, 'stackIs', { get: function() { const orig = Error.prepareStackTrace; Error.prepareStackTrace = function(_, stack) { return stack; }; const err = new Error(); Error.captureStackTrace(err, arguments.callee); const stack = err.stack; Error.prepareStackTrace = orig; return stack; }, }); } if (!this.lineIs) { Object.defineProperty(this, 'lineIs', { get: function() { return this.stackIs[depth].getLineNumber(); }, }); } if (!this.functionIs) { Object.defineProperty(this, 'functionIs', { get: function() { return this.stackIs[depth].getFunctionName(); }, }); } return { function: this.functionIs, line: this.lineIs, }; }; -
samrocksc created this gist
Apr 19, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,54 @@ const v = require('debug')('verbose'); const e = require('debug')('error'); const w = require('debug')('warning'); const buildStack = () => { const depth = 3; if (!this.__stack) { Object.defineProperty(this, '__stack', { get: function() { var orig = Error.prepareStackTrace; Error.prepareStackTrace = function(_, stack) { return stack; }; var err = new Error(); Error.captureStackTrace(err, arguments.callee); var stack = err.stack; Error.prepareStackTrace = orig; return stack; }, }); } if (!this.__line) { Object.defineProperty(this, '__line', { get: function() { return this.__stack[depth].getLineNumber(); }, }); } if (!this.__function) { Object.defineProperty(this, '__function', { get: function() { return this.__stack[depth].getFunctionName(); }, }); } return { function: this.__function, line: this.__line, }; }; /** * base the functions to apply debugging */ const debug = { verbose: msg => v(msg, buildStack()), error: msg => e(msg, buildStack()), warning: msg => w(msg, buildStack()), }; module.exports = debug;