@mks2508/better-logger 0.0.1 ā 0.0.2-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +10 -1
- package/.github/workflows/ci.yml +319 -0
- package/.github/workflows/release.yml +269 -0
- package/.npmrc.bak +1 -0
- package/README.md +577 -0
- package/demo.html +840 -0
- package/dist/chunks/Logger-BQhMKy_T.js +2 -0
- package/dist/chunks/Logger-BQhMKy_T.js.map +1 -0
- package/dist/chunks/Logger-BrFKFZcD.js +978 -0
- package/dist/chunks/Logger-BrFKFZcD.js.map +1 -0
- package/dist/chunks/core-2opW4Pi3.js +194 -0
- package/dist/chunks/core-2opW4Pi3.js.map +1 -0
- package/dist/chunks/core-DyugwSYZ.js +4 -0
- package/dist/chunks/core-DyugwSYZ.js.map +1 -0
- package/dist/chunks/exports-BNP3R7dp.js +421 -0
- package/dist/chunks/exports-BNP3R7dp.js.map +1 -0
- package/dist/chunks/exports-U1xLBXrY.js +2 -0
- package/dist/chunks/exports-U1xLBXrY.js.map +1 -0
- package/dist/chunks/styling-DhUDzwlE.js +654 -0
- package/dist/chunks/styling-DhUDzwlE.js.map +1 -0
- package/dist/chunks/styling-tmRDI28D.js +2 -0
- package/dist/chunks/styling-tmRDI28D.js.map +1 -0
- package/dist/core.cjs +2 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.js +244 -0
- package/dist/core.js.map +1 -0
- package/dist/exports.cjs +2 -0
- package/dist/exports.cjs.map +1 -0
- package/dist/exports.js +237 -0
- package/dist/exports.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +105 -0
- package/dist/index.js.map +1 -0
- package/dist/styling.cjs +2 -0
- package/dist/styling.cjs.map +1 -0
- package/dist/styling.js +146 -0
- package/dist/styling.js.map +1 -0
- package/dist/types/core.d.ts +211 -0
- package/dist/types/exports.d.ts +600 -0
- package/dist/types/index.d.ts +675 -0
- package/dist/types/styling.d.ts +751 -0
- package/docs/CORE.md +264 -0
- package/docs/EXPORTS.md +467 -0
- package/docs/STYLING.md +405 -0
- package/index.html +28 -4
- package/package.json +37 -4
- package/src/Logger.ts +28 -8
- package/src/cli/CommandProcessor.ts +2 -2
- package/src/cli/commands/ExportCommand.ts +5 -0
- package/src/cli/commands/StatusCommand.ts +11 -10
- package/src/core.ts +320 -0
- package/src/example.ts +184 -62
- package/src/exports-module.ts +311 -0
- package/src/handlers/ExportLogHandler.ts +34 -13
- package/src/index.ts +97 -79
- package/src/main.ts +77 -7
- package/src/styling-module.ts +244 -0
- package/src/utils/stackTrace.ts +39 -10
- package/src/utils/timestamps.ts +1 -1
- package/tsconfig.json +40 -14
- package/vite.config.ts +84 -0
- package/dist/assets/index-DxvJByYN.js +0 -183
- package/dist/index.html +0 -334
package/src/core.ts
ADDED
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Core Logger Module - Minimal logging without advanced features
|
|
3
|
+
* @version 0.0.1
|
|
4
|
+
*
|
|
5
|
+
* This module provides the essential logging functionality without visual enhancements,
|
|
6
|
+
* SVG support, or advanced styling. Perfect for lightweight applications or server-side usage.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// Core types
|
|
10
|
+
import type {
|
|
11
|
+
LogLevel,
|
|
12
|
+
Verbosity,
|
|
13
|
+
LoggerConfig,
|
|
14
|
+
ILogHandler,
|
|
15
|
+
LogMetadata,
|
|
16
|
+
TimerEntry
|
|
17
|
+
} from './types/index.js';
|
|
18
|
+
|
|
19
|
+
// Core utilities only
|
|
20
|
+
import {
|
|
21
|
+
parseStackTrace,
|
|
22
|
+
formatTimestamp
|
|
23
|
+
} from './utils/index.js';
|
|
24
|
+
|
|
25
|
+
// Minimal constants
|
|
26
|
+
import { DEFAULT_CONFIG } from './constants.js';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Minimal Logger class with core functionality only
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* import { CoreLogger } from '@mks2508/better-logger/core';
|
|
34
|
+
*
|
|
35
|
+
* const logger = new CoreLogger();
|
|
36
|
+
* logger.info('Hello world');
|
|
37
|
+
* logger.error('Something went wrong', error);
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export class CoreLogger {
|
|
41
|
+
private config: LoggerConfig;
|
|
42
|
+
private scopedPrefix?: string;
|
|
43
|
+
private handlers: ILogHandler[] = [];
|
|
44
|
+
private timers: Map<string, TimerEntry> = new Map();
|
|
45
|
+
private groupDepth: number = 0;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Creates a new CoreLogger instance
|
|
49
|
+
* @param config - Optional configuration
|
|
50
|
+
*/
|
|
51
|
+
constructor(config: Partial<LoggerConfig> = {}) {
|
|
52
|
+
this.config = {
|
|
53
|
+
...DEFAULT_CONFIG,
|
|
54
|
+
...config,
|
|
55
|
+
// Force disable advanced features for core module
|
|
56
|
+
enableColors: false,
|
|
57
|
+
enableTimestamps: config.enableTimestamps ?? true,
|
|
58
|
+
enableStackTrace: config.enableStackTrace ?? false,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// ===== CONFIGURATION METHODS =====
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Get current configuration
|
|
66
|
+
*/
|
|
67
|
+
getConfig(): LoggerConfig {
|
|
68
|
+
return { ...this.config };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Sets the global prefix for all log messages
|
|
73
|
+
*/
|
|
74
|
+
setGlobalPrefix(prefix: string): void {
|
|
75
|
+
this.config.globalPrefix = prefix;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Sets the verbosity level for filtering log output
|
|
80
|
+
*/
|
|
81
|
+
setVerbosity(level: Verbosity): void {
|
|
82
|
+
this.config.verbosity = level;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Creates a scoped logger with a specific prefix
|
|
87
|
+
*/
|
|
88
|
+
createScopedLogger(prefix: string): CoreLogger {
|
|
89
|
+
const scopedLogger = new CoreLogger(this.config);
|
|
90
|
+
scopedLogger.scopedPrefix = prefix;
|
|
91
|
+
scopedLogger.handlers = [...this.handlers];
|
|
92
|
+
return scopedLogger;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Adds a custom log handler for extensibility
|
|
97
|
+
*/
|
|
98
|
+
addHandler(handler: ILogHandler): void {
|
|
99
|
+
this.handlers.push(handler);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// ===== CORE LOGGING METHODS =====
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Checks if a log level should be output based on current verbosity
|
|
106
|
+
*/
|
|
107
|
+
private shouldLog(level: LogLevel): boolean {
|
|
108
|
+
if (this.config.verbosity === 'silent') return false;
|
|
109
|
+
const levels = { debug: 0, info: 1, warn: 2, error: 3, critical: 4 };
|
|
110
|
+
return levels[level] >= levels[this.config.verbosity];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Gets the effective prefix (global + scoped)
|
|
115
|
+
*/
|
|
116
|
+
private getEffectivePrefix(): string | undefined {
|
|
117
|
+
const parts = [this.config.globalPrefix, this.scopedPrefix].filter(Boolean);
|
|
118
|
+
return parts.length > 0 ? parts.join(':') : undefined;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Core logging method with minimal formatting
|
|
123
|
+
*/
|
|
124
|
+
private log(level: LogLevel, ...args: any[]): void {
|
|
125
|
+
if (!this.shouldLog(level)) return;
|
|
126
|
+
|
|
127
|
+
const prefix = this.getEffectivePrefix();
|
|
128
|
+
const timestamp = this.config.enableTimestamps ? formatTimestamp() : null;
|
|
129
|
+
const stackInfo = this.config.enableStackTrace ? parseStackTrace() : null;
|
|
130
|
+
|
|
131
|
+
// Simple formatting without CSS styling
|
|
132
|
+
const parts: string[] = [];
|
|
133
|
+
|
|
134
|
+
if (timestamp) {
|
|
135
|
+
parts.push(`[${timestamp.slice(11, 23)}]`);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
parts.push(`[${level.toUpperCase()}]`);
|
|
139
|
+
|
|
140
|
+
if (prefix) {
|
|
141
|
+
parts.push(`[${prefix}]`);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const groupIndent = ' '.repeat(this.groupDepth);
|
|
145
|
+
const logPrefix = groupIndent + parts.join(' ');
|
|
146
|
+
|
|
147
|
+
// Output to console with simple formatting
|
|
148
|
+
console.log(logPrefix, ...args);
|
|
149
|
+
|
|
150
|
+
if (stackInfo && this.config.enableStackTrace) {
|
|
151
|
+
console.log(` at ${stackInfo.file}:${stackInfo.line}:${stackInfo.column}`);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Call custom handlers
|
|
155
|
+
const metadata: LogMetadata = {
|
|
156
|
+
timestamp: timestamp || formatTimestamp(),
|
|
157
|
+
level,
|
|
158
|
+
prefix,
|
|
159
|
+
stackInfo: stackInfo || undefined,
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
this.handlers.forEach(handler => {
|
|
163
|
+
try {
|
|
164
|
+
handler.handle(level, String(args[0] || ''), args, metadata);
|
|
165
|
+
} catch (error) {
|
|
166
|
+
console.error('Log handler failed:', error);
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Logs debug information (lowest priority)
|
|
173
|
+
*/
|
|
174
|
+
debug(...args: any[]): void {
|
|
175
|
+
this.log('debug', ...args);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Logs informational messages
|
|
180
|
+
*/
|
|
181
|
+
info(...args: any[]): void {
|
|
182
|
+
this.log('info', ...args);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Logs warning messages
|
|
187
|
+
*/
|
|
188
|
+
warn(...args: any[]): void {
|
|
189
|
+
this.log('warn', ...args);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Logs error messages
|
|
194
|
+
*/
|
|
195
|
+
error(...args: any[]): void {
|
|
196
|
+
this.log('error', ...args);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Logs critical errors (highest priority)
|
|
201
|
+
*/
|
|
202
|
+
critical(...args: any[]): void {
|
|
203
|
+
this.log('critical', ...args);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Logs trace information (detailed debugging)
|
|
208
|
+
*/
|
|
209
|
+
trace(...args: any[]): void {
|
|
210
|
+
this.log('debug', ...args);
|
|
211
|
+
if (this.shouldLog('debug')) {
|
|
212
|
+
console.trace(...args);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// ===== BASIC ADVANCED FEATURES =====
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Displays data in a table format
|
|
220
|
+
*/
|
|
221
|
+
table(data: any, columns?: string[]): void {
|
|
222
|
+
if (!this.shouldLog('info')) return;
|
|
223
|
+
|
|
224
|
+
const prefix = this.getEffectivePrefix();
|
|
225
|
+
console.log(`[TABLE]${prefix ? ` [${prefix}]` : ''}:`);
|
|
226
|
+
|
|
227
|
+
if (columns) {
|
|
228
|
+
console.table(data, columns);
|
|
229
|
+
} else {
|
|
230
|
+
console.table(data);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Starts a collapsible group in the console
|
|
236
|
+
*/
|
|
237
|
+
group(label: string, collapsed: boolean = false): void {
|
|
238
|
+
const prefix = this.getEffectivePrefix();
|
|
239
|
+
const fullLabel = `${prefix ? `[${prefix}] ` : ''}${label}`;
|
|
240
|
+
|
|
241
|
+
if (collapsed) {
|
|
242
|
+
console.groupCollapsed(fullLabel);
|
|
243
|
+
} else {
|
|
244
|
+
console.group(fullLabel);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
this.groupDepth++;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Ends the current console group
|
|
252
|
+
*/
|
|
253
|
+
groupEnd(): void {
|
|
254
|
+
if (this.groupDepth > 0) {
|
|
255
|
+
console.groupEnd();
|
|
256
|
+
this.groupDepth--;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Starts a timer with the given label
|
|
262
|
+
*/
|
|
263
|
+
time(label: string): void {
|
|
264
|
+
const timer: TimerEntry = {
|
|
265
|
+
label,
|
|
266
|
+
startTime: performance.now(),
|
|
267
|
+
};
|
|
268
|
+
this.timers.set(label, timer);
|
|
269
|
+
console.log(`[TIMER] Started: ${label}`);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Ends a timer and logs the elapsed time
|
|
274
|
+
*/
|
|
275
|
+
timeEnd(label: string): void {
|
|
276
|
+
const timer = this.timers.get(label);
|
|
277
|
+
if (!timer) {
|
|
278
|
+
this.warn(`Timer '${label}' does not exist`);
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const elapsed = performance.now() - timer.startTime;
|
|
283
|
+
this.timers.delete(label);
|
|
284
|
+
console.log(`[TIMER] ${label}: ${elapsed.toFixed(2)}ms`);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// Create and export singleton instance for convenience
|
|
289
|
+
const coreLogger = new CoreLogger();
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Export individual methods for convenience (with proper binding)
|
|
293
|
+
*/
|
|
294
|
+
export const debug = (...args: any[]) => coreLogger.debug(...args);
|
|
295
|
+
export const info = (...args: any[]) => coreLogger.info(...args);
|
|
296
|
+
export const warn = (...args: any[]) => coreLogger.warn(...args);
|
|
297
|
+
export const error = (...args: any[]) => coreLogger.error(...args);
|
|
298
|
+
export const critical = (...args: any[]) => coreLogger.critical(...args);
|
|
299
|
+
export const trace = (...args: any[]) => coreLogger.trace(...args);
|
|
300
|
+
export const table = (data: any, columns?: string[]) => coreLogger.table(data, columns);
|
|
301
|
+
export const group = (label: string, collapsed?: boolean) => coreLogger.group(label, collapsed);
|
|
302
|
+
export const groupEnd = () => coreLogger.groupEnd();
|
|
303
|
+
export const time = (label: string) => coreLogger.time(label);
|
|
304
|
+
export const timeEnd = (label: string) => coreLogger.timeEnd(label);
|
|
305
|
+
export const setGlobalPrefix = (prefix: string) => coreLogger.setGlobalPrefix(prefix);
|
|
306
|
+
export const createScopedLogger = (prefix: string) => coreLogger.createScopedLogger(prefix);
|
|
307
|
+
export const setVerbosity = (level: Verbosity) => coreLogger.setVerbosity(level);
|
|
308
|
+
export const addHandler = (handler: ILogHandler) => coreLogger.addHandler(handler);
|
|
309
|
+
|
|
310
|
+
// Export the singleton as default
|
|
311
|
+
export default coreLogger;
|
|
312
|
+
|
|
313
|
+
// Re-export core types
|
|
314
|
+
export type {
|
|
315
|
+
LogLevel,
|
|
316
|
+
Verbosity,
|
|
317
|
+
LoggerConfig,
|
|
318
|
+
ILogHandler,
|
|
319
|
+
LogMetadata
|
|
320
|
+
} from './types/index.js';
|
package/src/example.ts
CHANGED
|
@@ -1,88 +1,210 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @fileoverview
|
|
2
|
+
* @fileoverview Comprehensive examples and demonstrations of Better Logger
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import logger, {
|
|
6
|
+
Logger,
|
|
6
7
|
debug,
|
|
7
8
|
info,
|
|
8
9
|
warn,
|
|
9
10
|
error,
|
|
10
11
|
success,
|
|
12
|
+
critical,
|
|
11
13
|
createScopedLogger,
|
|
12
14
|
setGlobalPrefix,
|
|
13
15
|
setVerbosity,
|
|
16
|
+
setTheme,
|
|
17
|
+
setBannerType,
|
|
18
|
+
showBanner,
|
|
19
|
+
logWithSVG,
|
|
20
|
+
logAnimated,
|
|
21
|
+
cli,
|
|
22
|
+
createStyle,
|
|
23
|
+
stylePresets,
|
|
14
24
|
FileLogHandler,
|
|
15
25
|
AnalyticsLogHandler
|
|
16
|
-
} from './
|
|
17
|
-
import { StyleBuilder } from './styling/index.js';
|
|
26
|
+
} from './index.js';
|
|
18
27
|
|
|
19
|
-
//
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
// Visual features demonstrations
|
|
29
|
+
export function demonstrateBanners() {
|
|
30
|
+
info('šØ Banner System Demo');
|
|
31
|
+
|
|
32
|
+
showBanner('simple');
|
|
33
|
+
setTimeout(() => showBanner('ascii'), 1000);
|
|
34
|
+
setTimeout(() => showBanner('unicode'), 2000);
|
|
35
|
+
setTimeout(() => showBanner('svg'), 3000);
|
|
36
|
+
setTimeout(() => showBanner('animated'), 4000);
|
|
37
|
+
}
|
|
24
38
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
39
|
+
export function demonstrateThemes() {
|
|
40
|
+
info('š Theme System Demo');
|
|
41
|
+
|
|
42
|
+
const themes = ['default', 'dark', 'neon', 'cyberpunk', 'retro'];
|
|
43
|
+
themes.forEach((theme, index) => {
|
|
44
|
+
setTimeout(() => {
|
|
45
|
+
setTheme(theme as any);
|
|
46
|
+
info(`Theme switched to: ${theme}`);
|
|
47
|
+
}, index * 1500);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
28
50
|
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
51
|
+
export function demonstrateSVG() {
|
|
52
|
+
const logoSVG = `<svg width="100" height="50" viewBox="0 0 100 50">
|
|
53
|
+
<rect width="100" height="50" fill="#667eea"/>
|
|
54
|
+
<text x="50" y="30" font-family="Arial" font-size="12" fill="white" text-anchor="middle">LOGO</text>
|
|
55
|
+
</svg>`;
|
|
56
|
+
|
|
57
|
+
logWithSVG('š¼ļø Custom SVG Background', logoSVG, {
|
|
58
|
+
width: 300,
|
|
59
|
+
height: 60,
|
|
60
|
+
padding: '20px 100px'
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function demonstrateAnimations() {
|
|
65
|
+
logAnimated('⨠Loading animation...', 3);
|
|
66
|
+
setTimeout(() => logAnimated('š Animation complete!', 2), 3500);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function demonstrateCLI() {
|
|
70
|
+
info('š» CLI Commands Demo');
|
|
71
|
+
|
|
72
|
+
const commands = [
|
|
73
|
+
'/config theme:neon',
|
|
74
|
+
'/banner ascii',
|
|
75
|
+
'/verbose debug',
|
|
76
|
+
'/prefix DEMO'
|
|
77
|
+
];
|
|
78
|
+
|
|
79
|
+
commands.forEach((cmd, index) => {
|
|
80
|
+
setTimeout(() => {
|
|
81
|
+
info(`Executing: ${cmd}`);
|
|
82
|
+
cli(cmd);
|
|
83
|
+
}, index * 1500);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function demonstrateExports() {
|
|
88
|
+
info('š¤ Export functionality would be demonstrated here');
|
|
89
|
+
info('Note: Export features require ExportLogger from /exports module');
|
|
90
|
+
|
|
91
|
+
const sampleData = [
|
|
92
|
+
{ timestamp: new Date().toISOString(), level: 'info', message: 'Sample log 1' },
|
|
93
|
+
{ timestamp: new Date().toISOString(), level: 'error', message: 'Sample log 2' },
|
|
94
|
+
{ timestamp: new Date().toISOString(), level: 'warn', message: 'Sample log 3' }
|
|
95
|
+
];
|
|
96
|
+
|
|
97
|
+
logger.table(sampleData, ['timestamp', 'level', 'message']);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Core features demonstrations
|
|
101
|
+
export function demonstrateBasicLogging() {
|
|
102
|
+
setGlobalPrefix('DEMO');
|
|
103
|
+
setVerbosity('debug');
|
|
32
104
|
|
|
33
|
-
|
|
34
|
-
info('
|
|
35
|
-
debug('Debug information', { config: { mode: 'development' } });
|
|
105
|
+
debug('š Debug information', { config: { mode: 'development' } });
|
|
106
|
+
info('ā¹ļø Application started successfully');
|
|
36
107
|
warn('ā ļø This is a warning message');
|
|
37
108
|
error('ā An error occurred', new Error('Sample error'));
|
|
38
109
|
success('ā
User authentication successful');
|
|
110
|
+
critical('š„ Critical system failure detected');
|
|
111
|
+
}
|
|
39
112
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
Logger.group('User Session Details');
|
|
46
|
-
apiLogger.table([
|
|
47
|
-
{ id: 1, name: 'John Doe', email: 'john@example.com' },
|
|
48
|
-
{ id: 2, name: 'Jane Smith', email: 'jane@example.com' }
|
|
49
|
-
]);
|
|
50
|
-
Logger.groupEnd();
|
|
51
|
-
|
|
52
|
-
// Performance timing
|
|
53
|
-
Logger.time('data-processing');
|
|
54
|
-
// Simulate some processing
|
|
55
|
-
setTimeout(() => {
|
|
56
|
-
Logger.timeEnd('data-processing');
|
|
57
|
-
}, 100);
|
|
58
|
-
|
|
59
|
-
// Critical error with stack trace
|
|
60
|
-
Logger.critical('š„ Critical system failure detected');
|
|
61
|
-
|
|
62
|
-
// Custom styled logging
|
|
63
|
-
console.log(
|
|
64
|
-
'%cCustom Styled Message',
|
|
65
|
-
new StyleBuilder()
|
|
66
|
-
.bg('linear-gradient(45deg, #ff6b6b, #feca57)')
|
|
67
|
-
.color('#ffffff')
|
|
68
|
-
.padding('10px 15px')
|
|
69
|
-
.rounded('8px')
|
|
70
|
-
.shadow('0 4px 8px rgba(0,0,0,0.2)')
|
|
71
|
-
.bold()
|
|
72
|
-
.build()
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
// Grouped logging with data
|
|
76
|
-
const users = [
|
|
77
|
-
{ name: 'Alice', role: 'admin' },
|
|
78
|
-
{ name: 'Bob', role: 'user' },
|
|
79
|
-
{ name: 'Charlie', role: 'admin' }
|
|
113
|
+
export function demonstrateTable() {
|
|
114
|
+
const userData = [
|
|
115
|
+
{ id: 1, name: 'John Doe', email: 'john@example.com', status: 'active' },
|
|
116
|
+
{ id: 2, name: 'Jane Smith', email: 'jane@example.com', status: 'inactive' },
|
|
117
|
+
{ id: 3, name: 'Bob Johnson', email: 'bob@example.com', status: 'active' }
|
|
80
118
|
];
|
|
119
|
+
|
|
120
|
+
logger.table(userData);
|
|
121
|
+
logger.table(userData, ['name', 'email']);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function demonstrateGrouping() {
|
|
125
|
+
logger.group('š User Analysis');
|
|
126
|
+
info('Analyzing user data...');
|
|
127
|
+
|
|
128
|
+
logger.group('š Statistics', false);
|
|
129
|
+
info('Total users: 150');
|
|
130
|
+
info('Active users: 120');
|
|
131
|
+
info('New this month: 25');
|
|
132
|
+
logger.groupEnd();
|
|
133
|
+
|
|
134
|
+
logger.group('šÆ Top Users');
|
|
135
|
+
success('Premium user: Alice Johnson');
|
|
136
|
+
success('Most active: Bob Smith');
|
|
137
|
+
logger.groupEnd();
|
|
138
|
+
|
|
139
|
+
logger.groupEnd();
|
|
140
|
+
}
|
|
81
141
|
|
|
82
|
-
|
|
142
|
+
export function demonstrateTiming() {
|
|
143
|
+
logger.time('api-request');
|
|
144
|
+
|
|
145
|
+
info('š Making API request...');
|
|
146
|
+
|
|
147
|
+
setTimeout(() => {
|
|
148
|
+
logger.timeEnd('api-request');
|
|
149
|
+
success('ā
API request completed');
|
|
150
|
+
}, Math.random() * 2000 + 500);
|
|
83
151
|
}
|
|
84
152
|
|
|
85
|
-
|
|
86
|
-
|
|
153
|
+
export function demonstrateScopedLogger() {
|
|
154
|
+
const apiLogger = createScopedLogger('API');
|
|
155
|
+
const dbLogger = createScopedLogger('DB');
|
|
156
|
+
const authLogger = createScopedLogger('AUTH');
|
|
157
|
+
|
|
158
|
+
apiLogger.info('š Fetching user data', { endpoint: '/api/users' });
|
|
159
|
+
dbLogger.debug('š¾ Database query executed', { query: 'SELECT * FROM users LIMIT 10' });
|
|
160
|
+
authLogger.success('š User authentication successful', { userId: 12345 });
|
|
161
|
+
|
|
162
|
+
apiLogger.warn('ā ļø Rate limit approaching', { remaining: 10 });
|
|
163
|
+
dbLogger.error('ā Connection timeout', { timeout: '5s' });
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function demonstrateTrace() {
|
|
167
|
+
function deepFunction() {
|
|
168
|
+
function deeperFunction() {
|
|
169
|
+
logger.trace('š Deep trace call with full stack');
|
|
170
|
+
}
|
|
171
|
+
deeperFunction();
|
|
172
|
+
}
|
|
173
|
+
deepFunction();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function demonstrateCustomStyles() {
|
|
177
|
+
const customStyle = createStyle()
|
|
178
|
+
.bg('linear-gradient(135deg, #ff6b6b 0%, #feca57 100%)')
|
|
179
|
+
.color('white')
|
|
180
|
+
.padding('12px 20px')
|
|
181
|
+
.rounded('10px')
|
|
182
|
+
.shadow('0 4px 15px rgba(0,0,0,0.3)')
|
|
183
|
+
.bold()
|
|
184
|
+
.build();
|
|
185
|
+
|
|
186
|
+
console.log('%cšØ Custom Styled Message', customStyle);
|
|
187
|
+
console.log('%cā
Success Style', stylePresets.success);
|
|
188
|
+
console.log('%cā Error Style', stylePresets.error);
|
|
189
|
+
console.log('%cā ļø Warning Style', stylePresets.warning);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// Comprehensive demonstration
|
|
193
|
+
export function demonstrateAllFeatures() {
|
|
194
|
+
info('š Starting comprehensive Better Logger demonstration...');
|
|
195
|
+
|
|
196
|
+
setTimeout(() => demonstrateBanners(), 500);
|
|
197
|
+
setTimeout(() => demonstrateBasicLogging(), 6000);
|
|
198
|
+
setTimeout(() => demonstrateCustomStyles(), 8000);
|
|
199
|
+
setTimeout(() => demonstrateGrouping(), 10000);
|
|
200
|
+
setTimeout(() => demonstrateTiming(), 13000);
|
|
201
|
+
setTimeout(() => demonstrateScopedLogger(), 16000);
|
|
202
|
+
setTimeout(() => demonstrateThemes(), 18000);
|
|
203
|
+
|
|
204
|
+
setTimeout(() => {
|
|
205
|
+
success('š Demonstration complete! Check your console for all the styled outputs.');
|
|
206
|
+
}, 25000);
|
|
207
|
+
}
|
|
87
208
|
|
|
88
|
-
|
|
209
|
+
// Auto-run basic demo on import
|
|
210
|
+
demonstrateBasicLogging();
|