Skip to content

Instantly share code, notes, and snippets.

@kshwetabh
Last active July 25, 2019 05:45
Show Gist options
  • Save kshwetabh/331f0d2f0ffa98608c041cbee9e283cd to your computer and use it in GitHub Desktop.
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.
//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