Created
June 11, 2014 23:11
-
-
Save v0lkan/a1ff9e2ce5cb6a1f3613 to your computer and use it in GitHub Desktop.
makes console.log display method and line info.
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
var methods = ['log', 'warn'], i, len, old; | |
for (i = 0, len = methods.length; i < len; i++){ | |
old = console[methods[i]]; | |
console[methods[i]] = function() { | |
var stack = (new Error()).stack.split(/\n/); | |
if (stack[0].indexOf('Error') === 0) {stack = stack.slice(1);} | |
var args = [].slice.apply(arguments).concat([stack[1].trim()]); | |
return old.apply(console, args); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment