Created
March 5, 2019 21:49
-
-
Save justinmklam/10e896ea88a07f57a1814139ff2a4f5e to your computer and use it in GitHub Desktop.
console.log() override to display messages in a frontend element instead.
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
// 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