Skip to content

Instantly share code, notes, and snippets.

@v0lkan
Created June 11, 2014 23:11
Show Gist options
  • Save v0lkan/a1ff9e2ce5cb6a1f3613 to your computer and use it in GitHub Desktop.
Save v0lkan/a1ff9e2ce5cb6a1f3613 to your computer and use it in GitHub Desktop.
makes console.log display method and line info.
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