Skip to content

Instantly share code, notes, and snippets.

@yoannmoinet
Last active February 3, 2016 18:19
Show Gist options
  • Save yoannmoinet/a6040e22695d8617d8cf to your computer and use it in GitHub Desktop.
Save yoannmoinet/a6040e22695d8617d8cf to your computer and use it in GitHub Desktop.
Will output in the console what the stack is at the moment this is called.
// nb [int] the number of line to get from the stack
function logStack (nb) {
try {
throw new Error();
} catch (e) {
var stack = e.stack.match(/(https?:\/\/[\w.:0-9\/]+)/g);
if (nb === undefined) {
nb = stack.length - 2;
}
console.log(
'- Stack(' + nb + ') :\n ' +
_.first(_.last(stack, stack.length - 2), nb)
.join('\n ')
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment