-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.html
48 lines (42 loc) · 1.36 KB
/
log.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>log viewer</title>
<style>
.error {
color: red;
}
</style>
<script src="/socket.io/socket.io.js"></script>
</head>
<body>
<pre id="logView"></pre>
<script>
const socket = io();
const logView = document.getElementById("logView");
socket.on("connect", () => {
logView.innerHTML += `<div style="color: green;">서버와의 연결됐습니다.</div>`;
scrollDown();
});
socket.on("log", info => {
const { message, level, timestamp } = JSON.parse(info);
if (message.startsWith("GET /admin/dashboardData")) return;
logView.innerHTML += `<div class="${level}">${timestamp} ${level}: ${message}</div>`;
scrollDown();
});
socket.on("error", err => {
logView.innerHTML += `<div class="error">${err.toString()}</div>`;
scrollDown();
});
socket.on("disconnect", () => {
logView.innerHTML += `<div style="color: red;">서버와의 연결이 끊어졌습니다.</div>`;
scrollDown();
});
function scrollDown() {
window.scrollTo(0, document.body.scrollHeight);
}
</script>
</body>
</html>