Skip to content

Instantly share code, notes, and snippets.

@justinmklam
Created March 5, 2019 21:49
Show Gist options
  • Save justinmklam/10e896ea88a07f57a1814139ff2a4f5e to your computer and use it in GitHub Desktop.
Save justinmklam/10e896ea88a07f57a1814139ff2a4f5e to your computer and use it in GitHub Desktop.
console.log() override to display messages in a frontend element instead.
// Override console log to show messages on frontend. Useful for debugging on mobile (where console is unavailable).
//
// Example HTML:
//
// <div id="log"></div>
//
// Source: https://stackoverflow.com/a/20256785
(function () {
var old = console.log;
var logger = document.getElementById('log');
console.log = function (message) {
if (typeof message == 'object') {
logger.innerHTML += (JSON && JSON.stringify ? JSON.stringify(message) : message) + '<br />';
} else {
logger.innerHTML += message + '<br />';
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment