Skip to content

Instantly share code, notes, and snippets.

@nitso
Last active August 29, 2015 13:57
Show Gist options
  • Save nitso/9666399 to your computer and use it in GitHub Desktop.
Save nitso/9666399 to your computer and use it in GitHub Desktop.
var getStackTrace = function() {
if (typeof Error.captureStackTrace == 'undefined') {
return [];
}
var obj = {};
Error.captureStackTrace(obj, getStackTrace);
var trace = obj.stack.split("\n");
trace.splice(0, 2);
return trace.map(function(value) {
return value.replace(/^\s+at\s+/, '');
});
};
var log = function() {
var args = Array.prototype.slice.call(arguments, 0);
var trace = getStackTrace();
if (trace.length) {
args.push({stackTrace: trace});
}
console.log.apply(console, args);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment