Skip to content

Instantly share code, notes, and snippets.

@dotmaster
Created December 3, 2010 10:23
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dotmaster/726802 to your computer and use it in GitHub Desktop.
Save dotmaster/726802 to your computer and use it in GitHub Desktop.
hijacking Javascript console.log revamped with StackTrace (just Google Chrome)
// usage as usual: console.log('inside coolFunc',this,arguments);
if (typeof console !== "undefined") {
console.logJack = console.log;
window.log={}
window.log.history = window.log.history || {}; // store logs to a global history for reference
console.log=function(){
var timestamp= (new Date); //create a timestamp of the log
var millis=timestamp.getTime();
var readableString=timestamp.toUTCString();
var stack=new Error().stack; //save a stacktrace for Google Chrome
var array=Array.prototype.slice.call(arguments);
var args={arguments:array, stackTrace:stack}
log.history[millis]=args; //save everything to the log
console.logJack(readableString, arguments, millis); //call the original log function with a timestamp
}
}
@inspire22
Copy link

Looks promising, but your'e not passing the stack trace anywhere into the orig. console log?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment