Created
July 24, 2019 22:39
-
-
Save resynth1943/c4d38382c522194fc39bffbeebaef7c2 to your computer and use it in GitHub Desktop.
A tiny logger that outputs logs to an element as <code> elements.
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
let logBuffer = []; | |
let appendText = (text) => { | |
logBuffer.push(text); | |
} | |
window.addEventListener('DOMContentLoaded', () => { | |
const logBox = document.getElementById('logbox'); | |
appendText = (text) => { | |
logBox.appendChild(document.createElement('br')); | |
const codeElement = document.createElement('code'); | |
codeElement.appendChild(new Text(text)); | |
logBox.appendChild(codeElement); | |
}; | |
for (const item of logBuffer) { | |
appendText(item); | |
} | |
logBuffer = []; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment