Created
May 24, 2015 21:38
-
-
Save huttj/29ac35b816fbcf6c502a to your computer and use it in GitHub Desktop.
Automatic line number logging in JavaScript
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
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