Skip to content

Instantly share code, notes, and snippets.

@xploshioOn
Created April 9, 2018 13:23
Show Gist options
  • Save xploshioOn/56606807cc0b30b02ee430809ff0f048 to your computer and use it in GitHub Desktop.
Save xploshioOn/56606807cc0b30b02ee430809ff0f048 to your computer and use it in GitHub Desktop.
add all errors/console.log to div on html dynamically
var baseLogFunction = console.log;
console.log = function(){
baseLogFunction.apply(console, arguments);
var args = Array.prototype.slice.call(arguments);
for(var i=0;i<args.length;i++){
var node = createLogNode(args[i]);
document.querySelector("#debugDiv").appendChild(node);
}
}
function createLogNode(message){
var node = document.createElement("div");
var textNode = document.createTextNode(message);
node.appendChild(textNode);
return node;
}
window.onerror = function(message, url, linenumber) {
console.log("JavaScript error: " + message + " on line " +
linenumber + " for " + url);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment