Created
July 5, 2020 05:57
-
-
Save moosebay/1cb6beba8ad57336e4a2d9342a30a9b3 to your computer and use it in GitHub Desktop.
This is a shim for console logs. Console log interceptor IE 11 compatiable
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
var oldConsole = { | |
log: console.log, | |
debug: console.debug, | |
info: console.info, | |
warn: console.warn, | |
error: console.error, | |
trace: console.trace | |
}; | |
function doSomething(obj) { | |
// do your thing | |
} | |
function shim(type) { | |
var args = [...arguments].splice(1) | |
oldConsole[type](...args) | |
doSomething({ | |
arguments: [...args], | |
timestamp: new Date().getTime() / 1000, | |
type: type | |
}); | |
} | |
window.addEventListener('error', function (event) { | |
oldConsole.log(event); | |
doSomething({ | |
arguments: [event.message], | |
timestamp: new Date().getTime() / 1000, | |
type: 'error', | |
errorEvent: { | |
lineNo: event.lineno, | |
stack: event.error && event.error.stack, | |
colno: event.colno, | |
filename: event.filename | |
} | |
}) | |
}) | |
console.log = function () { shim('log', ...arguments) }; | |
console.debug = function () { shim('debug', ...arguments) }; | |
console.info = function () { shim('info', ...arguments) }; | |
console.warn = function () { shim('warn', ...arguments) }; | |
console.error = function () { shim('error', ...arguments) }; | |
console.trace = function () { shim('trace', ...arguments) }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment