-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.html
More file actions
166 lines (152 loc) · 4.99 KB
/
log.html
File metadata and controls
166 lines (152 loc) · 4.99 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Activity Logs</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
<style>
body {
background-color: #f8f9fa;
font-family: 'Inter', sans-serif;
}
.log-container {
max-width: 1000px;
margin: 2rem auto;
background: white;
border-radius: 0.75rem;
box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.05);
}
.log-entry {
padding: 1rem 1.5rem;
border-bottom: 1px solid #eceff1;
transition: background-color 0.2s ease;
display: flex;
gap: 1.5rem;
align-items: flex-start;
}
.log-entry:hover {
background-color: #f8f9fa;
}
.log-date {
color: #3f51b5;
font-weight: 600;
min-width: 120px;
font-size: 0.9rem;
}
.log-time {
color: #4caf50;
font-weight: 500;
min-width: 100px;
font-size: 0.9rem;
}
.log-message {
color: #37474f;
flex-grow: 1;
font-size: 0.95rem;
line-height: 1.5;
}
.log-error {
color: #d32f2f;
background-color: #ffebee;
border-left: 3px solid #d32f2f;
}
.header-section {
border-bottom: 1px solid #eceff1;
padding: 1.5rem;
}
.dropdown {
max-width: 200px;
}
@media (max-width: 768px) {
.log-entry {
flex-direction: column;
gap: 0.5rem;
padding: 1rem;
}
.log-date, .log-time {
min-width: auto;
}
}
</style>
</head>
<body>
<div class="container py-4">
<div class="log-container">
<div class="header-section">
<div class="d-flex flex-column flex-md-row justify-content-between align-items-md-center mb-3">
<h2 class="h4 mb-3 mb-md-0 fw-bold">Activity Logs</h2>
<div class="d-flex gap-2">
<button class="btn btn-primary d-flex align-items-center" onclick="fetchLogs()">
<span class="d-none d-sm-inline">Refresh</span>
</button>
<select id="dateFilter" class="form-select" onchange="filterLogs()">
<option value="">All Dates</option>
</select>
</div>
</div>
</div>
<div id="log-content" class="py-2"></div>
</div>
</div>
<script>
let allLogs = [];
function fetchLogs() {
fetch("http://localhost:5000/logs")
.then(response => response.json())
.then(data => {
if (data.logs) {
allLogs = data.logs.reverse();
populateDateDropdown();
displayLogs();
}
})
.catch(console.error);
}
function populateDateDropdown() {
const dates = [...new Set(allLogs.map(log => {
const match = log.match(/^(\d{4}-\d{2}-\d{2})/);
return match ? match[1] : null;
}).filter(Boolean))].reverse();
const dropdown = document.getElementById("dateFilter");
dropdown.innerHTML = '<option value="">All Dates</option>';
dates.forEach(date => {
const option = new Option(date, date);
dropdown.add(option);
});
}
function displayLogs(filterDate = "") {
const container = document.getElementById("log-content");
container.innerHTML = "";
const filteredLogs = filterDate
? allLogs.filter(log => log.startsWith(filterDate))
: allLogs;
if (filteredLogs.length === 0) {
container.innerHTML = `<div class="text-center py-4 text-muted">No logs found</div>`;
return;
}
filteredLogs.forEach(log => {
const entry = document.createElement("div");
entry.className = "log-entry";
const match = log.match(/^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2},\d{3}) - (.*)/s);
if (match) {
entry.innerHTML = `
<div class="log-date">${match[1]}</div>
<div class="log-time">${match[2]}</div>
<div class="log-message">${match[3]}</div>
`;
} else {
entry.className += " log-error";
entry.innerHTML = `<div class="log-message">${log}</div>`;
}
container.appendChild(entry);
});
}
function filterLogs() {
const selectedDate = document.getElementById("dateFilter").value;
displayLogs(selectedDate);
}
fetchLogs();
</script>
</body>
</html>