I'm building a debugging tool for my web app and I need to show console errors in a div. I know I can use my own made console like object and use it, but for future use I need to send all console errors to window. Actually I want to catch console events.
console.info() : The console.info() is a method in JavaScript that is used to display the important messages to the console.
} if you see in my 3 statement i.e alert(“Let's go down the first road!”); we are using 'alert' here to write a statement. But, when it comes to the 6th statement we are instructed to use 'console. log'. We use 'console.
Here's a way using closure, containing the old console log function in the scope of the new one.
console.log = (function (old_function, div_log) { return function (text) { old_function(text); div_log.value += text; }; } (console.log.bind(console), document.getElementById("error-log")));
To keep the console working:
if (typeof console != "undefined") if (typeof console.log != 'undefined') console.olog = console.log; else console.olog = function() {}; console.log = function(message) { console.olog(message); $('#debugDiv').append('<p>' + message + '</p>'); }; console.error = console.debug = console.info = console.log
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With