Last active
May 17, 2017 09:48
-
-
Save amodm/09a3350ec3162b8fe27d76bc24cca373 to your computer and use it in GitHub Desktop.
console.log to output window on jsFiddle
This file contains hidden or 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
// Hotlink: https://rawgit.com/amodm/09a3350ec3162b8fe27d76bc24cca373/raw/6bce576080dba78ef49fddbbda28f2e421b2caea/jsfiddle-logger.js | |
// | |
// You may need to call initJsFiddleLogger() explicitly | |
// | |
const existingConsoleLog = console && console.log; | |
const jsFiddleLogger = function(message) { | |
if (existingConsoleLog) { | |
existingConsoleLog(message); | |
} | |
if (typeof message === 'object') { | |
message = JSON.stringify(message); | |
} | |
const newLine = document.createElement('p'); | |
newLine.append(message); | |
jsFiddleLogger.jsFiddleLogContainer.appendChild(newLine); | |
}; | |
function initJsFiddleLogger() { | |
if (!console) console = {}; | |
if (!console.log || !console.log.jsFiddleLogContainer) { | |
console.log = jsFiddleLogger; | |
} | |
const logContainerName = 'logger'; | |
let logContainer = document.getElementById(logContainerName); | |
if (!logContainer) { | |
logContainer = document.createElement('div'); | |
logContainer.id = logContainerName; | |
document.body.appendChild(logContainer); | |
jsFiddleLogger.jsFiddleLogContainer = logContainer; | |
} | |
} | |
//onDomReady(initJsFiddleLogger); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment