-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-logging.html
More file actions
208 lines (188 loc) · 7.4 KB
/
test-logging.html
File metadata and controls
208 lines (188 loc) · 7.4 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test Terminal Logging</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
h1 {
color: #333;
}
.button-container {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin-bottom: 20px;
}
button {
padding: 10px 15px;
border: none;
border-radius: 4px;
cursor: pointer;
font-weight: bold;
}
.nav-button {
background-color: #4a90e2;
color: white;
}
.click-button {
background-color: #e24a90;
color: white;
}
.warning-button {
background-color: #e2c84a;
color: white;
}
.error-button {
background-color: #e24a4a;
color: white;
}
.info-button {
background-color: #4ae290;
color: white;
}
.log-container {
background-color: #f5f5f5;
padding: 15px;
border-radius: 4px;
margin-top: 20px;
}
.log-entry {
margin-bottom: 10px;
padding: 5px;
border-bottom: 1px solid #ddd;
}
.status {
margin-top: 20px;
padding: 10px;
background-color: #e8f5e9;
border-radius: 4px;
}
</style>
</head>
<body>
<h1>Test Terminal Logging</h1>
<p>This page allows you to test the terminal logging functionality. Click the buttons below to send different types of logs to the terminal.</p>
<div class="status" id="status">
Server Status: Checking...
</div>
<h2>Navigation Events</h2>
<div class="button-container">
<button class="nav-button" onclick="logNavigation('home', 'products')">Navigate: Home → Products</button>
<button class="nav-button" onclick="logNavigation('products', 'collections')">Navigate: Products → Collections</button>
<button class="nav-button" onclick="logNavigation('collections', 'about')">Navigate: Collections → About</button>
</div>
<h2>Button Clicks</h2>
<div class="button-container">
<button class="click-button" onclick="logClick('products-button', 'navigation button')">Click: Products Button</button>
<button class="click-button" onclick="logClick('collections-button', 'navigation button')">Click: Collections Button</button>
<button class="click-button" onclick="logClick('about-button', 'navigation button')">Click: About Button</button>
</div>
<h2>Warnings</h2>
<div class="button-container">
<button class="warning-button" onclick="logWarning('Missing onClick handler')">Warning: Missing onClick</button>
<button class="warning-button" onclick="logWarning('Navigation item not found')">Warning: Item Not Found</button>
</div>
<h2>Errors</h2>
<div class="button-container">
<button class="error-button" onclick="logError('Failed to navigate')">Error: Navigation Failed</button>
<button class="error-button" onclick="logError('Component crashed')">Error: Component Crashed</button>
</div>
<h2>Info Messages</h2>
<div class="button-container">
<button class="info-button" onclick="logInfo('Component mounted')">Info: Component Mounted</button>
<button class="info-button" onclick="logInfo('State updated')">Info: State Updated</button>
</div>
<div class="log-container">
<h3>Local Log (not sent to terminal)</h3>
<div id="log-output"></div>
</div>
<script>
// Check server status
async function checkServerStatus() {
try {
const response = await fetch('http://localhost:3001/api/test');
const data = await response.json();
document.getElementById('status').innerHTML = 'Server Status: <strong>Connected</strong> - ' + data.message;
document.getElementById('status').style.backgroundColor = '#e8f5e9';
} catch (error) {
document.getElementById('status').innerHTML = 'Server Status: <strong>Disconnected</strong> - Cannot connect to logging server';
document.getElementById('status').style.backgroundColor = '#ffebee';
}
}
// Log to terminal
async function logToTerminal(type, message, details = {}) {
try {
const response = await fetch('http://localhost:3001/api/log', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
type,
message,
details: {
...details,
timestamp: new Date().toISOString(),
source: 'test-logging.html'
}
}),
});
const data = await response.json();
// Add to local log
const logOutput = document.getElementById('log-output');
const logEntry = document.createElement('div');
logEntry.className = 'log-entry';
logEntry.innerHTML = `
<strong>[${type.toUpperCase()}]</strong> ${message}
<br>
<small>Sent to terminal: ${data.success ? 'Success' : 'Failed'}</small>
`;
logOutput.prepend(logEntry);
return data.success;
} catch (error) {
console.error('Error sending log to terminal:', error);
// Add to local log
const logOutput = document.getElementById('log-output');
const logEntry = document.createElement('div');
logEntry.className = 'log-entry';
logEntry.innerHTML = `
<strong>[ERROR]</strong> Failed to send log to terminal
<br>
<small>Error: ${error.message}</small>
`;
logOutput.prepend(logEntry);
return false;
}
}
// Log navigation
function logNavigation(from, to) {
logToTerminal('navigation', `Navigation from "${from}" to "${to}"`, { from, to });
}
// Log click
function logClick(elementId, elementType) {
logToTerminal('click', `Click on ${elementType}: "${elementId}"`, { elementId, elementType });
}
// Log warning
function logWarning(message) {
logToTerminal('warning', message);
}
// Log error
function logError(message) {
logToTerminal('error', message);
}
// Log info
function logInfo(message) {
logToTerminal('info', message);
}
// Check server status on load
window.onload = checkServerStatus;
</script>
</body>
</html>