Last active
July 25, 2019 05:45
-
-
Save kshwetabh/331f0d2f0ffa98608c041cbee9e283cd to your computer and use it in GitHub Desktop.
A convenient method to direct console.log/error statements to be written into a DIV and in browser's console.
This file contains 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
//Code borrowed from: https://github.com/aws-samples/amazon-kinesis-video-streams-media-viewer | |
function configureLogging() { | |
console._error = console.error; | |
console.error = function(messages) { | |
log('ERROR', Array.prototype.slice.call(arguments)); | |
console._error.apply(this, arguments); | |
} | |
console._log = console.log; | |
console.log = function(messages) { | |
log('INFO', Array.prototype.slice.call(arguments)); | |
console._log.apply(this, arguments); | |
} | |
function log(level, messages) { | |
var text = ''; | |
for (message of messages) { | |
if (typeof message === 'object') { message = JSON.stringify(message, null, 2); } | |
text += ' ' + message; | |
} | |
$('#logs').append($('<div>').text('[' + level + ']' + text + '\n')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment