-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic-usage.html
More file actions
247 lines (207 loc) · 6.45 KB
/
basic-usage.html
File metadata and controls
247 lines (207 loc) · 6.45 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Happy Web Logger - Basic Usage</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
max-width: 800px;
margin: 50px auto;
padding: 20px;
background: #f5f5f5;
}
.container {
background: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
h1 {
color: #333;
border-bottom: 3px solid #4CAF50;
padding-bottom: 10px;
}
button {
background: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
margin: 5px;
border-radius: 5px;
cursor: pointer;
font-size: 14px;
}
button:hover {
background: #45a049;
}
.button-group {
margin: 20px 0;
}
.info {
background: #e3f2fd;
padding: 15px;
border-left: 4px solid #2196F3;
margin: 20px 0;
}
pre {
background: #263238;
color: #aed581;
padding: 15px;
border-radius: 5px;
overflow-x: auto;
}
</style>
</head>
<body>
<div class="container">
<h1>🎯 Happy Web Logger - Basic Usage</h1>
<div class="info">
<strong>Instructions:</strong> Click the buttons below to test different logging features.
Open your browser's console to see the logs.
</div>
<div class="button-group">
<h3>Basic Logging</h3>
<button onclick="testDebug()">Debug Log</button>
<button onclick="testInfo()">Info Log</button>
<button onclick="testWarn()">Warning Log</button>
<button onclick="testError()">Error Log</button>
</div>
<div class="button-group">
<h3>Console Override</h3>
<button onclick="testConsoleLog()">Console.log</button>
<button onclick="testConsoleError()">Console.error</button>
</div>
<div class="button-group">
<h3>Advanced</h3>
<button onclick="testComplexObject()">Log Complex Object</button>
<button onclick="testHighVolume()">High Volume (1000 logs)</button>
<button onclick="testFlush()">Manual Flush</button>
</div>
<div class="button-group">
<h3>Configuration</h3>
<button onclick="switchToImmediate()">Immediate Mode</button>
<button onclick="switchToBatched()">Batched Mode</button>
<button onclick="switchToAdaptive()">Adaptive Mode</button>
</div>
<h3>Example Code</h3>
<pre><code>// Initialize the logger
import HappyLogger from '@bernardbaker/happy-web-logger';
const logger = HappyLogger.getInstance({
bufferMode: 'adaptive',
enableConsoleOverride: true,
logLevel: 'debug',
colors: {
debug: '#9e9e9e', // Gray
info: '#2196F3', // Blue
warn: '#FF9800', // Orange
error: '#F44336', // Red
log: '#4CAF50', // Green
},
});
// Use it!
logger.info('Hello, Happy Web Logger!');
console.log('This is intercepted too!');</code></pre>
</div>
<!-- In a real app, you would import from the built package -->
<script type="module">
// Simulated logger for demo purposes
// In production, import from: import HappyLogger from '@bernardbaker/happy-web-logger';
class MockHappyLogger {
constructor(config = {}) {
this.config = config;
console.log('Happy Web Logger initialized with config:', config);
}
debug(msg, ...args) {
console.log(`[DEBUG] ${msg}`, ...args);
}
info(msg, ...args) {
console.log(`[INFO] ${msg}`, ...args);
}
warn(msg, ...args) {
console.warn(`[WARN] ${msg}`, ...args);
}
error(msg, ...args) {
console.error(`[ERROR] ${msg}`, ...args);
}
configure(config) {
Object.assign(this.config, config);
console.log('Configuration updated:', this.config);
}
flush() {
console.log('Buffer flushed!');
}
}
// Initialize logger
window.logger = new MockHappyLogger({
bufferMode: 'adaptive',
enableConsoleOverride: true,
logLevel: 'debug', // Default - captures all log levels
colors: {
debug: '#9e9e9e',
info: '#2196F3',
warn: '#FF9800',
error: '#F44336',
log: '#4CAF50',
},
});
// Test functions
window.testDebug = function () {
logger.debug('This is a debug message', { detail: 'extra info' });
};
window.testInfo = function () {
logger.info('Application event occurred', { userId: 123, action: 'login' });
};
window.testWarn = function () {
logger.warn('Deprecation warning: Old API will be removed', { version: '2.0.0' });
};
window.testError = function () {
logger.error('An error occurred', new Error('Something went wrong'));
};
window.testConsoleLog = function () {
console.log('Regular console.log - intercepted by Happy Web Logger!');
};
window.testConsoleError = function () {
console.error('Console error - intercepted and enhanced!');
};
window.testComplexObject = function () {
const complexObj = {
user: { id: 1, name: 'John Doe', email: 'john@example.com' },
settings: { theme: 'dark', notifications: true },
metadata: { timestamp: Date.now(), version: '1.0.0' },
};
logger.info('Logging complex object', complexObj);
};
window.testHighVolume = function () {
console.time('1000 logs');
for (let i = 0; i < 1000; i++) {
logger.info(`Log message ${i}`, { iteration: i });
}
console.timeEnd('1000 logs');
alert('1000 logs sent! Check console for timing.');
};
window.testFlush = function () {
logger.info('Message 1');
logger.info('Message 2');
logger.info('Message 3');
logger.flush();
alert('Buffer flushed! All pending logs sent to worker.');
};
window.switchToImmediate = function () {
logger.configure({ bufferMode: 'immediate' });
alert('Switched to IMMEDIATE mode');
};
window.switchToBatched = function () {
logger.configure({ bufferMode: 'batched', batchSize: 10 });
alert('Switched to BATCHED mode (batch size: 10)');
};
window.switchToAdaptive = function () {
logger.configure({ bufferMode: 'adaptive' });
alert('Switched to ADAPTIVE mode (errors immediate, others batched)');
};
// Log initialization
logger.info('Happy Web Logger demo page loaded!');
</script>
</body>
</html>