Created
December 21, 2015 23:30
-
-
Save thomasJang/a8c891528f8f68ad9305 to your computer and use it in GitHub Desktop.
catch-console.js
This file contains 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 () { | |
var console = window.console; | |
if (!console) return; | |
function intercept(method) { | |
var original = console[method]; | |
console[method] = function () { | |
// do sneaky stuff | |
if (original.apply) { | |
// Do this for normal browsers | |
original.apply(console, arguments); | |
} | |
else { | |
// Do this for IE | |
var message = Array.prototype.slice.apply(arguments).join(' '); | |
original(message); | |
} | |
} | |
} | |
var methods = ['log', 'warn', 'error']; | |
for (var i = 0; i < methods.length; i++) intercept(methods[i]); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment