Skip to content

Instantly share code, notes, and snippets.

@huttj
Created May 24, 2015 21:38
Show Gist options
  • Save huttj/29ac35b816fbcf6c502a to your computer and use it in GitHub Desktop.
Save huttj/29ac35b816fbcf6c502a to your computer and use it in GitHub Desktop.
Automatic line number logging in JavaScript
function log() {
var stack;
try {
throw new Error();
} catch (e) {
stack = e.stack.split('\n')[2].match(/\s+at\s+(.+)/)[1] + ':\n\t';
}
var args = Array.prototype.slice.call(arguments);
args.unshift(stack);
console.log.apply(console, args);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment