Skip to content

Instantly share code, notes, and snippets.

@ayaysir
Created August 28, 2021 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayaysir/041784bd269ddb37b48a01dde5dc5e6c to your computer and use it in GitHub Desktop.
Save ayaysir/041784bd269ddb37b48a01dde5dc5e6c to your computer and use it in GitHub Desktop.
콘솔 로그(console.log)를 HTML에 표시
<!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