I want to override console.log method to invoke a set of tasks whenever console.log is called. I referred other Stackoverflow answers but that give me the error:
Uncaught RangeError: Maximum call stack size exceeded.
This is what I want to do:
backupconsolelog = console.log;
console.log = function(arguments)
{
//do my tasks;
backupconsolelog(arguments);
}
Update 1: Somehow managed to over-ride console.log successfully, but I'm now unable to execute console.log(displaySomethingInConsole) in the same .js file where over-riding is done. This somehow causes recursive call to console.log, and gives again Uncaught RangeError: Maximum call stack size exceeded.
How do I use console.log() in the same .js file?
Update 2: I've have a check() function which is called by over-rided console.log. But, there was a console.log call inside the check() function which caused Maximum call stack size exceeded. error.
Update 3: Error again! :(
Uncaught TypeError: Illegal invocation
var _log = window.console.log;
window.console.log = function () {
_log.apply(this, arguments);
check();
};
_log("aaa");
check() {};
Update 4: Binding console to _log, i.e., console.log.bind(console) cleared it.