@mks2508/better-logger 0.0.2-alpha.2 → 0.8.1-alpha.1
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/.github/workflows/ci-quality.yml +356 -0
- package/.github/workflows/docs-demo.yml +123 -0
- package/.github/workflows/releases-core.yml +448 -0
- package/.github/workflows/releases-full.yml +404 -0
- package/.github/{workflows → workflows-backup}/ci.yml +12 -110
- package/.github/workflows-backup/nightly.yml +196 -0
- package/.github/workflows-backup/release-optimized.yml +373 -0
- package/.release-notes-0.2.0.md +129 -0
- package/CHANGELOG.json +658 -0
- package/README.md +110 -512
- package/demo.html +9 -2
- package/dist/Logger.d.ts +176 -0
- package/dist/Logger.d.ts.map +1 -0
- package/dist/Logger.js +498 -0
- package/dist/chunks/{Logger-BrFKFZcD.js → Logger-CbCUS5pQ.js} +987 -5
- package/dist/chunks/Logger-CbCUS5pQ.js.map +1 -0
- package/dist/chunks/Logger-PCfgYKTP.js +2 -0
- package/dist/chunks/Logger-PCfgYKTP.js.map +1 -0
- package/dist/chunks/RemoteLogHandler-CjWpWZGl.js +33 -0
- package/dist/chunks/RemoteLogHandler-CjWpWZGl.js.map +1 -0
- package/dist/chunks/RemoteLogHandler-ymkQ97xl.js +2 -0
- package/dist/chunks/RemoteLogHandler-ymkQ97xl.js.map +1 -0
- package/dist/chunks/StyleBuilder-BoJTmskd.js +361 -0
- package/dist/chunks/StyleBuilder-BoJTmskd.js.map +1 -0
- package/dist/chunks/StyleBuilder-LPLzsoHY.js +4 -0
- package/dist/chunks/StyleBuilder-LPLzsoHY.js.map +1 -0
- package/dist/cli/CommandProcessor.d.ts +40 -0
- package/dist/cli/CommandProcessor.d.ts.map +1 -0
- package/dist/cli/CommandProcessor.js +57 -0
- package/dist/cli/commands/ConfigCommand.d.ts +17 -0
- package/dist/cli/commands/ConfigCommand.d.ts.map +1 -0
- package/dist/cli/commands/ConfigCommand.js +88 -0
- package/dist/cli/commands/ExportCommand.d.ts +51 -0
- package/dist/cli/commands/ExportCommand.d.ts.map +1 -0
- package/dist/cli/commands/ExportCommand.js +243 -0
- package/dist/cli/commands/StatusCommand.d.ts +33 -0
- package/dist/cli/commands/StatusCommand.d.ts.map +1 -0
- package/dist/cli/commands/StatusCommand.js +93 -0
- package/dist/cli/commands/ThemeCommand.d.ts +33 -0
- package/dist/cli/commands/ThemeCommand.d.ts.map +1 -0
- package/dist/cli/commands/ThemeCommand.js +79 -0
- package/dist/cli/help.d.ts +15 -0
- package/dist/cli/help.d.ts.map +1 -0
- package/dist/cli/help.js +118 -0
- package/dist/cli/index.d.ts +15 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +40 -0
- package/dist/constants.d.ts +91 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +80 -0
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +130 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +258 -242
- package/dist/core.js.map +1 -1
- package/dist/example.d.ts +18 -0
- package/dist/example.d.ts.map +1 -0
- package/dist/example.js +154 -0
- package/dist/exports-module.d.ts +203 -0
- package/dist/exports-module.d.ts.map +1 -0
- package/dist/exports-module.js +260 -0
- package/dist/exports.cjs +1 -1
- package/dist/exports.cjs.map +1 -1
- package/dist/exports.js +2 -2
- package/dist/handlers/AnalyticsLogHandler.d.ts +11 -0
- package/dist/handlers/AnalyticsLogHandler.d.ts.map +1 -0
- package/dist/handlers/AnalyticsLogHandler.js +19 -0
- package/dist/handlers/ExportLogHandler.d.ts +103 -0
- package/dist/handlers/ExportLogHandler.d.ts.map +1 -0
- package/dist/handlers/ExportLogHandler.js +516 -0
- package/dist/handlers/FileLogHandler.d.ts +13 -0
- package/dist/handlers/FileLogHandler.d.ts.map +1 -0
- package/dist/handlers/FileLogHandler.js +24 -0
- package/dist/handlers/RemoteLogHandler.d.ts +14 -0
- package/dist/handlers/RemoteLogHandler.d.ts.map +1 -0
- package/dist/handlers/RemoteLogHandler.js +37 -0
- package/dist/handlers/index.d.ts +8 -0
- package/dist/handlers/index.d.ts.map +1 -0
- package/dist/handlers/index.js +7 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +86 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +89 -103
- package/dist/main.d.ts +2 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +139 -0
- package/dist/styling/StyleBuilder.d.ts +132 -0
- package/dist/styling/StyleBuilder.d.ts.map +1 -0
- package/dist/styling/StyleBuilder.js +268 -0
- package/dist/styling/banners.d.ts +45 -0
- package/dist/styling/banners.d.ts.map +1 -0
- package/dist/styling/banners.js +155 -0
- package/dist/styling/index.d.ts +7 -0
- package/dist/styling/index.d.ts.map +1 -0
- package/dist/styling/index.js +6 -0
- package/dist/styling/themes.d.ts +10 -0
- package/dist/styling/themes.d.ts.map +1 -0
- package/dist/styling/themes.js +231 -0
- package/dist/styling-module.d.ts +185 -0
- package/dist/styling-module.d.ts.map +1 -0
- package/dist/styling-module.js +199 -0
- package/dist/styling.cjs +1 -1
- package/dist/styling.cjs.map +1 -1
- package/dist/styling.js +4 -4
- package/dist/types/Logger.d.ts +172 -0
- package/dist/types/Logger.d.ts.map +1 -0
- package/dist/types/cli/CommandProcessor.d.ts +37 -0
- package/dist/types/cli/CommandProcessor.d.ts.map +1 -0
- package/dist/types/cli/commands/ConfigCommand.d.ts +14 -0
- package/dist/types/cli/commands/ConfigCommand.d.ts.map +1 -0
- package/dist/types/cli/commands/ExportCommand.d.ts +48 -0
- package/dist/types/cli/commands/ExportCommand.d.ts.map +1 -0
- package/dist/types/cli/commands/StatusCommand.d.ts +30 -0
- package/dist/types/cli/commands/StatusCommand.d.ts.map +1 -0
- package/dist/types/cli/commands/ThemeCommand.d.ts +30 -0
- package/dist/types/cli/commands/ThemeCommand.d.ts.map +1 -0
- package/dist/types/cli/help.d.ts +12 -0
- package/dist/types/cli/help.d.ts.map +1 -0
- package/dist/types/cli/index.d.ts +15 -0
- package/dist/types/cli/index.d.ts.map +1 -0
- package/dist/types/constants.d.ts +88 -0
- package/dist/types/constants.d.ts.map +1 -0
- package/dist/types/core.d.ts +71 -211
- package/dist/types/core.d.ts.map +1 -0
- package/dist/types/core.js +13 -0
- package/dist/types/example.d.ts +18 -0
- package/dist/types/example.d.ts.map +1 -0
- package/dist/types/exports-module.d.ts +196 -0
- package/dist/types/exports-module.d.ts.map +1 -0
- package/dist/types/handlers/AnalyticsLogHandler.d.ts +8 -0
- package/dist/types/handlers/AnalyticsLogHandler.d.ts.map +1 -0
- package/dist/types/handlers/ExportLogHandler.d.ts +100 -0
- package/dist/types/handlers/ExportLogHandler.d.ts.map +1 -0
- package/dist/types/handlers/FileLogHandler.d.ts +10 -0
- package/dist/types/handlers/FileLogHandler.d.ts.map +1 -0
- package/dist/types/handlers/RemoteLogHandler.d.ts +11 -0
- package/dist/types/handlers/RemoteLogHandler.d.ts.map +1 -0
- package/dist/types/handlers/index.d.ts +8 -0
- package/dist/types/handlers/index.d.ts.map +1 -0
- package/dist/types/handlers.d.ts +88 -0
- package/dist/types/handlers.d.ts.map +1 -0
- package/dist/types/handlers.js +4 -0
- package/dist/types/index.d.ts +7 -675
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +4 -0
- package/dist/types/main.d.ts +2 -0
- package/dist/types/main.d.ts.map +1 -0
- package/dist/types/styling/StyleBuilder.d.ts +132 -0
- package/dist/types/styling/StyleBuilder.d.ts.map +1 -0
- package/dist/types/styling/banners.d.ts +42 -0
- package/dist/types/styling/banners.d.ts.map +1 -0
- package/dist/types/styling/index.d.ts +7 -0
- package/dist/types/styling/index.d.ts.map +1 -0
- package/dist/types/styling/themes.d.ts +7 -0
- package/dist/types/styling/themes.d.ts.map +1 -0
- package/dist/types/styling-module.d.ts +178 -0
- package/dist/types/styling-module.d.ts.map +1 -0
- package/dist/types/types/core.d.ts +71 -0
- package/dist/types/types/core.d.ts.map +1 -0
- package/dist/types/types/handlers.d.ts +85 -0
- package/dist/types/types/handlers.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +7 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +7 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/dist/types/utils/output.d.ts +29 -0
- package/dist/types/utils/output.d.ts.map +1 -0
- package/dist/types/utils/stackTrace.d.ts +6 -0
- package/dist/types/utils/stackTrace.d.ts.map +1 -0
- package/dist/types/utils/timestamps.d.ts +20 -0
- package/dist/types/utils/timestamps.d.ts.map +1 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +6 -0
- package/dist/utils/output.d.ts +32 -0
- package/dist/utils/output.d.ts.map +1 -0
- package/dist/utils/output.js +97 -0
- package/dist/utils/stackTrace.d.ts +9 -0
- package/dist/utils/stackTrace.d.ts.map +1 -0
- package/dist/utils/stackTrace.js +81 -0
- package/dist/utils/timestamps.d.ts +20 -0
- package/dist/utils/timestamps.d.ts.map +1 -0
- package/dist/utils/timestamps.js +71 -0
- package/docs/API.md +607 -0
- package/docs/DEVELOPMENT.md +731 -0
- package/docs/_config.yml +36 -0
- package/docs/index.md +179 -0
- package/examples/README.md +208 -0
- package/examples/basic-logging.js +75 -0
- package/examples/data-export.js +234 -0
- package/examples/package.json +16 -0
- package/examples/performance-timing.js +170 -0
- package/examples/styling-themes.js +207 -0
- package/package.json +24 -21
- package/packages/core/package.json +35 -0
- package/packages/exports/package.json +41 -0
- package/packages/styling/package.json +41 -0
- package/project-utils/README.md +172 -0
- package/project-utils/auto-release-gemini.ts +1193 -0
- package/project-utils/commit-generator.ts +1000 -0
- package/project-utils/commit-ui.ts +246 -0
- package/project-utils/git-utils.ts +199 -0
- package/project-utils/github-release-manager.ts +466 -0
- package/project-utils/prompt-templates.js +345 -0
- package/project-utils/prompt-templates.ts +422 -0
- package/project-utils/version-manager.ts +1078 -0
- package/src/Logger.ts +2 -1
- package/src/handlers/ExportLogHandler.ts +141 -0
- package/vite.config.ts +152 -50
- package/.claude/settings.local.json +0 -22
- package/.npmrc.bak +0 -1
- package/dist/chunks/Logger-BQhMKy_T.js +0 -2
- package/dist/chunks/Logger-BQhMKy_T.js.map +0 -1
- package/dist/chunks/Logger-BrFKFZcD.js.map +0 -1
- package/dist/chunks/core-2opW4Pi3.js +0 -194
- package/dist/chunks/core-2opW4Pi3.js.map +0 -1
- package/dist/chunks/core-DyugwSYZ.js +0 -4
- package/dist/chunks/core-DyugwSYZ.js.map +0 -1
- package/dist/chunks/exports-BNP3R7dp.js +0 -421
- package/dist/chunks/exports-BNP3R7dp.js.map +0 -1
- package/dist/chunks/exports-U1xLBXrY.js +0 -2
- package/dist/chunks/exports-U1xLBXrY.js.map +0 -1
- package/dist/chunks/styling-DhUDzwlE.js +0 -654
- package/dist/chunks/styling-DhUDzwlE.js.map +0 -1
- package/dist/chunks/styling-tmRDI28D.js +0 -2
- package/dist/chunks/styling-tmRDI28D.js.map +0 -1
- package/dist/types/exports.d.ts +0 -600
- package/dist/types/styling.d.ts +0 -751
- /package/.github/{workflows → workflows-backup}/release.yml +0 -0
package/demo.html
CHANGED
|
@@ -6,8 +6,15 @@
|
|
|
6
6
|
<title>Better Logger - Professional Console Logging</title>
|
|
7
7
|
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>📊</text></svg>">
|
|
8
8
|
|
|
9
|
-
<!-- Import Better Logger from
|
|
10
|
-
<script type="module"
|
|
9
|
+
<!-- Import Better Logger from jsDelivr CDN with local fallback -->
|
|
10
|
+
<script type="module">
|
|
11
|
+
try {
|
|
12
|
+
await import('https://cdn.jsdelivr.net/npm/@mks2508/better-logger@latest/dist/index.js');
|
|
13
|
+
} catch (e) {
|
|
14
|
+
console.log('Using local fallback');
|
|
15
|
+
await import('./dist/index.js');
|
|
16
|
+
}
|
|
17
|
+
</script>
|
|
11
18
|
|
|
12
19
|
<style>
|
|
13
20
|
* {
|
package/dist/Logger.d.ts
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Refactored Advanced Logger with modular architecture
|
|
3
|
+
* @version 2.0.0
|
|
4
|
+
*/
|
|
5
|
+
import type { Verbosity, ThemeVariant, BannerType, LoggerConfig, ILogHandler, StyleOptions } from './types/index.js';
|
|
6
|
+
import { ExportLogHandler } from './handlers/index.js';
|
|
7
|
+
/**
|
|
8
|
+
* Main Logger class implementing state-of-the-art logging capabilities
|
|
9
|
+
*/
|
|
10
|
+
export declare class Logger {
|
|
11
|
+
private config;
|
|
12
|
+
private scopedPrefix?;
|
|
13
|
+
private handlers;
|
|
14
|
+
private timers;
|
|
15
|
+
private groupDepth;
|
|
16
|
+
private exportHandler?;
|
|
17
|
+
private cliProcessor?;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new Logger instance
|
|
20
|
+
*/
|
|
21
|
+
constructor(config?: Partial<LoggerConfig>);
|
|
22
|
+
/**
|
|
23
|
+
* Get current configuration
|
|
24
|
+
*/
|
|
25
|
+
getConfig(): LoggerConfig;
|
|
26
|
+
/**
|
|
27
|
+
* Update configuration
|
|
28
|
+
*/
|
|
29
|
+
updateConfig(updates: Partial<LoggerConfig>): void;
|
|
30
|
+
/**
|
|
31
|
+
* Sets the global prefix for all log messages
|
|
32
|
+
*/
|
|
33
|
+
setGlobalPrefix(prefix: string): void;
|
|
34
|
+
/**
|
|
35
|
+
* Sets the verbosity level for filtering log output
|
|
36
|
+
*/
|
|
37
|
+
setVerbosity(level: Verbosity): void;
|
|
38
|
+
/**
|
|
39
|
+
* Sets the logger theme
|
|
40
|
+
*/
|
|
41
|
+
setTheme(theme: ThemeVariant): void;
|
|
42
|
+
/**
|
|
43
|
+
* Set banner type for initialization display
|
|
44
|
+
*/
|
|
45
|
+
setBannerType(bannerType: BannerType): void;
|
|
46
|
+
/**
|
|
47
|
+
* Reset logger to default configuration
|
|
48
|
+
*/
|
|
49
|
+
resetConfig(): void;
|
|
50
|
+
/**
|
|
51
|
+
* Creates a scoped logger with a specific prefix
|
|
52
|
+
*/
|
|
53
|
+
createScopedLogger(prefix: string): Logger;
|
|
54
|
+
/**
|
|
55
|
+
* Adds a custom log handler for extensibility
|
|
56
|
+
*/
|
|
57
|
+
addHandler(handler: ILogHandler): void;
|
|
58
|
+
/**
|
|
59
|
+
* Get all registered handlers
|
|
60
|
+
*/
|
|
61
|
+
getHandlers(): ILogHandler[];
|
|
62
|
+
/**
|
|
63
|
+
* Get export handler if available
|
|
64
|
+
*/
|
|
65
|
+
getExportHandler(): ExportLogHandler | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Checks if a log level should be output based on current verbosity
|
|
68
|
+
*/
|
|
69
|
+
private shouldLog;
|
|
70
|
+
/**
|
|
71
|
+
* Gets the effective prefix (global + scoped)
|
|
72
|
+
*/
|
|
73
|
+
private getEffectivePrefix;
|
|
74
|
+
/**
|
|
75
|
+
* Core logging method that handles styling and formatting
|
|
76
|
+
*/
|
|
77
|
+
private log;
|
|
78
|
+
/**
|
|
79
|
+
* Logs debug information (lowest priority)
|
|
80
|
+
*/
|
|
81
|
+
debug(...args: any[]): void;
|
|
82
|
+
/**
|
|
83
|
+
* Logs informational messages
|
|
84
|
+
*/
|
|
85
|
+
info(...args: any[]): void;
|
|
86
|
+
/**
|
|
87
|
+
* Logs warning messages
|
|
88
|
+
*/
|
|
89
|
+
warn(...args: any[]): void;
|
|
90
|
+
/**
|
|
91
|
+
* Logs error messages
|
|
92
|
+
*/
|
|
93
|
+
error(...args: any[]): void;
|
|
94
|
+
/**
|
|
95
|
+
* Logs success messages (special info level)
|
|
96
|
+
*/
|
|
97
|
+
success(...args: any[]): void;
|
|
98
|
+
/**
|
|
99
|
+
* Logs trace information (detailed debugging)
|
|
100
|
+
*/
|
|
101
|
+
trace(...args: any[]): void;
|
|
102
|
+
/**
|
|
103
|
+
* Logs critical errors (highest priority)
|
|
104
|
+
*/
|
|
105
|
+
critical(...args: any[]): void;
|
|
106
|
+
/**
|
|
107
|
+
* Displays data in a table format
|
|
108
|
+
*/
|
|
109
|
+
table(data: any, columns?: string[]): void;
|
|
110
|
+
/**
|
|
111
|
+
* Starts a collapsible group in the console
|
|
112
|
+
*/
|
|
113
|
+
group(label: string, collapsed?: boolean): void;
|
|
114
|
+
/**
|
|
115
|
+
* Ends the current console group
|
|
116
|
+
*/
|
|
117
|
+
groupEnd(): void;
|
|
118
|
+
/**
|
|
119
|
+
* Starts a timer with the given label
|
|
120
|
+
*/
|
|
121
|
+
time(label: string): void;
|
|
122
|
+
/**
|
|
123
|
+
* Ends a timer and logs the elapsed time
|
|
124
|
+
*/
|
|
125
|
+
timeEnd(label: string): void;
|
|
126
|
+
/**
|
|
127
|
+
* Display banner with specified or configured type
|
|
128
|
+
*/
|
|
129
|
+
showBanner(bannerType?: BannerType): void;
|
|
130
|
+
/**
|
|
131
|
+
* Log with SVG background image
|
|
132
|
+
*/
|
|
133
|
+
logWithSVG(message: string, svgContent?: string, options?: StyleOptions): void;
|
|
134
|
+
/**
|
|
135
|
+
* Log with animated background gradient
|
|
136
|
+
*/
|
|
137
|
+
logAnimated(message: string, duration?: number): void;
|
|
138
|
+
/**
|
|
139
|
+
* Groups logs by a specific property using modern Object.groupBy (when available)
|
|
140
|
+
*/
|
|
141
|
+
logGrouped<T>(items: T[], groupBy: (item: T) => string): void;
|
|
142
|
+
/**
|
|
143
|
+
* CLI command processor for logger configuration and export
|
|
144
|
+
*/
|
|
145
|
+
cli(command: string): Promise<void>;
|
|
146
|
+
}
|
|
147
|
+
declare const defaultLogger: Logger;
|
|
148
|
+
export default defaultLogger;
|
|
149
|
+
/**
|
|
150
|
+
* Export individual methods for convenience (with proper binding)
|
|
151
|
+
*/
|
|
152
|
+
export declare const debug: (...args: any[]) => void;
|
|
153
|
+
export declare const info: (...args: any[]) => void;
|
|
154
|
+
export declare const warn: (...args: any[]) => void;
|
|
155
|
+
export declare const error: (...args: any[]) => void;
|
|
156
|
+
export declare const success: (...args: any[]) => void;
|
|
157
|
+
export declare const trace: (...args: any[]) => void;
|
|
158
|
+
export declare const critical: (...args: any[]) => void;
|
|
159
|
+
export declare const table: (data: any, columns?: string[]) => void;
|
|
160
|
+
export declare const group: (label: string, collapsed?: boolean) => void;
|
|
161
|
+
export declare const groupEnd: () => void;
|
|
162
|
+
export declare const time: (label: string) => void;
|
|
163
|
+
export declare const timeEnd: (label: string) => void;
|
|
164
|
+
export declare const setGlobalPrefix: (prefix: string) => void;
|
|
165
|
+
export declare const createScopedLogger: (prefix: string) => Logger;
|
|
166
|
+
export declare const setVerbosity: (level: Verbosity) => void;
|
|
167
|
+
export declare const addHandler: (handler: ILogHandler) => void;
|
|
168
|
+
export declare const setTheme: (theme: ThemeVariant) => void;
|
|
169
|
+
export declare const setBannerType: (bannerType: BannerType) => void;
|
|
170
|
+
export declare const showBanner: (bannerType?: BannerType) => void;
|
|
171
|
+
export declare const logWithSVG: (message: string, svgContent?: string, options?: StyleOptions) => void;
|
|
172
|
+
export declare const logAnimated: (message: string, duration?: number) => void;
|
|
173
|
+
export declare const cli: (command: string) => Promise<void>;
|
|
174
|
+
export { FileLogHandler, RemoteLogHandler, AnalyticsLogHandler, ExportLogHandler } from './handlers/index.js';
|
|
175
|
+
export { StyleBuilder, StylePresets as Styles } from './styling/index.js';
|
|
176
|
+
//# sourceMappingURL=Logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../src/Logger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAER,SAAS,EACT,YAAY,EACZ,UAAU,EACV,YAAY,EAEZ,WAAW,EAEX,YAAY,EACf,MAAM,kBAAkB,CAAC;AAmB1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAavD;;GAEG;AACH,qBAAa,MAAM;IACf,OAAO,C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AU,YAAY,SAC7B,CAAC;AAC3D,eAAO,MAAM,WAAW,GAAI,SAAS,MAAM,EAAE,WAAW,MAAM,SACd,CAAC;AACjD,eAAO,MAAM,GAAG,GAAI,SAAS,MAAM,kBAA+B,CAAC;AAGnE,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC9G,OAAO,EAAE,YAAY,EAAE,YAAY,IAAI,MAAM,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/Logger.js
ADDED
|
@@ -0,0 +1,498 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Refactored Advanced Logger with modular architecture
|
|
3
|
+
* @version 2.0.0
|
|
4
|
+
*/
|
|
5
|
+
// Utility imports
|
|
6
|
+
import { parseStackTrace, formatTimestamp, createStyledOutput } from './utils/index.js';
|
|
7
|
+
// Styling imports
|
|
8
|
+
import { THEME_PRESETS, THEME_BANNERS, displayInitBanner, StylePresets, StyleBuilder } from './styling/index.js';
|
|
9
|
+
// Handler imports
|
|
10
|
+
import { ExportLogHandler } from './handlers/index.js';
|
|
11
|
+
// CLI imports
|
|
12
|
+
import { createDefaultCLI } from './cli/index.js';
|
|
13
|
+
// Constants
|
|
14
|
+
import { DEFAULT_CONFIG } from './constants.js';
|
|
15
|
+
/**
|
|
16
|
+
* Current active theme styles
|
|
17
|
+
*/
|
|
18
|
+
let LEVEL_STYLES = THEME_PRESETS.default;
|
|
19
|
+
/**
|
|
20
|
+
* Main Logger class implementing state-of-the-art logging capabilities
|
|
21
|
+
*/
|
|
22
|
+
export class Logger {
|
|
23
|
+
config;
|
|
24
|
+
scopedPrefix;
|
|
25
|
+
handlers = [];
|
|
26
|
+
timers = new Map();
|
|
27
|
+
groupDepth = 0;
|
|
28
|
+
exportHandler;
|
|
29
|
+
cliProcessor;
|
|
30
|
+
/**
|
|
31
|
+
* Creates a new Logger instance
|
|
32
|
+
*/
|
|
33
|
+
constructor(config = {}) {
|
|
34
|
+
this.config = {
|
|
35
|
+
...DEFAULT_CONFIG,
|
|
36
|
+
...config,
|
|
37
|
+
};
|
|
38
|
+
// Initialize export handler if buffer size is specified
|
|
39
|
+
if (this.config.bufferSize) {
|
|
40
|
+
this.exportHandler = new ExportLogHandler(this.config.bufferSize);
|
|
41
|
+
this.handlers.push(this.exportHandler);
|
|
42
|
+
}
|
|
43
|
+
// Initialize CLI processor
|
|
44
|
+
this.cliProcessor = createDefaultCLI();
|
|
45
|
+
}
|
|
46
|
+
// ===== CONFIGURATION METHODS =====
|
|
47
|
+
/**
|
|
48
|
+
* Get current configuration
|
|
49
|
+
*/
|
|
50
|
+
getConfig() {
|
|
51
|
+
return { ...this.config };
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Update configuration
|
|
55
|
+
*/
|
|
56
|
+
updateConfig(updates) {
|
|
57
|
+
this.config = { ...this.config, ...updates };
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Sets the global prefix for all log messages
|
|
61
|
+
*/
|
|
62
|
+
setGlobalPrefix(prefix) {
|
|
63
|
+
this.config.globalPrefix = prefix;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Sets the verbosity level for filtering log output
|
|
67
|
+
*/
|
|
68
|
+
setVerbosity(level) {
|
|
69
|
+
this.config.verbosity = level;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Sets the logger theme
|
|
73
|
+
*/
|
|
74
|
+
setTheme(theme) {
|
|
75
|
+
if (theme in THEME_PRESETS) {
|
|
76
|
+
LEVEL_STYLES = THEME_PRESETS[theme];
|
|
77
|
+
this.config.theme = theme;
|
|
78
|
+
// Show theme-specific banner
|
|
79
|
+
if (theme in THEME_BANNERS) {
|
|
80
|
+
const themeBanner = THEME_BANNERS[theme];
|
|
81
|
+
console.log(`%c${themeBanner.simple}`, themeBanner.style);
|
|
82
|
+
}
|
|
83
|
+
this.success(`Theme changed to: ${theme}`);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
this.error(`Invalid theme: ${theme}. Available themes:`, Object.keys(THEME_PRESETS));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Set banner type for initialization display
|
|
91
|
+
*/
|
|
92
|
+
setBannerType(bannerType) {
|
|
93
|
+
this.config.bannerType = bannerType;
|
|
94
|
+
this.success(`Banner type changed to: ${bannerType}`);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Reset logger to default configuration
|
|
98
|
+
*/
|
|
99
|
+
resetConfig() {
|
|
100
|
+
this.config = { ...DEFAULT_CONFIG };
|
|
101
|
+
LEVEL_STYLES = THEME_PRESETS.default;
|
|
102
|
+
this.success('Logger configuration reset to defaults');
|
|
103
|
+
}
|
|
104
|
+
// ===== SCOPED LOGGER =====
|
|
105
|
+
/**
|
|
106
|
+
* Creates a scoped logger with a specific prefix
|
|
107
|
+
*/
|
|
108
|
+
createScopedLogger(prefix) {
|
|
109
|
+
const scopedLogger = new Logger(this.config);
|
|
110
|
+
scopedLogger.scopedPrefix = prefix;
|
|
111
|
+
scopedLogger.handlers = [...this.handlers];
|
|
112
|
+
scopedLogger.exportHandler = this.exportHandler;
|
|
113
|
+
return scopedLogger;
|
|
114
|
+
}
|
|
115
|
+
// ===== HANDLER MANAGEMENT =====
|
|
116
|
+
/**
|
|
117
|
+
* Adds a custom log handler for extensibility
|
|
118
|
+
*/
|
|
119
|
+
addHandler(handler) {
|
|
120
|
+
this.handlers.push(handler);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Get all registered handlers
|
|
124
|
+
*/
|
|
125
|
+
getHandlers() {
|
|
126
|
+
return [...this.handlers];
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Get export handler if available
|
|
130
|
+
*/
|
|
131
|
+
getExportHandler() {
|
|
132
|
+
return this.exportHandler;
|
|
133
|
+
}
|
|
134
|
+
// ===== CORE LOGGING METHODS =====
|
|
135
|
+
/**
|
|
136
|
+
* Checks if a log level should be output based on current verbosity
|
|
137
|
+
*/
|
|
138
|
+
shouldLog(level) {
|
|
139
|
+
if (this.config.verbosity === 'silent')
|
|
140
|
+
return false;
|
|
141
|
+
const levels = { debug: 0, info: 1, warn: 2, error: 3, critical: 4 };
|
|
142
|
+
return levels[level] >= levels[this.config.verbosity];
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Gets the effective prefix (global + scoped)
|
|
146
|
+
*/
|
|
147
|
+
getEffectivePrefix() {
|
|
148
|
+
const parts = [this.config.globalPrefix, this.scopedPrefix].filter(Boolean);
|
|
149
|
+
return parts.length > 0 ? parts.join(':') : undefined;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Core logging method that handles styling and formatting
|
|
153
|
+
*/
|
|
154
|
+
log(level, ...args) {
|
|
155
|
+
if (!this.shouldLog(level))
|
|
156
|
+
return;
|
|
157
|
+
const stackInfo = this.config.enableStackTrace ? parseStackTrace() : null;
|
|
158
|
+
const prefix = this.getEffectivePrefix();
|
|
159
|
+
const message = args.length > 0 ? String(args[0]) : '';
|
|
160
|
+
const additionalArgs = args.slice(1);
|
|
161
|
+
// Create styled output
|
|
162
|
+
const [format, ...styles] = createStyledOutput(level, LEVEL_STYLES, prefix, message, stackInfo);
|
|
163
|
+
// Add group indentation
|
|
164
|
+
const groupIndent = ' '.repeat(this.groupDepth);
|
|
165
|
+
const finalFormat = groupIndent + format;
|
|
166
|
+
// Output to console
|
|
167
|
+
if (additionalArgs.length > 0) {
|
|
168
|
+
console.log(finalFormat, ...styles, ...additionalArgs);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
console.log(finalFormat, ...styles);
|
|
172
|
+
}
|
|
173
|
+
// Update export handler group info
|
|
174
|
+
if (this.exportHandler) {
|
|
175
|
+
this.exportHandler.setGroupInfo(this.groupDepth);
|
|
176
|
+
}
|
|
177
|
+
// Call custom handlers
|
|
178
|
+
const metadata = {
|
|
179
|
+
timestamp: formatTimestamp(),
|
|
180
|
+
level,
|
|
181
|
+
prefix,
|
|
182
|
+
stackInfo: stackInfo ? stackInfo : undefined,
|
|
183
|
+
};
|
|
184
|
+
this.handlers.forEach(handler => {
|
|
185
|
+
try {
|
|
186
|
+
handler.handle(level, message, args, metadata);
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
console.error('Log handler failed:', error);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Logs debug information (lowest priority)
|
|
195
|
+
*/
|
|
196
|
+
debug(...args) {
|
|
197
|
+
this.log('debug', ...args);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Logs informational messages
|
|
201
|
+
*/
|
|
202
|
+
info(...args) {
|
|
203
|
+
this.log('info', ...args);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Logs warning messages
|
|
207
|
+
*/
|
|
208
|
+
warn(...args) {
|
|
209
|
+
this.log('warn', ...args);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Logs error messages
|
|
213
|
+
*/
|
|
214
|
+
error(...args) {
|
|
215
|
+
this.log('error', ...args);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Logs success messages (special info level)
|
|
219
|
+
*/
|
|
220
|
+
success(...args) {
|
|
221
|
+
if (!this.shouldLog('info'))
|
|
222
|
+
return;
|
|
223
|
+
const stackInfo = this.config.enableStackTrace ? parseStackTrace() : null;
|
|
224
|
+
const prefix = this.getEffectivePrefix();
|
|
225
|
+
const message = args.length > 0 ? String(args[0]) : '';
|
|
226
|
+
const additionalArgs = args.slice(1);
|
|
227
|
+
// Handle success as special case - use info level with success styling
|
|
228
|
+
const [format, ...styles] = createStyledOutput('info', LEVEL_STYLES, prefix, message, stackInfo);
|
|
229
|
+
// Override with success styling
|
|
230
|
+
const successStyle = LEVEL_STYLES.success;
|
|
231
|
+
let emoji = '✅';
|
|
232
|
+
let label = 'SUCCESS';
|
|
233
|
+
if (successStyle) {
|
|
234
|
+
if (successStyle.emoji) {
|
|
235
|
+
emoji = successStyle.emoji;
|
|
236
|
+
}
|
|
237
|
+
if (successStyle.label) {
|
|
238
|
+
label = successStyle.label;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
const successFormat = format.replace(/ℹ️ INFO/, `${emoji} ${label}`);
|
|
242
|
+
const groupIndent = ' '.repeat(this.groupDepth);
|
|
243
|
+
const finalFormat = groupIndent + successFormat;
|
|
244
|
+
if (additionalArgs.length > 0) {
|
|
245
|
+
console.log(finalFormat, ...styles, ...additionalArgs);
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
console.log(finalFormat, ...styles);
|
|
249
|
+
}
|
|
250
|
+
// Call handlers
|
|
251
|
+
const metadata = {
|
|
252
|
+
timestamp: formatTimestamp(),
|
|
253
|
+
level: 'info',
|
|
254
|
+
prefix,
|
|
255
|
+
stackInfo: stackInfo ? stackInfo : undefined,
|
|
256
|
+
};
|
|
257
|
+
this.handlers.forEach(handler => {
|
|
258
|
+
try {
|
|
259
|
+
handler.handle('info', message, args, metadata);
|
|
260
|
+
}
|
|
261
|
+
catch (error) {
|
|
262
|
+
console.error('Log handler failed:', error);
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Logs trace information (detailed debugging)
|
|
268
|
+
*/
|
|
269
|
+
trace(...args) {
|
|
270
|
+
this.log('debug', ...args);
|
|
271
|
+
if (this.shouldLog('debug')) {
|
|
272
|
+
console.trace(...args);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Logs critical errors (highest priority)
|
|
277
|
+
*/
|
|
278
|
+
critical(...args) {
|
|
279
|
+
this.log('critical', ...args);
|
|
280
|
+
}
|
|
281
|
+
// ===== ADVANCED LOGGING FEATURES =====
|
|
282
|
+
/**
|
|
283
|
+
* Displays data in a table format
|
|
284
|
+
*/
|
|
285
|
+
table(data, columns) {
|
|
286
|
+
if (!this.shouldLog('info'))
|
|
287
|
+
return;
|
|
288
|
+
const prefix = this.getEffectivePrefix();
|
|
289
|
+
const tableStyle = StylePresets.accent().build();
|
|
290
|
+
const format = `%c📊 TABLE${prefix ? ` [${prefix}]` : ''}`;
|
|
291
|
+
console.log(format, tableStyle);
|
|
292
|
+
if (columns) {
|
|
293
|
+
console.table(data, columns);
|
|
294
|
+
}
|
|
295
|
+
else {
|
|
296
|
+
console.table(data);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Starts a collapsible group in the console
|
|
301
|
+
*/
|
|
302
|
+
group(label, collapsed = false) {
|
|
303
|
+
const groupStyle = new StyleBuilder()
|
|
304
|
+
.bg('linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%)')
|
|
305
|
+
.color('#1565c0')
|
|
306
|
+
.border('1px solid #90caf9')
|
|
307
|
+
.padding('4px 12px')
|
|
308
|
+
.rounded('6px')
|
|
309
|
+
.bold()
|
|
310
|
+
.build();
|
|
311
|
+
const format = `%c📁 ${label}`;
|
|
312
|
+
if (collapsed) {
|
|
313
|
+
console.groupCollapsed(format, groupStyle);
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
console.group(format, groupStyle);
|
|
317
|
+
}
|
|
318
|
+
this.groupDepth++;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Ends the current console group
|
|
322
|
+
*/
|
|
323
|
+
groupEnd() {
|
|
324
|
+
if (this.groupDepth > 0) {
|
|
325
|
+
console.groupEnd();
|
|
326
|
+
this.groupDepth--;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
// ===== PERFORMANCE TIMING =====
|
|
330
|
+
/**
|
|
331
|
+
* Starts a timer with the given label
|
|
332
|
+
*/
|
|
333
|
+
time(label) {
|
|
334
|
+
const timer = {
|
|
335
|
+
label,
|
|
336
|
+
startTime: performance.now(),
|
|
337
|
+
};
|
|
338
|
+
this.timers.set(label, timer);
|
|
339
|
+
const timerStyle = StylePresets.warning().build();
|
|
340
|
+
console.log(`%c⏱️ Timer started: ${label}`, timerStyle);
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Ends a timer and logs the elapsed time
|
|
344
|
+
*/
|
|
345
|
+
timeEnd(label) {
|
|
346
|
+
const timer = this.timers.get(label);
|
|
347
|
+
if (!timer) {
|
|
348
|
+
this.warn(`Timer '${label}' does not exist`);
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
const elapsed = performance.now() - timer.startTime;
|
|
352
|
+
this.timers.delete(label);
|
|
353
|
+
const timerStyle = StylePresets.success().build();
|
|
354
|
+
console.log(`%c⏱️ Timer ended: ${label} - ${elapsed.toFixed(2)}ms`, timerStyle);
|
|
355
|
+
}
|
|
356
|
+
// ===== ADVANCED VISUAL FEATURES =====
|
|
357
|
+
/**
|
|
358
|
+
* Display banner with specified or configured type
|
|
359
|
+
*/
|
|
360
|
+
showBanner(bannerType) {
|
|
361
|
+
const effectiveBannerType = bannerType ? bannerType : this.config.bannerType;
|
|
362
|
+
displayInitBanner(effectiveBannerType);
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Log with SVG background image
|
|
366
|
+
*/
|
|
367
|
+
logWithSVG(message, svgContent, options = {}) {
|
|
368
|
+
const { width = 300, height = 60, padding = '30px 150px' } = options;
|
|
369
|
+
let svgDataUri = '';
|
|
370
|
+
if (svgContent) {
|
|
371
|
+
const encodedSVG = encodeURIComponent(svgContent);
|
|
372
|
+
svgDataUri = `data:image/svg+xml,${encodedSVG}`;
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
const defaultSVG = `<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 ${width} ${height}'><defs><linearGradient id='grad' x1='0%' y1='0%' x2='100%' y2='0%'><stop offset='0%' style='stop-color:%23667eea'/><stop offset='100%' style='stop-color:%23764ba2'/></linearGradient></defs><rect width='100%' height='100%' fill='url(%23grad)' rx='4'/><text x='${width / 2}' y='${height / 2 + 5}' text-anchor='middle' fill='white' font-family='monospace' font-size='14' font-weight='bold'>${message}</text></svg>`;
|
|
376
|
+
svgDataUri = `data:image/svg+xml,${encodeURIComponent(defaultSVG)}`;
|
|
377
|
+
}
|
|
378
|
+
const svgStyle = new StyleBuilder()
|
|
379
|
+
.bg(`url("${svgDataUri}") no-repeat center center`)
|
|
380
|
+
.padding(padding)
|
|
381
|
+
.color('transparent')
|
|
382
|
+
.rounded('4px')
|
|
383
|
+
.build();
|
|
384
|
+
console.log(`%c${message}`, svgStyle);
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Log with animated background gradient
|
|
388
|
+
*/
|
|
389
|
+
logAnimated(message, duration = 3) {
|
|
390
|
+
// Inject CSS animation if not already present
|
|
391
|
+
if (!document.getElementById('logger-animations')) {
|
|
392
|
+
const style = document.createElement('style');
|
|
393
|
+
style.id = 'logger-animations';
|
|
394
|
+
style.textContent = `
|
|
395
|
+
@keyframes loggerGradient {
|
|
396
|
+
0% { background-position: 0% 50%; }
|
|
397
|
+
50% { background-position: 100% 50%; }
|
|
398
|
+
100% { background-position: 0% 50%; }
|
|
399
|
+
}
|
|
400
|
+
`;
|
|
401
|
+
document.head.appendChild(style);
|
|
402
|
+
}
|
|
403
|
+
const animatedStyle = new StyleBuilder()
|
|
404
|
+
.bg('linear-gradient(-45deg, #667eea, #764ba2, #667eea, #764ba2)')
|
|
405
|
+
.css('background-size', '400% 400%')
|
|
406
|
+
.color('#ffffff')
|
|
407
|
+
.padding('12px 20px')
|
|
408
|
+
.rounded('8px')
|
|
409
|
+
.bold()
|
|
410
|
+
.font('Monaco, Consolas, monospace')
|
|
411
|
+
.animation(`loggerGradient ${duration}s ease infinite`)
|
|
412
|
+
.display('inline-block')
|
|
413
|
+
.build();
|
|
414
|
+
console.log(`%c${message}`, animatedStyle);
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Groups logs by a specific property using modern Object.groupBy (when available)
|
|
418
|
+
*/
|
|
419
|
+
logGrouped(items, groupBy) {
|
|
420
|
+
try {
|
|
421
|
+
// Use Object.groupBy if available (ES2024), otherwise fallback to reduce
|
|
422
|
+
let grouped;
|
|
423
|
+
if (Object.groupBy) {
|
|
424
|
+
grouped = Object.groupBy(items, groupBy);
|
|
425
|
+
}
|
|
426
|
+
else {
|
|
427
|
+
grouped = items.reduce((acc, item) => {
|
|
428
|
+
const key = groupBy(item);
|
|
429
|
+
if (!acc[key]) {
|
|
430
|
+
acc[key] = [];
|
|
431
|
+
}
|
|
432
|
+
acc[key].push(item);
|
|
433
|
+
return acc;
|
|
434
|
+
}, {});
|
|
435
|
+
}
|
|
436
|
+
Object.entries(grouped).forEach(([group, groupItems]) => {
|
|
437
|
+
this.group(`Group: ${group}`);
|
|
438
|
+
this.table(groupItems);
|
|
439
|
+
this.groupEnd();
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
catch {
|
|
443
|
+
this.info('Grouped data:', items);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
// ===== CLI SYSTEM =====
|
|
447
|
+
/**
|
|
448
|
+
* CLI command processor for logger configuration and export
|
|
449
|
+
*/
|
|
450
|
+
async cli(command) {
|
|
451
|
+
if (!this.cliProcessor) {
|
|
452
|
+
this.error('CLI processor not initialized');
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
await this.cliProcessor.processCommand(command, this);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
// Create and export the singleton instance
|
|
459
|
+
const defaultLogger = new Logger({
|
|
460
|
+
verbosity: 'info',
|
|
461
|
+
enableColors: true,
|
|
462
|
+
enableTimestamps: true,
|
|
463
|
+
enableStackTrace: true,
|
|
464
|
+
bufferSize: 1000, // Enable export functionality by default
|
|
465
|
+
});
|
|
466
|
+
// Display initialization banner
|
|
467
|
+
displayInitBanner();
|
|
468
|
+
// Export the singleton instance as default
|
|
469
|
+
export default defaultLogger;
|
|
470
|
+
/**
|
|
471
|
+
* Export individual methods for convenience (with proper binding)
|
|
472
|
+
*/
|
|
473
|
+
export const debug = (...args) => defaultLogger.debug(...args);
|
|
474
|
+
export const info = (...args) => defaultLogger.info(...args);
|
|
475
|
+
export const warn = (...args) => defaultLogger.warn(...args);
|
|
476
|
+
export const error = (...args) => defaultLogger.error(...args);
|
|
477
|
+
export const success = (...args) => defaultLogger.success(...args);
|
|
478
|
+
export const trace = (...args) => defaultLogger.trace(...args);
|
|
479
|
+
export const critical = (...args) => defaultLogger.critical(...args);
|
|
480
|
+
export const table = (data, columns) => defaultLogger.table(data, columns);
|
|
481
|
+
export const group = (label, collapsed) => defaultLogger.group(label, collapsed);
|
|
482
|
+
export const groupEnd = () => defaultLogger.groupEnd();
|
|
483
|
+
export const time = (label) => defaultLogger.time(label);
|
|
484
|
+
export const timeEnd = (label) => defaultLogger.timeEnd(label);
|
|
485
|
+
export const setGlobalPrefix = (prefix) => defaultLogger.setGlobalPrefix(prefix);
|
|
486
|
+
export const createScopedLogger = (prefix) => defaultLogger.createScopedLogger(prefix);
|
|
487
|
+
export const setVerbosity = (level) => defaultLogger.setVerbosity(level);
|
|
488
|
+
export const addHandler = (handler) => defaultLogger.addHandler(handler);
|
|
489
|
+
export const setTheme = (theme) => defaultLogger.setTheme(theme);
|
|
490
|
+
export const setBannerType = (bannerType) => defaultLogger.setBannerType(bannerType);
|
|
491
|
+
export const showBanner = (bannerType) => defaultLogger.showBanner(bannerType);
|
|
492
|
+
export const logWithSVG = (message, svgContent, options) => defaultLogger.logWithSVG(message, svgContent, options);
|
|
493
|
+
export const logAnimated = (message, duration) => defaultLogger.logAnimated(message, duration);
|
|
494
|
+
export const cli = (command) => defaultLogger.cli(command);
|
|
495
|
+
// Re-export handlers and utilities for backward compatibility
|
|
496
|
+
export { FileLogHandler, RemoteLogHandler, AnalyticsLogHandler, ExportLogHandler } from './handlers/index.js';
|
|
497
|
+
export { StyleBuilder, StylePresets as Styles } from './styling/index.js'; // Test change to trigger workflow
|
|
498
|
+
// Test permissions fix
|