Created
August 28, 2021 12:01
-
-
Save ayaysir/041784bd269ddb37b48a01dde5dc5e6c to your computer and use it in GitHub Desktop.
콘솔 로그(console.log)를 HTML에 표시
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Console Log</title> | |
</head> | |
<body> | |
<pre id="console"></pre> | |
<script> | |
'use strict' | |
const consoleDiv = document.getElementById("console") | |
const consoleToHtml = function() { | |
consoleDiv.textContent += `${(new Date()).toLocaleString("ko-KR")} >>>` | |
Array.from(arguments).forEach(el => { | |
consoleDiv.textContent += " " | |
const insertValue = typeof el === "object" ? JSON.stringify(el) : el | |
consoleDiv.textContent += insertValue | |
}) | |
consoleDiv.textContent += "\n" | |
} | |
window.console.log = consoleToHtml | |
const object = { | |
a: "AAA", | |
b: "BBB", | |
c: { | |
c_a: "CA", | |
c_b: "CB" | |
}, | |
f: function() { | |
return true | |
} | |
} | |
console.log("지원자 %s: %d점", "김을동", 30, [3, 0, '점']) | |
console.log("aaa", 32.145, object) | |
console.log() | |
console.log(consoleToHtml) | |
</script> | |
</body></html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment