Last active
November 21, 2017 19:50
-
-
Save kevinchisholm/b74dab0d32f53ac2d655266605cf7f2b to your computer and use it in GitHub Desktop.
Show console.log output in the DOM
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
(function () { | |
var $consoleLog = $('<div id="console-log"></div>'), | |
newLine = function(){return $('<p class="console-line"></p>'); }, | |
cssText = '.console-line{margin:10px;padding:10px;background-color:#ededed;border:1px solid #ccc;font-weight:700;font-family:monospace;color:#333;font-size:18px}.dir{background-color:#80e5a6}.info{background-color:#cff}.warn{background-color:#fdfd96}.error{background-color:#ff6961}', | |
$style = $('<style>' + cssText + '</style>'); | |
//reminder: jQuery is a dependency! | |
$('body').prepend($consoleLog); | |
$('body').append($style); | |
window.console = { | |
log: function(text) { | |
$consoleLog.append(newLine().html(text)); | |
}, | |
dir: function(text) { | |
$consoleLog.append(newLine().addClass('dir').html(JSON.stringify(text))); | |
}, | |
info: function(text) { | |
$consoleLog.append(newLine().addClass('info').html(text)); | |
}, | |
warn: function(text) { | |
$consoleLog.append(newLine().addClass('warn').html(text)); | |
}, | |
error: function(text) { | |
$consoleLog.append(newLine().addClass('error').html(text)); | |
}, | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment