How to show all console messages on a div?
I have this code:
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
Which is great for simple console logs, but I want everything in there! whatever the console shows in the browser I want in this div:
eg:
i170.png:1 GET http://localhost:3000/modules/core/img/items/i170.png 404 (Not Found)
i183.png:1 GET http://localhost:3000/modules/core/img/items/i183.png 404 (Not Found)
is not displayed in the div I created, how can I show all of it there?
+3
source to share
1 answer
There are two questions here.
1) dump all arguments passed to console.log
You get all the arguments to a function in arguments
. So this is a possible solution.
Edit
console.log = function(message) {
console.olog(message);
$('#debugDiv').append('<p>' + message + '</p>');
};
to
console.log = function() {
console.olog.apply(console, arguments);
$('#debugDiv').append('<p>' + [].map.call(arguments, JSON.stringify) + '</p>');
};
2) get all errors
The simplest solution is to add
window.onerror = console.log;
but please note that some errors do not run onerror
and cannot be tied to JS.
+3
source to share