@mks2508/better-logger 5.0.0 → 5.0.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/dist/chunks/{Logger-Cbi1f10o.js → Logger-CKqzXDh3.js} +2 -2
- package/dist/chunks/{Logger-Cbi1f10o.js.map → Logger-CKqzXDh3.js.map} +1 -1
- package/dist/chunks/{Logger-BZ7B7OXE.js → Logger-D_vuKP4l.js} +2 -2
- package/dist/chunks/{Logger-BZ7B7OXE.js.map → Logger-D_vuKP4l.js.map} +1 -1
- package/dist/chunks/cli-module-B-njrTWb.js +2 -0
- package/dist/chunks/cli-module-B-njrTWb.js.map +1 -0
- package/dist/chunks/{cli-module-ClIJmaT8.js → cli-module-Cx7qotPY.js} +16 -9
- package/dist/chunks/cli-module-Cx7qotPY.js.map +1 -0
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/exports.cjs +1 -1
- package/dist/exports.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +3 -3
- package/dist/styling.cjs +1 -1
- package/dist/styling.js +2 -2
- package/dist/terminal/formatter.d.ts.map +1 -1
- package/package.json +5 -1
- package/.claude/settings.local.json +0 -48
- package/.github/workflows/ci-quality.yml +0 -357
- package/.github/workflows/docs-demo.yml +0 -119
- package/.github/workflows/releases-core.yml +0 -512
- package/.github/workflows/releases-full.yml +0 -582
- package/.github/workflows-backup/ci.yml +0 -221
- package/.github/workflows-backup/nightly.yml +0 -196
- package/.github/workflows-backup/release-optimized.yml +0 -373
- package/.github/workflows-backup/release.yml +0 -269
- package/.release-notes-0.2.0.md +0 -129
- package/.yamllint +0 -28
- package/CHANGELOG.json +0 -1076
- package/CHANGELOG.md +0 -209
- package/CLAUDE.md +0 -217
- package/bun.lock +0 -333
- package/demo.html +0 -847
- package/dist/chunks/cli-module-CadqgZ1Z.js +0 -2
- package/dist/chunks/cli-module-CadqgZ1Z.js.map +0 -1
- package/dist/chunks/cli-module-ClIJmaT8.js.map +0 -1
- package/docs/API.md +0 -918
- package/docs/CORE.md +0 -264
- package/docs/DEVELOPMENT.md +0 -731
- package/docs/EXPORTS.md +0 -467
- package/docs/PACKAGES.md +0 -244
- package/docs/STYLING.md +0 -405
- package/docs/_config.yml +0 -36
- package/docs/index.md +0 -179
- package/examples/README.md +0 -208
- package/examples/basic-logging.js +0 -75
- package/examples/data-export.js +0 -234
- package/examples/package.json +0 -16
- package/examples/performance-timing.js +0 -170
- package/examples/simplified-api.js +0 -124
- package/examples/styling-themes.js +0 -207
- package/index.html +0 -358
- package/packages/core/package.json +0 -57
- package/packages/exports/package.json +0 -41
- package/packages/nodejs-opentui/README.md +0 -232
- package/packages/nodejs-opentui/package.json +0 -72
- package/packages/nodejs-opentui/src/LogRenderer.ts +0 -171
- package/packages/nodejs-opentui/src/OpenTUILogHandler.ts +0 -178
- package/packages/nodejs-opentui/src/components/LogBadge.tsx +0 -131
- package/packages/nodejs-opentui/src/index.ts +0 -133
- package/packages/nodejs-opentui/src/types.ts +0 -158
- package/packages/nodejs-opentui/tsconfig.json +0 -20
- package/packages/styling/package.json +0 -41
- package/playground/demo-all.ts +0 -95
- package/playground/demo-box.ts +0 -85
- package/playground/demo-levels.ts +0 -56
- package/playground/demo-real-world.ts +0 -98
- package/playground/demo-spinner.ts +0 -77
- package/playground/demo-steps.ts +0 -72
- package/playground/demo-table.ts +0 -83
- package/project-utils/README.md +0 -172
- package/project-utils/auto-release-gemini.ts +0 -1193
- package/project-utils/auto-release-ui.ts +0 -1329
- package/project-utils/commit-generator.ts +0 -1385
- package/project-utils/commit-ui.ts +0 -264
- package/project-utils/git-utils.ts +0 -199
- package/project-utils/github-release-manager.ts +0 -466
- package/project-utils/project-config.ts +0 -260
- package/project-utils/prompt-templates.js +0 -345
- package/project-utils/prompt-templates.ts +0 -422
- package/project-utils/version-manager.ts +0 -1078
- package/public/vite.svg +0 -1
- package/src/Logger.ts +0 -1858
- package/src/ScopedLogger.ts +0 -256
- package/src/cli/CommandProcessor.ts +0 -248
- package/src/cli/commands/ConfigCommand.ts +0 -93
- package/src/cli/commands/ExportCommand.ts +0 -276
- package/src/cli/commands/HistoryCommand.ts +0 -117
- package/src/cli/commands/StatusCommand.ts +0 -112
- package/src/cli/commands/ThemeCommand.ts +0 -88
- package/src/cli/help.ts +0 -127
- package/src/cli/index.ts +0 -71
- package/src/cli-module.ts +0 -21
- package/src/cli-primitives/box.ts +0 -86
- package/src/cli-primitives/cli-table.ts +0 -62
- package/src/cli-primitives/divider.ts +0 -17
- package/src/cli-primitives/header.ts +0 -18
- package/src/cli-primitives/index.ts +0 -13
- package/src/cli-primitives/server-fallback.ts +0 -54
- package/src/cli-primitives/spinner.ts +0 -133
- package/src/cli-primitives/step.ts +0 -22
- package/src/constants.ts +0 -313
- package/src/core.ts +0 -397
- package/src/example.ts +0 -210
- package/src/exports-module.ts +0 -311
- package/src/handlers/AnalyticsLogHandler.ts +0 -22
- package/src/handlers/ExportLogHandler.ts +0 -610
- package/src/handlers/FileLogHandler.ts +0 -169
- package/src/handlers/RemoteLogHandler.ts +0 -42
- package/src/handlers/index.ts +0 -8
- package/src/hooks/HookManager.ts +0 -177
- package/src/hooks/index.ts +0 -1
- package/src/index.ts +0 -395
- package/src/main.ts +0 -196
- package/src/serializers/SerializerRegistry.ts +0 -173
- package/src/serializers/index.ts +0 -1
- package/src/style.css +0 -96
- package/src/styling/LogStyleBuilder.ts +0 -355
- package/src/styling/SemanticStyles.ts +0 -380
- package/src/styling/SmartPresets.ts +0 -288
- package/src/styling/StyleBuilder.ts +0 -319
- package/src/styling/StyleCache.ts +0 -131
- package/src/styling/banners.ts +0 -168
- package/src/styling/index.ts +0 -27
- package/src/styling/themes.ts +0 -235
- package/src/styling-module.ts +0 -244
- package/src/terminal/color-converter.ts +0 -315
- package/src/terminal/formatter.ts +0 -236
- package/src/terminal/terminal-renderer.ts +0 -342
- package/src/transports/ConsoleTransport.ts +0 -28
- package/src/transports/FileTransport.ts +0 -53
- package/src/transports/HttpTransport.ts +0 -56
- package/src/transports/TransportManager.ts +0 -130
- package/src/transports/index.ts +0 -4
- package/src/types/core.ts +0 -417
- package/src/types/handlers.ts +0 -95
- package/src/types/hooks.ts +0 -45
- package/src/types/index.ts +0 -83
- package/src/types/serializers.ts +0 -30
- package/src/types/transports.ts +0 -52
- package/src/typescript.svg +0 -1
- package/src/utils/adapter.ts +0 -291
- package/src/utils/ansi-colors.ts +0 -333
- package/src/utils/environment-detector.ts +0 -170
- package/src/utils/environment.ts +0 -94
- package/src/utils/formatting.ts +0 -332
- package/src/utils/index.ts +0 -33
- package/src/utils/opentui-detection.ts +0 -138
- package/src/utils/output.ts +0 -227
- package/src/utils/stackTrace.ts +0 -144
- package/src/utils/timestamps.ts +0 -80
- package/src/vite-env.d.ts +0 -1
- package/src/writers/BufferWriter.ts +0 -157
- package/src/writers/index.ts +0 -6
- package/test-core-browser.html +0 -237
- package/test-core-node.js +0 -63
- package/tests/test-conflict-resolution.ts +0 -391
- package/tests/validate-workflows.sh +0 -131
- package/tests/yaml-autofix.sh +0 -146
- package/tsconfig.json +0 -50
- package/vite.config.ts +0 -256
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview OpenTUI detection and enhancement utilities for core logger
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { isNode } from './environment.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Check if OpenTUI packages are available
|
|
9
|
-
*/
|
|
10
|
-
export async function hasOpenTUI(): Promise<boolean> {
|
|
11
|
-
if (!isNode) {
|
|
12
|
-
return false; // OpenTUI is Node.js only
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
// Try to dynamically import OpenTUI core
|
|
17
|
-
// @ts-expect-error - Optional dependency, may not be installed
|
|
18
|
-
await import('@opentui/core');
|
|
19
|
-
return true;
|
|
20
|
-
} catch (error) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Check if OpenTUI enhancement package is available
|
|
27
|
-
*/
|
|
28
|
-
export async function hasOpenTUILogHandler(): Promise<boolean> {
|
|
29
|
-
if (!isNode) {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
try {
|
|
34
|
-
// @ts-expect-error - Optional dependency, may not be installed
|
|
35
|
-
await import('@mks2508/better-logger-nodejs-opentui');
|
|
36
|
-
return true;
|
|
37
|
-
} catch (error) {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Dynamically enhance logger with OpenTUI if available
|
|
44
|
-
*/
|
|
45
|
-
export async function tryEnhanceWithOpenTUI(logger: any): Promise<boolean> {
|
|
46
|
-
try {
|
|
47
|
-
// Check if both OpenTUI and our enhancement package are available
|
|
48
|
-
const [hasCore, hasEnhancer] = await Promise.all([
|
|
49
|
-
hasOpenTUI(),
|
|
50
|
-
hasOpenTUILogHandler()
|
|
51
|
-
]);
|
|
52
|
-
|
|
53
|
-
if (!hasCore || !hasEnhancer) {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Dynamically import and apply enhancement
|
|
58
|
-
// @ts-expect-error - Optional dependency, may not be installed
|
|
59
|
-
const { enhanceLoggerWithOpenTUI } = await import('@mks2508/better-logger-nodejs-opentui');
|
|
60
|
-
|
|
61
|
-
const enhanced = await enhanceLoggerWithOpenTUI(logger, {
|
|
62
|
-
renderer: {
|
|
63
|
-
animated: true,
|
|
64
|
-
theme: 'auto',
|
|
65
|
-
components: {
|
|
66
|
-
badges: true,
|
|
67
|
-
progressBars: false,
|
|
68
|
-
tables: false,
|
|
69
|
-
charts: false
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
return enhanced;
|
|
75
|
-
} catch (error) {
|
|
76
|
-
console.warn('Failed to enhance logger with OpenTUI:', error);
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Get OpenTUI environment information
|
|
83
|
-
*/
|
|
84
|
-
export async function getOpenTUIInfo(): Promise<{
|
|
85
|
-
available: boolean;
|
|
86
|
-
coreAvailable: boolean;
|
|
87
|
-
handlerAvailable: boolean;
|
|
88
|
-
nodeVersion: string | null;
|
|
89
|
-
terminalSupport: boolean;
|
|
90
|
-
}> {
|
|
91
|
-
const [coreAvailable, handlerAvailable] = await Promise.all([
|
|
92
|
-
hasOpenTUI(),
|
|
93
|
-
hasOpenTUILogHandler()
|
|
94
|
-
]);
|
|
95
|
-
|
|
96
|
-
return {
|
|
97
|
-
available: coreAvailable && handlerAvailable,
|
|
98
|
-
coreAvailable,
|
|
99
|
-
handlerAvailable,
|
|
100
|
-
nodeVersion: isNode ? process.version : null,
|
|
101
|
-
terminalSupport: isNode ? process.stdout?.isTTY === true : false
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Auto-enhance logger with best available rendering
|
|
107
|
-
*/
|
|
108
|
-
export async function autoEnhanceLogger(logger: any): Promise<{
|
|
109
|
-
enhanced: boolean;
|
|
110
|
-
method: 'opentui' | 'ansi' | 'plain';
|
|
111
|
-
info?: any;
|
|
112
|
-
}> {
|
|
113
|
-
// Try OpenTUI first
|
|
114
|
-
const openTUIEnhanced = await tryEnhanceWithOpenTUI(logger);
|
|
115
|
-
if (openTUIEnhanced) {
|
|
116
|
-
return {
|
|
117
|
-
enhanced: true,
|
|
118
|
-
method: 'opentui',
|
|
119
|
-
info: await getOpenTUIInfo()
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Fallback to ANSI colors if in Node.js
|
|
124
|
-
if (isNode && process.stdout?.isTTY) {
|
|
125
|
-
return {
|
|
126
|
-
enhanced: false,
|
|
127
|
-
method: 'ansi',
|
|
128
|
-
info: { reason: 'OpenTUI not available, using ANSI colors' }
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Plain text fallback
|
|
133
|
-
return {
|
|
134
|
-
enhanced: false,
|
|
135
|
-
method: 'plain',
|
|
136
|
-
info: { reason: 'No enhanced rendering available' }
|
|
137
|
-
};
|
|
138
|
-
}
|
package/src/utils/output.ts
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Styled output creation utilities for Advanced Logger
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { LogLevel, StackInfo, DevToolsTheme, AdaptiveColors } from '../types/index.js';
|
|
6
|
-
import { formatTimestamp } from './timestamps.js';
|
|
7
|
-
import { StyleBuilder } from '../styling/index.js';
|
|
8
|
-
import { ADAPTIVE_COLORS } from '../constants.js';
|
|
9
|
-
import { getEnvironment, supportsANSI } from './environment-detector.js';
|
|
10
|
-
import { adaptToTerminal } from './adapter.js';
|
|
11
|
-
import type { LogStyles } from '../types/index.js';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Style configuration for each log level
|
|
15
|
-
*/
|
|
16
|
-
export interface LevelStyleConfig {
|
|
17
|
-
emoji: string;
|
|
18
|
-
label: string;
|
|
19
|
-
background: string;
|
|
20
|
-
color: string;
|
|
21
|
-
border: string;
|
|
22
|
-
shadow: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Detects the current DevTools theme preference
|
|
27
|
-
*/
|
|
28
|
-
export function detectDevToolsTheme(): DevToolsTheme {
|
|
29
|
-
try {
|
|
30
|
-
if (typeof window === 'undefined' || !window.matchMedia) {
|
|
31
|
-
return 'light'; // Safe fallback for SSR or older browsers
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
|
35
|
-
return mediaQuery.matches ? 'dark' : 'light';
|
|
36
|
-
} catch (error) {
|
|
37
|
-
console.warn('Failed to detect DevTools theme:', error);
|
|
38
|
-
return 'light'; // Fallback to light theme
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Gets adaptive color based on current DevTools theme
|
|
44
|
-
*/
|
|
45
|
-
export function getAdaptiveColor(colors: AdaptiveColors, theme?: DevToolsTheme): string {
|
|
46
|
-
const currentTheme = theme ?? detectDevToolsTheme();
|
|
47
|
-
return colors[currentTheme];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Sets up theme change listener for dynamic updates
|
|
52
|
-
*/
|
|
53
|
-
export function setupThemeChangeListener(callback: (theme: DevToolsTheme) => void): (() => void) | null {
|
|
54
|
-
try {
|
|
55
|
-
if (typeof window === 'undefined' || !window.matchMedia) {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
|
60
|
-
const handler = (e: MediaQueryListEvent) => {
|
|
61
|
-
callback(e.matches ? 'dark' : 'light');
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
// Use newer addEventListener if available, fallback to addListener
|
|
65
|
-
if (mediaQuery.addEventListener) {
|
|
66
|
-
mediaQuery.addEventListener('change', handler);
|
|
67
|
-
return () => mediaQuery.removeEventListener('change', handler);
|
|
68
|
-
} else if (mediaQuery.addListener) {
|
|
69
|
-
mediaQuery.addListener(handler);
|
|
70
|
-
return () => mediaQuery.removeListener?.(handler);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return null;
|
|
74
|
-
} catch (error) {
|
|
75
|
-
console.warn('Failed to set up theme change listener:', error);
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Creates styled console output with multiple %c formatters
|
|
83
|
-
* Automatically adapts to browser or terminal environment
|
|
84
|
-
*/
|
|
85
|
-
export function createStyledOutput(
|
|
86
|
-
level: LogLevel,
|
|
87
|
-
levelStyles: Record<LogLevel | 'success', LevelStyleConfig>,
|
|
88
|
-
prefix: string | undefined,
|
|
89
|
-
message: string,
|
|
90
|
-
stackInfo: StackInfo | null,
|
|
91
|
-
autoDetectTheme: boolean = true,
|
|
92
|
-
presetStyles?: LogStyles,
|
|
93
|
-
presetName?: string
|
|
94
|
-
): [string, ...string[]] {
|
|
95
|
-
const levelConfig = levelStyles[level];
|
|
96
|
-
const timestamp = formatTimestamp();
|
|
97
|
-
const environment = getEnvironment();
|
|
98
|
-
|
|
99
|
-
// Check if we should use terminal rendering
|
|
100
|
-
if (environment !== 'browser' && supportsANSI()) {
|
|
101
|
-
return createTerminalOutput(level, message, timestamp, prefix, stackInfo, presetStyles, presetName);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Browser rendering (existing logic)
|
|
105
|
-
const currentTheme = autoDetectTheme ? detectDevToolsTheme() : 'light';
|
|
106
|
-
|
|
107
|
-
// Base styles with adaptive colors
|
|
108
|
-
const timestampStyle = new StyleBuilder()
|
|
109
|
-
.color(getAdaptiveColor(ADAPTIVE_COLORS.timestamp, currentTheme))
|
|
110
|
-
.size('11px')
|
|
111
|
-
.font('Monaco, Consolas, monospace')
|
|
112
|
-
.build();
|
|
113
|
-
|
|
114
|
-
const levelStyle = new StyleBuilder()
|
|
115
|
-
.bg(levelConfig.background)
|
|
116
|
-
.color(levelConfig.color)
|
|
117
|
-
.border(levelConfig.border)
|
|
118
|
-
.shadow(levelConfig.shadow)
|
|
119
|
-
.padding('2px 8px')
|
|
120
|
-
.rounded('4px')
|
|
121
|
-
.bold()
|
|
122
|
-
.font('Monaco, Consolas, monospace')
|
|
123
|
-
.size('12px')
|
|
124
|
-
.build();
|
|
125
|
-
|
|
126
|
-
const prefixStyle = new StyleBuilder()
|
|
127
|
-
.bg(getAdaptiveColor(ADAPTIVE_COLORS.prefixBackground, currentTheme))
|
|
128
|
-
.color(getAdaptiveColor(ADAPTIVE_COLORS.prefix, currentTheme))
|
|
129
|
-
.padding('2px 6px')
|
|
130
|
-
.rounded('3px')
|
|
131
|
-
.bold()
|
|
132
|
-
.font('Monaco, Consolas, monospace')
|
|
133
|
-
.size('11px')
|
|
134
|
-
.build();
|
|
135
|
-
|
|
136
|
-
const messageStyle = new StyleBuilder()
|
|
137
|
-
.color(getAdaptiveColor(ADAPTIVE_COLORS.messageText, currentTheme))
|
|
138
|
-
.font('system-ui, -apple-system, sans-serif')
|
|
139
|
-
.size('14px')
|
|
140
|
-
.build();
|
|
141
|
-
|
|
142
|
-
const locationStyle = new StyleBuilder()
|
|
143
|
-
.color(getAdaptiveColor(ADAPTIVE_COLORS.location, currentTheme))
|
|
144
|
-
.size('11px')
|
|
145
|
-
.font('Monaco, Consolas, monospace')
|
|
146
|
-
.build();
|
|
147
|
-
|
|
148
|
-
// Build format string and styles
|
|
149
|
-
let format = `%c${timestamp.slice(11, 23)} %c${levelConfig.emoji} ${levelConfig.label}`;
|
|
150
|
-
const styles = [timestampStyle, levelStyle];
|
|
151
|
-
|
|
152
|
-
if (prefix) {
|
|
153
|
-
format += ` %c${prefix}`;
|
|
154
|
-
styles.push(prefixStyle);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
format += ` %c${message}`;
|
|
158
|
-
styles.push(messageStyle);
|
|
159
|
-
|
|
160
|
-
if (stackInfo) {
|
|
161
|
-
format += ` %c(${stackInfo.file}:${stackInfo.line}:${stackInfo.column})`;
|
|
162
|
-
styles.push(locationStyle);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return [format, ...styles];
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Create a unique ID for log entries
|
|
170
|
-
*/
|
|
171
|
-
export function generateLogId(): string {
|
|
172
|
-
return `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Escape HTML entities for safe HTML output
|
|
177
|
-
*/
|
|
178
|
-
export function escapeHtml(text: string): string {
|
|
179
|
-
const div = document.createElement('div');
|
|
180
|
-
div.textContent = text;
|
|
181
|
-
return div.innerHTML;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Convert objects to safe string representation for logging
|
|
186
|
-
*/
|
|
187
|
-
export function safeStringify(obj: any, _maxDepth = 3): string {
|
|
188
|
-
try {
|
|
189
|
-
return JSON.stringify(obj, (_key, value) => {
|
|
190
|
-
if (typeof value === 'function') return '[Function]';
|
|
191
|
-
if (value instanceof Error) return `[Error: ${value.message}]`;
|
|
192
|
-
if (value instanceof Date) return value.toISOString();
|
|
193
|
-
if (typeof value === 'undefined') return '[undefined]';
|
|
194
|
-
return value;
|
|
195
|
-
}, 2);
|
|
196
|
-
} catch (error) {
|
|
197
|
-
return String(obj);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Create terminal output with ANSI colors and formatting
|
|
203
|
-
*/
|
|
204
|
-
export function createTerminalOutput(
|
|
205
|
-
level: LogLevel,
|
|
206
|
-
message: string,
|
|
207
|
-
timestamp?: string,
|
|
208
|
-
prefix?: string,
|
|
209
|
-
stackInfo?: StackInfo | null,
|
|
210
|
-
presetStyles?: LogStyles,
|
|
211
|
-
presetName?: string
|
|
212
|
-
): [string, ...string[]] {
|
|
213
|
-
const location = stackInfo ? `${stackInfo.file}:${stackInfo.line}:${stackInfo.column}` : undefined;
|
|
214
|
-
|
|
215
|
-
// Use the adapter to convert styles to ANSI
|
|
216
|
-
const ansiStyle = adaptToTerminal(
|
|
217
|
-
level,
|
|
218
|
-
message,
|
|
219
|
-
timestamp,
|
|
220
|
-
prefix,
|
|
221
|
-
location,
|
|
222
|
-
presetStyles,
|
|
223
|
-
presetName
|
|
224
|
-
);
|
|
225
|
-
|
|
226
|
-
return [ansiStyle.text];
|
|
227
|
-
}
|
package/src/utils/stackTrace.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Stack trace parsing utilities for Advanced Logger
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { StackInfo } from '../types/index.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Check if a filename represents a minified/bundle file
|
|
9
|
-
*/
|
|
10
|
-
function isMinifiedFile(filename: string): boolean {
|
|
11
|
-
// Skip if filename contains minified patterns
|
|
12
|
-
const minifiedPatterns = [
|
|
13
|
-
/\.min\.js$/,
|
|
14
|
-
/\.bundle\.js$/,
|
|
15
|
-
/\.chunk\.js$/,
|
|
16
|
-
/-[\w\d]{8,}\.js$/, // Hash-based filenames
|
|
17
|
-
/Logger-[A-Za-z0-9]+\.js$/, // Logger bundle files
|
|
18
|
-
/node_modules/,
|
|
19
|
-
/dist\//,
|
|
20
|
-
/build\//,
|
|
21
|
-
/\.mjs$/
|
|
22
|
-
];
|
|
23
|
-
|
|
24
|
-
return minifiedPatterns.some(pattern => pattern.test(filename));
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Extract clean filename from full path
|
|
29
|
-
*/
|
|
30
|
-
function extractCleanFilename(fullPath: string): string {
|
|
31
|
-
// Extract just the filename from the full path
|
|
32
|
-
const filename = fullPath.split(/[/\\]/).pop() || fullPath;
|
|
33
|
-
|
|
34
|
-
// Remove common build/minified suffixes
|
|
35
|
-
return filename
|
|
36
|
-
.replace(/\.min\.js$/, '.js')
|
|
37
|
-
.replace(/\.bundle\.js$/, '.js')
|
|
38
|
-
.replace(/\.chunk\.js$/, '.js')
|
|
39
|
-
.replace(/-[\w\d]{8,}\.js$/, '.js')
|
|
40
|
-
.replace(/Logger-[A-Za-z0-9]+\.js$/, 'logger.ts');
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Parses the current stack trace to extract caller information
|
|
45
|
-
*/
|
|
46
|
-
export function parseStackTrace(): StackInfo | null {
|
|
47
|
-
try {
|
|
48
|
-
const stack = new Error().stack;
|
|
49
|
-
if (!stack) {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const lines = stack.split('\n').filter(line => line.trim());
|
|
54
|
-
|
|
55
|
-
// Find the first caller that's not from Logger methods
|
|
56
|
-
for (let i = 1; i < lines.length; i++) {
|
|
57
|
-
const line = lines[i];
|
|
58
|
-
|
|
59
|
-
if (!line) {
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Skip if line contains Logger methods or parseStackTrace
|
|
64
|
-
if (line.includes('parseStackTrace') ||
|
|
65
|
-
line.includes('Logger.') ||
|
|
66
|
-
line.includes('.log(') ||
|
|
67
|
-
line.includes('createStyledOutput')) {
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Parse different stack trace formats
|
|
72
|
-
let match;
|
|
73
|
-
|
|
74
|
-
// Chrome format: "at functionName (file:line:column)" or "at file:line:column"
|
|
75
|
-
const chromeMatch = line.match(/at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?$/);
|
|
76
|
-
if (chromeMatch) {
|
|
77
|
-
const filename = chromeMatch[2];
|
|
78
|
-
// Skip minified/bundle files
|
|
79
|
-
if (filename && isMinifiedFile(filename)) {
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
match = chromeMatch;
|
|
83
|
-
} else {
|
|
84
|
-
// Firefox format: "functionName@file:line:column"
|
|
85
|
-
const firefoxMatch = line.match(/(.+?)@(.+?):(\d+):(\d+)$/);
|
|
86
|
-
if (firefoxMatch) {
|
|
87
|
-
const filename = firefoxMatch[2];
|
|
88
|
-
// Skip minified/bundle files
|
|
89
|
-
if (filename && isMinifiedFile(filename)) {
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
match = firefoxMatch;
|
|
93
|
-
} else {
|
|
94
|
-
// Safari/other formats
|
|
95
|
-
const safariMatch = line.match(/(\S+)?@(.+?):(\d+):(\d+)$/);
|
|
96
|
-
if (safariMatch) {
|
|
97
|
-
const filename = safariMatch[2];
|
|
98
|
-
// Skip minified/bundle files
|
|
99
|
-
if (filename && isMinifiedFile(filename)) {
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
match = safariMatch;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (!match) {
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const [, functionName, file, lineStr, columnStr] = match;
|
|
112
|
-
|
|
113
|
-
if (!file) {
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Use clean filename extraction to avoid minified files
|
|
118
|
-
const cleanFileName = extractCleanFilename(file).split('?')[0];
|
|
119
|
-
if (!cleanFileName) {
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Parse line and column numbers
|
|
124
|
-
const lineNum = lineStr ? parseInt(lineStr, 10) : 0;
|
|
125
|
-
const columnNum = columnStr ? parseInt(columnStr, 10) : 0;
|
|
126
|
-
|
|
127
|
-
// Clean function name
|
|
128
|
-
const cleanFunction = functionName && functionName.trim()
|
|
129
|
-
? functionName.trim()
|
|
130
|
-
: undefined;
|
|
131
|
-
|
|
132
|
-
return {
|
|
133
|
-
file: cleanFileName ? cleanFileName : 'unknown',
|
|
134
|
-
line: lineNum,
|
|
135
|
-
column: columnNum,
|
|
136
|
-
function: cleanFunction
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
return null;
|
|
141
|
-
} catch {
|
|
142
|
-
return null;
|
|
143
|
-
}
|
|
144
|
-
}
|
package/src/utils/timestamps.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Timestamp utilities for Advanced Logger
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { TIME_UNITS } from '../constants.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Formats the timestamp using modern Date API
|
|
9
|
-
*/
|
|
10
|
-
export function formatTimestamp(): string {
|
|
11
|
-
try {
|
|
12
|
-
// Use modern Temporal API if available, fallback to Date
|
|
13
|
-
const now = new Date();
|
|
14
|
-
return now.toISOString();
|
|
15
|
-
} catch {
|
|
16
|
-
return new Date().toISOString();
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Parse relative time strings like "2h", "30m", "1d" into milliseconds
|
|
22
|
-
*/
|
|
23
|
-
export function parseRelativeTime(timeStr: string): number {
|
|
24
|
-
const match = timeStr.match(/^(\d+)(ms|s|m|h|d)$/);
|
|
25
|
-
if (!match) {
|
|
26
|
-
throw new Error(`Invalid time format: ${timeStr}. Use format like "2h", "30m", "1d"`);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const [, amount, unit] = match;
|
|
30
|
-
const multiplier = TIME_UNITS[unit as keyof typeof TIME_UNITS];
|
|
31
|
-
|
|
32
|
-
return parseInt(amount || '0', 10) * multiplier;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Parse time input which can be Date, ISO string, or relative time
|
|
37
|
-
*/
|
|
38
|
-
export function parseTimeInput(input: Date | string | number): Date {
|
|
39
|
-
if (input instanceof Date) {
|
|
40
|
-
return input;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (typeof input === 'number') {
|
|
44
|
-
// Assume hours ago
|
|
45
|
-
return new Date(Date.now() - input * TIME_UNITS.h);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (typeof input === 'string') {
|
|
49
|
-
// Try parsing as ISO date first
|
|
50
|
-
const isoDate = new Date(input);
|
|
51
|
-
if (!isNaN(isoDate.getTime())) {
|
|
52
|
-
return isoDate;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Try parsing as relative time
|
|
56
|
-
try {
|
|
57
|
-
const ms = parseRelativeTime(input);
|
|
58
|
-
return new Date(Date.now() - ms);
|
|
59
|
-
} catch {
|
|
60
|
-
throw new Error(`Invalid time format: ${input}`);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
throw new Error(`Unsupported time input type: ${typeof input}`);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Format timestamp for display in different contexts
|
|
69
|
-
*/
|
|
70
|
-
export function formatDisplayTime(date: Date, format: 'short' | 'full' | 'time-only' = 'short'): string {
|
|
71
|
-
switch (format) {
|
|
72
|
-
case 'time-only':
|
|
73
|
-
return date.toTimeString().slice(0, 8); // HH:MM:SS
|
|
74
|
-
case 'full':
|
|
75
|
-
return date.toISOString();
|
|
76
|
-
case 'short':
|
|
77
|
-
default:
|
|
78
|
-
return date.toISOString().slice(11, 23); // HH:MM:SS.mmm
|
|
79
|
-
}
|
|
80
|
-
}
|
package/src/vite-env.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/// <reference types="vite/client" />
|