Skip to content

Instantly share code, notes, and snippets.

@designbyadrian
Created August 18, 2014 14:41
Show Gist options
  • Save designbyadrian/2eb329c853516cef618a to your computer and use it in GitHub Desktop.
Save designbyadrian/2eb329c853516cef618a to your computer and use it in GitHub Desktop.
Hijack console.log, console.warn, and console.error without breaking the default browser function.
var cl,ce,cw;
if(window.console && console.log){
cl = console.log;
console.log = function(){
MyLogFunction(arguments);
cl.apply(this, arguments)
}
}
if(window.console && console.warn){
cw = console.warn;
console.warn = function(){
MyWarnFunction(arguments);
cw.apply(this, arguments)
}
}
if(window.console && console.error){
ce = console.error;
console.error = function(){
MyErrorFunction(arguments);
ce.apply(this, arguments)
}
}
@taylorjdawson
Copy link

The massageArguments method will get passed the arguments object and from there you can apply your formatting to each of the arguments that were originally passed to the console.<method>()

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