@mks2508/better-logger 0.14.0-alpha.2 → 1.1.0
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 +2 -1
- package/dist/Logger.d.ts +12 -16
- package/dist/Logger.d.ts.map +1 -1
- package/dist/ScopedLogger.d.ts +1 -9
- package/dist/chunks/{Logger-D_p3xnbq.js → Logger-C9zTFYBh.js} +2 -2
- package/dist/chunks/Logger-C9zTFYBh.js.map +1 -0
- package/dist/chunks/{Logger-Crw1woqR.js → Logger-Th9SfADL.js} +50 -17
- package/dist/chunks/Logger-Th9SfADL.js.map +1 -0
- package/dist/chunks/ScopedLogger-HgV_J-ug.js +2 -0
- package/dist/chunks/ScopedLogger-HgV_J-ug.js.map +1 -0
- package/dist/chunks/ScopedLogger-uAAeJkfA.js +361 -0
- package/dist/chunks/ScopedLogger-uAAeJkfA.js.map +1 -0
- package/dist/chunks/environment-5I5unY89.js +4 -0
- package/dist/chunks/environment-5I5unY89.js.map +1 -0
- package/dist/chunks/{environment-Bxbnw4pd.js → environment-wXLQvk5g.js} +103 -11
- package/dist/chunks/environment-wXLQvk5g.js.map +1 -0
- package/dist/chunks/formatting-CiFnwe1I.js +2 -0
- package/dist/chunks/formatting-CiFnwe1I.js.map +1 -0
- package/dist/chunks/formatting-DIhpRCCk.js +380 -0
- package/dist/chunks/formatting-DIhpRCCk.js.map +1 -0
- package/dist/cli/CommandProcessor.d.ts +1 -4
- package/dist/cli/commands/ConfigCommand.d.ts +2 -5
- package/dist/cli/commands/ExportCommand.d.ts +2 -5
- package/dist/cli/commands/HistoryCommand.d.ts +2 -5
- package/dist/cli/commands/StatusCommand.d.ts +2 -5
- package/dist/cli/commands/ThemeCommand.d.ts +2 -5
- package/dist/cli/help.d.ts +2 -5
- package/dist/cli/index.d.ts +1 -1
- package/dist/constants.d.ts +110 -5
- package/dist/constants.d.ts.map +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +1 -8
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +281 -307
- package/dist/core.js.map +1 -1
- package/dist/exports-module.d.ts +1 -8
- package/dist/exports.cjs +1 -1
- package/dist/exports.js +2 -2
- package/dist/handlers/AnalyticsLogHandler.d.ts +1 -4
- package/dist/handlers/ExportLogHandler.d.ts +1 -4
- package/dist/handlers/ExportLogHandler.d.ts.map +1 -1
- package/dist/handlers/FileLogHandler.d.ts +1 -4
- package/dist/handlers/RemoteLogHandler.d.ts +1 -4
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -41
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +246 -159
- package/dist/index.js.map +1 -1
- package/dist/styling/LogStyleBuilder.d.ts +2 -5
- package/dist/styling/SemanticStyles.d.ts +0 -3
- package/dist/styling/SmartPresets.d.ts +1 -4
- package/dist/styling/banners.d.ts +1 -4
- package/dist/styling/themes.d.ts +2 -5
- package/dist/styling-module.d.ts +1 -8
- package/dist/styling.cjs +1 -1
- package/dist/styling.js +3 -3
- package/dist/types/core.d.ts +13 -0
- package/dist/types/core.d.ts.map +1 -1
- package/dist/types/handlers.d.ts +1 -4
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/ansi-colors.d.ts +156 -0
- package/dist/utils/ansi-colors.d.ts.map +1 -0
- package/dist/utils/formatting.d.ts +20 -2
- package/dist/utils/formatting.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/output.d.ts +1 -4
- package/dist/utils/stackTrace.d.ts +1 -4
- package/package.json +2 -1
- package/src/Logger.ts +102 -64
- package/src/constants.ts +131 -1
- package/src/core.ts +11 -7
- package/src/handlers/ExportLogHandler.ts +2 -1
- package/src/index.ts +62 -27
- package/src/styling/SemanticStyles.ts +1 -1
- package/src/types/core.ts +15 -1
- package/src/types/index.ts +1 -0
- package/src/utils/ansi-colors.ts +333 -0
- package/src/utils/formatting.ts +196 -6
- package/src/utils/index.ts +23 -11
- package/vite.config.ts +1 -1
- package/dist/.tsbuildinfo +0 -1
- package/dist/Logger.js +0 -1124
- package/dist/ScopedLogger.js +0 -426
- package/dist/chunks/Logger-Crw1woqR.js.map +0 -1
- package/dist/chunks/Logger-D_p3xnbq.js.map +0 -1
- package/dist/chunks/environment-Bxbnw4pd.js.map +0 -1
- package/dist/chunks/environment-Dm66zOML.js +0 -4
- package/dist/chunks/environment-Dm66zOML.js.map +0 -1
- package/dist/chunks/formatting-C0riPC5_.js +0 -95
- package/dist/chunks/formatting-C0riPC5_.js.map +0 -1
- package/dist/chunks/formatting-DNCAV66-.js +0 -2
- package/dist/chunks/formatting-DNCAV66-.js.map +0 -1
- package/dist/cli/CommandProcessor.js +0 -184
- package/dist/cli/commands/ConfigCommand.js +0 -88
- package/dist/cli/commands/ExportCommand.js +0 -243
- package/dist/cli/commands/HistoryCommand.js +0 -96
- package/dist/cli/commands/StatusCommand.js +0 -93
- package/dist/cli/commands/ThemeCommand.js +0 -79
- package/dist/cli/help.js +0 -118
- package/dist/cli/index.js +0 -46
- package/dist/constants.js +0 -159
- package/dist/example.js +0 -154
- package/dist/exports-module.js +0 -260
- package/dist/handlers/AnalyticsLogHandler.js +0 -19
- package/dist/handlers/ExportLogHandler.js +0 -516
- package/dist/handlers/FileLogHandler.js +0 -156
- package/dist/handlers/RemoteLogHandler.js +0 -37
- package/dist/handlers/index.js +0 -7
- package/dist/main.js +0 -139
- package/dist/styling/LogStyleBuilder.js +0 -289
- package/dist/styling/SemanticStyles.js +0 -339
- package/dist/styling/SmartPresets.js +0 -276
- package/dist/styling/StyleBuilder.js +0 -280
- package/dist/styling/banners.js +0 -155
- package/dist/styling/index.js +0 -9
- package/dist/styling/themes.js +0 -231
- package/dist/styling-module.js +0 -199
- package/dist/types/Logger.d.ts +0 -700
- package/dist/types/Logger.d.ts.map +0 -1
- package/dist/types/ScopedLogger.d.ts +0 -310
- package/dist/types/ScopedLogger.d.ts.map +0 -1
- package/dist/types/cli/CommandProcessor.d.ts +0 -100
- package/dist/types/cli/CommandProcessor.d.ts.map +0 -1
- package/dist/types/cli/commands/ConfigCommand.d.ts +0 -14
- package/dist/types/cli/commands/ConfigCommand.d.ts.map +0 -1
- package/dist/types/cli/commands/ExportCommand.d.ts +0 -48
- package/dist/types/cli/commands/ExportCommand.d.ts.map +0 -1
- package/dist/types/cli/commands/HistoryCommand.d.ts +0 -47
- package/dist/types/cli/commands/HistoryCommand.d.ts.map +0 -1
- package/dist/types/cli/commands/StatusCommand.d.ts +0 -30
- package/dist/types/cli/commands/StatusCommand.d.ts.map +0 -1
- package/dist/types/cli/commands/ThemeCommand.d.ts +0 -30
- package/dist/types/cli/commands/ThemeCommand.d.ts.map +0 -1
- package/dist/types/cli/help.d.ts +0 -12
- package/dist/types/cli/help.d.ts.map +0 -1
- package/dist/types/cli/index.d.ts +0 -15
- package/dist/types/cli/index.d.ts.map +0 -1
- package/dist/types/constants.d.ts +0 -119
- package/dist/types/constants.d.ts.map +0 -1
- package/dist/types/core.js +0 -28
- package/dist/types/example.d.ts +0 -18
- package/dist/types/example.d.ts.map +0 -1
- package/dist/types/exports-module.d.ts +0 -196
- package/dist/types/exports-module.d.ts.map +0 -1
- package/dist/types/handlers/AnalyticsLogHandler.d.ts +0 -8
- package/dist/types/handlers/AnalyticsLogHandler.d.ts.map +0 -1
- package/dist/types/handlers/ExportLogHandler.d.ts +0 -100
- package/dist/types/handlers/ExportLogHandler.d.ts.map +0 -1
- package/dist/types/handlers/FileLogHandler.d.ts +0 -33
- package/dist/types/handlers/FileLogHandler.d.ts.map +0 -1
- package/dist/types/handlers/RemoteLogHandler.d.ts +0 -11
- package/dist/types/handlers/RemoteLogHandler.d.ts.map +0 -1
- package/dist/types/handlers/index.d.ts +0 -8
- package/dist/types/handlers/index.d.ts.map +0 -1
- package/dist/types/handlers.js +0 -4
- package/dist/types/index.js +0 -4
- package/dist/types/main.d.ts +0 -2
- package/dist/types/main.d.ts.map +0 -1
- package/dist/types/styling/LogStyleBuilder.d.ts +0 -146
- package/dist/types/styling/LogStyleBuilder.d.ts.map +0 -1
- package/dist/types/styling/SemanticStyles.d.ts +0 -178
- package/dist/types/styling/SemanticStyles.d.ts.map +0 -1
- package/dist/types/styling/SmartPresets.d.ts +0 -22
- package/dist/types/styling/SmartPresets.d.ts.map +0 -1
- package/dist/types/styling/StyleBuilder.d.ts +0 -140
- package/dist/types/styling/StyleBuilder.d.ts.map +0 -1
- package/dist/types/styling/banners.d.ts +0 -42
- package/dist/types/styling/banners.d.ts.map +0 -1
- package/dist/types/styling/index.d.ts +0 -10
- package/dist/types/styling/index.d.ts.map +0 -1
- package/dist/types/styling/themes.d.ts +0 -7
- package/dist/types/styling/themes.d.ts.map +0 -1
- package/dist/types/styling-module.d.ts +0 -178
- package/dist/types/styling-module.d.ts.map +0 -1
- package/dist/types/types/core.d.ts +0 -221
- package/dist/types/types/core.d.ts.map +0 -1
- package/dist/types/types/handlers.d.ts +0 -85
- package/dist/types/types/handlers.d.ts.map +0 -1
- package/dist/types/types/index.d.ts +0 -7
- package/dist/types/types/index.d.ts.map +0 -1
- package/dist/types/utils/environment.d.ts +0 -47
- package/dist/types/utils/environment.d.ts.map +0 -1
- package/dist/types/utils/formatting.d.ts +0 -37
- package/dist/types/utils/formatting.d.ts.map +0 -1
- package/dist/types/utils/index.d.ts +0 -7
- package/dist/types/utils/index.d.ts.map +0 -1
- package/dist/types/utils/opentui-detection.d.ts +0 -34
- package/dist/types/utils/opentui-detection.d.ts.map +0 -1
- package/dist/types/utils/output.d.ts +0 -41
- package/dist/types/utils/output.d.ts.map +0 -1
- package/dist/types/utils/stackTrace.d.ts +0 -6
- package/dist/types/utils/stackTrace.d.ts.map +0 -1
- package/dist/types/utils/timestamps.d.ts +0 -20
- package/dist/types/utils/timestamps.d.ts.map +0 -1
- package/dist/utils/environment.js +0 -85
- package/dist/utils/formatting.js +0 -117
- package/dist/utils/index.js +0 -6
- package/dist/utils/opentui-detection.js +0 -116
- package/dist/utils/output.js +0 -150
- package/dist/utils/stackTrace.js +0 -81
- package/dist/utils/timestamps.js +0 -71
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { LogLevel, StackInfo, DevToolsTheme, AdaptiveColors } from '../types/index.js';
|
|
2
|
-
/**
|
|
3
|
-
* Style configuration for each log level
|
|
4
|
-
*/
|
|
5
|
-
export interface LevelStyleConfig {
|
|
6
|
-
emoji: string;
|
|
7
|
-
label: string;
|
|
8
|
-
background: string;
|
|
9
|
-
color: string;
|
|
10
|
-
border: string;
|
|
11
|
-
shadow: string;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Detects the current DevTools theme preference
|
|
15
|
-
*/
|
|
16
|
-
export declare function detectDevToolsTheme(): DevToolsTheme;
|
|
17
|
-
/**
|
|
18
|
-
* Gets adaptive color based on current DevTools theme
|
|
19
|
-
*/
|
|
20
|
-
export declare function getAdaptiveColor(colors: AdaptiveColors, theme?: DevToolsTheme): string;
|
|
21
|
-
/**
|
|
22
|
-
* Sets up theme change listener for dynamic updates
|
|
23
|
-
*/
|
|
24
|
-
export declare function setupThemeChangeListener(callback: (theme: DevToolsTheme) => void): (() => void) | null;
|
|
25
|
-
/**
|
|
26
|
-
* Creates styled console output with multiple %c formatters
|
|
27
|
-
*/
|
|
28
|
-
export declare function createStyledOutput(level: LogLevel, levelStyles: Record<LogLevel | 'success', LevelStyleConfig>, prefix: string | undefined, message: string, stackInfo: StackInfo | null, autoDetectTheme?: boolean): [string, ...string[]];
|
|
29
|
-
/**
|
|
30
|
-
* Create a unique ID for log entries
|
|
31
|
-
*/
|
|
32
|
-
export declare function generateLogId(): string;
|
|
33
|
-
/**
|
|
34
|
-
* Escape HTML entities for safe HTML output
|
|
35
|
-
*/
|
|
36
|
-
export declare function escapeHtml(text: string): string;
|
|
37
|
-
/**
|
|
38
|
-
* Convert objects to safe string representation for logging
|
|
39
|
-
*/
|
|
40
|
-
export declare function safeStringify(obj: any, _maxDepth?: number): string;
|
|
41
|
-
//# sourceMappingURL=output.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../../src/utils/output.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAK5F;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,aAAa,CAYnD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,cAAc,EAAE,KAAK,CAAC,EAAE,aAAa,GAAG,MAAM,CAGtF;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAyBtG;AAGD;;GAEG;AACH,wBAAgB,kBAAkB,CAC9B,KAAK,EAAE,QAAQ,EACf,WAAW,EAAE,MAAM,CAAC,QAAQ,GAAG,SAAS,EAAE,gBAAgB,CAAC,EAC3D,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,SAAS,GAAG,IAAI,EAC3B,eAAe,GAAE,OAAc,GAChC,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAgEvB;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAI/C;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,SAAS,SAAI,GAAG,MAAM,CAY7D"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stackTrace.d.ts","sourceRoot":"","sources":["../../../src/utils/stackTrace.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD;;GAEG;AACH,wBAAgB,eAAe,IAAI,SAAS,GAAG,IAAI,CAqFlD"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Timestamp utilities for Advanced Logger
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Formats the timestamp using modern Date API
|
|
6
|
-
*/
|
|
7
|
-
export declare function formatTimestamp(): string;
|
|
8
|
-
/**
|
|
9
|
-
* Parse relative time strings like "2h", "30m", "1d" into milliseconds
|
|
10
|
-
*/
|
|
11
|
-
export declare function parseRelativeTime(timeStr: string): number;
|
|
12
|
-
/**
|
|
13
|
-
* Parse time input which can be Date, ISO string, or relative time
|
|
14
|
-
*/
|
|
15
|
-
export declare function parseTimeInput(input: Date | string | number): Date;
|
|
16
|
-
/**
|
|
17
|
-
* Format timestamp for display in different contexts
|
|
18
|
-
*/
|
|
19
|
-
export declare function formatDisplayTime(date: Date, format?: 'short' | 'full' | 'time-only'): string;
|
|
20
|
-
//# sourceMappingURL=timestamps.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"timestamps.d.ts","sourceRoot":"","sources":["../../../src/utils/timestamps.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;GAEG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAQxC;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAUzD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CA2BlE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,GAAE,OAAO,GAAG,MAAM,GAAG,WAAqB,GAAG,MAAM,CAUtG"}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Environment detection utilities for Universal Logger
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Checks if running in Node.js environment
|
|
6
|
-
*/
|
|
7
|
-
export const isNode = typeof process !== 'undefined' &&
|
|
8
|
-
process.versions &&
|
|
9
|
-
process.versions.node;
|
|
10
|
-
/**
|
|
11
|
-
* Checks if running in browser environment
|
|
12
|
-
*/
|
|
13
|
-
export const isBrowser = typeof window !== 'undefined' &&
|
|
14
|
-
typeof document !== 'undefined';
|
|
15
|
-
/**
|
|
16
|
-
* Checks if running in web worker environment
|
|
17
|
-
*/
|
|
18
|
-
export const isWebWorker = typeof self !== 'undefined' &&
|
|
19
|
-
typeof self.importScripts === 'function';
|
|
20
|
-
/**
|
|
21
|
-
* Checks if running in Deno environment
|
|
22
|
-
*/
|
|
23
|
-
export const isDeno = typeof globalThis !== 'undefined' &&
|
|
24
|
-
'Deno' in globalThis;
|
|
25
|
-
/**
|
|
26
|
-
* Gets the current runtime environment
|
|
27
|
-
*/
|
|
28
|
-
export function getRuntimeEnvironment() {
|
|
29
|
-
if (isNode)
|
|
30
|
-
return 'node';
|
|
31
|
-
if (isBrowser)
|
|
32
|
-
return 'browser';
|
|
33
|
-
if (isWebWorker)
|
|
34
|
-
return 'webworker';
|
|
35
|
-
if (isDeno)
|
|
36
|
-
return 'deno';
|
|
37
|
-
return 'unknown';
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Checks if colors/styling should be supported in current environment
|
|
41
|
-
*/
|
|
42
|
-
export function supportsColors() {
|
|
43
|
-
if (isBrowser) {
|
|
44
|
-
// Browser always supports CSS colors
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
if (isNode) {
|
|
48
|
-
// Check if Node.js supports colors
|
|
49
|
-
return process.stdout?.isTTY === true ||
|
|
50
|
-
process.env.FORCE_COLOR === '1' ||
|
|
51
|
-
process.env.FORCE_COLOR === 'true';
|
|
52
|
-
}
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Checks if CSS styling is supported (browser-only feature)
|
|
57
|
-
*/
|
|
58
|
-
export function supportsCSSColors() {
|
|
59
|
-
return isBrowser;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Checks if ANSI colors are supported (terminal environments)
|
|
63
|
-
*/
|
|
64
|
-
export function supportsANSIColors() {
|
|
65
|
-
if (isNode) {
|
|
66
|
-
return process.stdout?.isTTY === true ||
|
|
67
|
-
process.env.FORCE_COLOR === '1' ||
|
|
68
|
-
process.env.FORCE_COLOR === 'true';
|
|
69
|
-
}
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Gets environment-specific information
|
|
74
|
-
*/
|
|
75
|
-
export function getEnvironmentInfo() {
|
|
76
|
-
const env = getRuntimeEnvironment();
|
|
77
|
-
return {
|
|
78
|
-
runtime: env,
|
|
79
|
-
supportsColors: supportsColors(),
|
|
80
|
-
supportsCSSColors: supportsCSSColors(),
|
|
81
|
-
supportsANSIColors: supportsANSIColors(),
|
|
82
|
-
isProduction: isNode ? process.env.NODE_ENV === 'production' : false,
|
|
83
|
-
version: isNode ? process.versions.node : (isBrowser ? navigator.userAgent : 'unknown')
|
|
84
|
-
};
|
|
85
|
-
}
|
package/dist/utils/formatting.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Formatting utilities for Universal Logger
|
|
3
|
-
*/
|
|
4
|
-
import { formatTimestamp } from './timestamps.js';
|
|
5
|
-
/**
|
|
6
|
-
* Creates plain text output for any environment
|
|
7
|
-
* No colors, no styling - maximum compatibility
|
|
8
|
-
*/
|
|
9
|
-
export function createPlainOutput(level, message, prefix, stackInfo) {
|
|
10
|
-
const timestamp = formatTimestamp();
|
|
11
|
-
const timeStr = timestamp.slice(11, 23); // HH:MM:SS.mmm
|
|
12
|
-
let output = `[${timeStr}] [${level.toUpperCase()}]`;
|
|
13
|
-
if (prefix) {
|
|
14
|
-
output += ` [${prefix}]`;
|
|
15
|
-
}
|
|
16
|
-
output += ` ${message}`;
|
|
17
|
-
if (stackInfo) {
|
|
18
|
-
output += ` (${stackInfo.file}:${stackInfo.line}:${stackInfo.column})`;
|
|
19
|
-
}
|
|
20
|
-
return output;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Gets the appropriate log method for the level
|
|
24
|
-
* Uses different console methods for better semantics
|
|
25
|
-
*/
|
|
26
|
-
export function getConsoleMethod(level) {
|
|
27
|
-
switch (level) {
|
|
28
|
-
case 'debug':
|
|
29
|
-
return 'log';
|
|
30
|
-
case 'info':
|
|
31
|
-
return 'info';
|
|
32
|
-
case 'warn':
|
|
33
|
-
return 'warn';
|
|
34
|
-
case 'error':
|
|
35
|
-
case 'critical':
|
|
36
|
-
return 'error';
|
|
37
|
-
default:
|
|
38
|
-
return 'log';
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Create a simple log entry object for handlers
|
|
43
|
-
*/
|
|
44
|
-
export function createLogEntry(level, message, args, prefix, stackInfo) {
|
|
45
|
-
return {
|
|
46
|
-
timestamp: formatTimestamp(),
|
|
47
|
-
level: level.toUpperCase(),
|
|
48
|
-
prefix,
|
|
49
|
-
message,
|
|
50
|
-
args: args.slice(1), // Exclude the first message argument
|
|
51
|
-
location: stackInfo ? {
|
|
52
|
-
file: stackInfo.file,
|
|
53
|
-
line: stackInfo.line,
|
|
54
|
-
column: stackInfo.column,
|
|
55
|
-
function: stackInfo.function
|
|
56
|
-
} : undefined,
|
|
57
|
-
raw: args
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Format data for table display in plain text
|
|
62
|
-
*/
|
|
63
|
-
export function formatTablePlain(data, columns) {
|
|
64
|
-
try {
|
|
65
|
-
if (Array.isArray(data)) {
|
|
66
|
-
if (data.length === 0)
|
|
67
|
-
return '[Empty Array]';
|
|
68
|
-
// Simple array formatting
|
|
69
|
-
if (typeof data[0] !== 'object') {
|
|
70
|
-
return data.map((item, i) => `${i}: ${item}`).join('\n');
|
|
71
|
-
}
|
|
72
|
-
// Object array formatting
|
|
73
|
-
const keys = columns || Object.keys(data[0] || {});
|
|
74
|
-
const header = keys.join('\t');
|
|
75
|
-
const rows = data.map(item => keys.map(key => String(item[key] || '')).join('\t'));
|
|
76
|
-
return [header, ...rows].join('\n');
|
|
77
|
-
}
|
|
78
|
-
if (typeof data === 'object' && data !== null) {
|
|
79
|
-
// Simple object formatting
|
|
80
|
-
return Object.entries(data)
|
|
81
|
-
.map(([key, value]) => `${key}: ${value}`)
|
|
82
|
-
.join('\n');
|
|
83
|
-
}
|
|
84
|
-
return String(data);
|
|
85
|
-
}
|
|
86
|
-
catch (error) {
|
|
87
|
-
return `[Error formatting table: ${error}]`;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Safe object serialization for logging
|
|
92
|
-
*/
|
|
93
|
-
export function safeSerialize(obj, maxDepth = 3, currentDepth = 0) {
|
|
94
|
-
if (currentDepth >= maxDepth) {
|
|
95
|
-
return '[Max Depth Reached]';
|
|
96
|
-
}
|
|
97
|
-
if (obj === null)
|
|
98
|
-
return null;
|
|
99
|
-
if (obj === undefined)
|
|
100
|
-
return '[undefined]';
|
|
101
|
-
if (typeof obj === 'function')
|
|
102
|
-
return '[Function]';
|
|
103
|
-
if (obj instanceof Error)
|
|
104
|
-
return `[Error: ${obj.message}]`;
|
|
105
|
-
if (obj instanceof Date)
|
|
106
|
-
return obj.toISOString();
|
|
107
|
-
if (typeof obj !== 'object')
|
|
108
|
-
return obj;
|
|
109
|
-
if (Array.isArray(obj)) {
|
|
110
|
-
return obj.map(item => safeSerialize(item, maxDepth, currentDepth + 1));
|
|
111
|
-
}
|
|
112
|
-
const result = {};
|
|
113
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
114
|
-
result[key] = safeSerialize(value, maxDepth, currentDepth + 1);
|
|
115
|
-
}
|
|
116
|
-
return result;
|
|
117
|
-
}
|
package/dist/utils/index.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Utility functions exports for Advanced Logger
|
|
3
|
-
*/
|
|
4
|
-
export { parseStackTrace } from './stackTrace.js';
|
|
5
|
-
export { formatTimestamp, parseRelativeTime, parseTimeInput, formatDisplayTime } from './timestamps.js';
|
|
6
|
-
export { createStyledOutput, generateLogId, escapeHtml, safeStringify, detectDevToolsTheme, getAdaptiveColor, setupThemeChangeListener } from './output.js';
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview OpenTUI detection and enhancement utilities for core logger
|
|
3
|
-
*/
|
|
4
|
-
import { isNode } from './environment.js';
|
|
5
|
-
/**
|
|
6
|
-
* Check if OpenTUI packages are available
|
|
7
|
-
*/
|
|
8
|
-
export async function hasOpenTUI() {
|
|
9
|
-
if (!isNode) {
|
|
10
|
-
return false; // OpenTUI is Node.js only
|
|
11
|
-
}
|
|
12
|
-
try {
|
|
13
|
-
// Try to dynamically import OpenTUI core
|
|
14
|
-
// @ts-expect-error - Optional dependency, may not be installed
|
|
15
|
-
await import('@opentui/core');
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
catch (error) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Check if OpenTUI enhancement package is available
|
|
24
|
-
*/
|
|
25
|
-
export async function hasOpenTUILogHandler() {
|
|
26
|
-
if (!isNode) {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
try {
|
|
30
|
-
// @ts-expect-error - Optional dependency, may not be installed
|
|
31
|
-
await import('@mks2508/better-logger-nodejs-opentui');
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
catch (error) {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Dynamically enhance logger with OpenTUI if available
|
|
40
|
-
*/
|
|
41
|
-
export async function tryEnhanceWithOpenTUI(logger) {
|
|
42
|
-
try {
|
|
43
|
-
// Check if both OpenTUI and our enhancement package are available
|
|
44
|
-
const [hasCore, hasEnhancer] = await Promise.all([
|
|
45
|
-
hasOpenTUI(),
|
|
46
|
-
hasOpenTUILogHandler()
|
|
47
|
-
]);
|
|
48
|
-
if (!hasCore || !hasEnhancer) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
// Dynamically import and apply enhancement
|
|
52
|
-
// @ts-expect-error - Optional dependency, may not be installed
|
|
53
|
-
const { enhanceLoggerWithOpenTUI } = await import('@mks2508/better-logger-nodejs-opentui');
|
|
54
|
-
const enhanced = await enhanceLoggerWithOpenTUI(logger, {
|
|
55
|
-
renderer: {
|
|
56
|
-
animated: true,
|
|
57
|
-
theme: 'auto',
|
|
58
|
-
components: {
|
|
59
|
-
badges: true,
|
|
60
|
-
progressBars: false,
|
|
61
|
-
tables: false,
|
|
62
|
-
charts: false
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
return enhanced;
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
console.warn('Failed to enhance logger with OpenTUI:', error);
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Get OpenTUI environment information
|
|
75
|
-
*/
|
|
76
|
-
export async function getOpenTUIInfo() {
|
|
77
|
-
const [coreAvailable, handlerAvailable] = await Promise.all([
|
|
78
|
-
hasOpenTUI(),
|
|
79
|
-
hasOpenTUILogHandler()
|
|
80
|
-
]);
|
|
81
|
-
return {
|
|
82
|
-
available: coreAvailable && handlerAvailable,
|
|
83
|
-
coreAvailable,
|
|
84
|
-
handlerAvailable,
|
|
85
|
-
nodeVersion: isNode ? process.version : null,
|
|
86
|
-
terminalSupport: isNode ? process.stdout?.isTTY === true : false
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Auto-enhance logger with best available rendering
|
|
91
|
-
*/
|
|
92
|
-
export async function autoEnhanceLogger(logger) {
|
|
93
|
-
// Try OpenTUI first
|
|
94
|
-
const openTUIEnhanced = await tryEnhanceWithOpenTUI(logger);
|
|
95
|
-
if (openTUIEnhanced) {
|
|
96
|
-
return {
|
|
97
|
-
enhanced: true,
|
|
98
|
-
method: 'opentui',
|
|
99
|
-
info: await getOpenTUIInfo()
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
// Fallback to ANSI colors if in Node.js
|
|
103
|
-
if (isNode && process.stdout?.isTTY) {
|
|
104
|
-
return {
|
|
105
|
-
enhanced: false,
|
|
106
|
-
method: 'ansi',
|
|
107
|
-
info: { reason: 'OpenTUI not available, using ANSI colors' }
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
// Plain text fallback
|
|
111
|
-
return {
|
|
112
|
-
enhanced: false,
|
|
113
|
-
method: 'plain',
|
|
114
|
-
info: { reason: 'No enhanced rendering available' }
|
|
115
|
-
};
|
|
116
|
-
}
|
package/dist/utils/output.js
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Styled output creation utilities for Advanced Logger
|
|
3
|
-
*/
|
|
4
|
-
import { formatTimestamp } from './timestamps.js';
|
|
5
|
-
import { StyleBuilder } from '../styling/index.js';
|
|
6
|
-
import { ADAPTIVE_COLORS } from '../constants.js';
|
|
7
|
-
/**
|
|
8
|
-
* Detects the current DevTools theme preference
|
|
9
|
-
*/
|
|
10
|
-
export function detectDevToolsTheme() {
|
|
11
|
-
try {
|
|
12
|
-
if (typeof window === 'undefined' || !window.matchMedia) {
|
|
13
|
-
return 'light'; // Safe fallback for SSR or older browsers
|
|
14
|
-
}
|
|
15
|
-
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
|
16
|
-
return mediaQuery.matches ? 'dark' : 'light';
|
|
17
|
-
}
|
|
18
|
-
catch (error) {
|
|
19
|
-
console.warn('Failed to detect DevTools theme:', error);
|
|
20
|
-
return 'light'; // Fallback to light theme
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Gets adaptive color based on current DevTools theme
|
|
25
|
-
*/
|
|
26
|
-
export function getAdaptiveColor(colors, theme) {
|
|
27
|
-
const currentTheme = theme ?? detectDevToolsTheme();
|
|
28
|
-
return colors[currentTheme];
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Sets up theme change listener for dynamic updates
|
|
32
|
-
*/
|
|
33
|
-
export function setupThemeChangeListener(callback) {
|
|
34
|
-
try {
|
|
35
|
-
if (typeof window === 'undefined' || !window.matchMedia) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
|
39
|
-
const handler = (e) => {
|
|
40
|
-
callback(e.matches ? 'dark' : 'light');
|
|
41
|
-
};
|
|
42
|
-
// Use newer addEventListener if available, fallback to addListener
|
|
43
|
-
if (mediaQuery.addEventListener) {
|
|
44
|
-
mediaQuery.addEventListener('change', handler);
|
|
45
|
-
return () => mediaQuery.removeEventListener('change', handler);
|
|
46
|
-
}
|
|
47
|
-
else if (mediaQuery.addListener) {
|
|
48
|
-
mediaQuery.addListener(handler);
|
|
49
|
-
return () => mediaQuery.removeListener?.(handler);
|
|
50
|
-
}
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
console.warn('Failed to set up theme change listener:', error);
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Creates styled console output with multiple %c formatters
|
|
60
|
-
*/
|
|
61
|
-
export function createStyledOutput(level, levelStyles, prefix, message, stackInfo, autoDetectTheme = true) {
|
|
62
|
-
const levelConfig = levelStyles[level];
|
|
63
|
-
const timestamp = formatTimestamp();
|
|
64
|
-
const currentTheme = autoDetectTheme ? detectDevToolsTheme() : 'light';
|
|
65
|
-
// Base styles with adaptive colors
|
|
66
|
-
const timestampStyle = new StyleBuilder()
|
|
67
|
-
.color(getAdaptiveColor(ADAPTIVE_COLORS.timestamp, currentTheme))
|
|
68
|
-
.size('11px')
|
|
69
|
-
.font('Monaco, Consolas, monospace')
|
|
70
|
-
.build();
|
|
71
|
-
const levelStyle = new StyleBuilder()
|
|
72
|
-
.bg(levelConfig.background)
|
|
73
|
-
.color(levelConfig.color)
|
|
74
|
-
.border(levelConfig.border)
|
|
75
|
-
.shadow(levelConfig.shadow)
|
|
76
|
-
.padding('2px 8px')
|
|
77
|
-
.rounded('4px')
|
|
78
|
-
.bold()
|
|
79
|
-
.font('Monaco, Consolas, monospace')
|
|
80
|
-
.size('12px')
|
|
81
|
-
.build();
|
|
82
|
-
const prefixStyle = new StyleBuilder()
|
|
83
|
-
.bg(getAdaptiveColor(ADAPTIVE_COLORS.prefixBackground, currentTheme))
|
|
84
|
-
.color(getAdaptiveColor(ADAPTIVE_COLORS.prefix, currentTheme))
|
|
85
|
-
.padding('2px 6px')
|
|
86
|
-
.rounded('3px')
|
|
87
|
-
.bold()
|
|
88
|
-
.font('Monaco, Consolas, monospace')
|
|
89
|
-
.size('11px')
|
|
90
|
-
.build();
|
|
91
|
-
const messageStyle = new StyleBuilder()
|
|
92
|
-
.color(getAdaptiveColor(ADAPTIVE_COLORS.messageText, currentTheme))
|
|
93
|
-
.font('system-ui, -apple-system, sans-serif')
|
|
94
|
-
.size('14px')
|
|
95
|
-
.build();
|
|
96
|
-
const locationStyle = new StyleBuilder()
|
|
97
|
-
.color(getAdaptiveColor(ADAPTIVE_COLORS.location, currentTheme))
|
|
98
|
-
.size('11px')
|
|
99
|
-
.font('Monaco, Consolas, monospace')
|
|
100
|
-
.build();
|
|
101
|
-
// Build format string and styles
|
|
102
|
-
let format = `%c${timestamp.slice(11, 23)} %c${levelConfig.emoji} ${levelConfig.label}`;
|
|
103
|
-
const styles = [timestampStyle, levelStyle];
|
|
104
|
-
if (prefix) {
|
|
105
|
-
format += ` %c${prefix}`;
|
|
106
|
-
styles.push(prefixStyle);
|
|
107
|
-
}
|
|
108
|
-
format += ` %c${message}`;
|
|
109
|
-
styles.push(messageStyle);
|
|
110
|
-
if (stackInfo) {
|
|
111
|
-
format += ` %c(${stackInfo.file}:${stackInfo.line}:${stackInfo.column})`;
|
|
112
|
-
styles.push(locationStyle);
|
|
113
|
-
}
|
|
114
|
-
return [format, ...styles];
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Create a unique ID for log entries
|
|
118
|
-
*/
|
|
119
|
-
export function generateLogId() {
|
|
120
|
-
return `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Escape HTML entities for safe HTML output
|
|
124
|
-
*/
|
|
125
|
-
export function escapeHtml(text) {
|
|
126
|
-
const div = document.createElement('div');
|
|
127
|
-
div.textContent = text;
|
|
128
|
-
return div.innerHTML;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Convert objects to safe string representation for logging
|
|
132
|
-
*/
|
|
133
|
-
export function safeStringify(obj, _maxDepth = 3) {
|
|
134
|
-
try {
|
|
135
|
-
return JSON.stringify(obj, (_key, value) => {
|
|
136
|
-
if (typeof value === 'function')
|
|
137
|
-
return '[Function]';
|
|
138
|
-
if (value instanceof Error)
|
|
139
|
-
return `[Error: ${value.message}]`;
|
|
140
|
-
if (value instanceof Date)
|
|
141
|
-
return value.toISOString();
|
|
142
|
-
if (typeof value === 'undefined')
|
|
143
|
-
return '[undefined]';
|
|
144
|
-
return value;
|
|
145
|
-
}, 2);
|
|
146
|
-
}
|
|
147
|
-
catch (error) {
|
|
148
|
-
return String(obj);
|
|
149
|
-
}
|
|
150
|
-
}
|
package/dist/utils/stackTrace.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Stack trace parsing utilities for Advanced Logger
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Parses the current stack trace to extract caller information
|
|
6
|
-
*/
|
|
7
|
-
export function parseStackTrace() {
|
|
8
|
-
try {
|
|
9
|
-
const stack = new Error().stack;
|
|
10
|
-
if (!stack) {
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
const lines = stack.split('\n').filter(line => line.trim());
|
|
14
|
-
// Find the first caller that's not from Logger methods
|
|
15
|
-
for (let i = 1; i < lines.length; i++) {
|
|
16
|
-
const line = lines[i];
|
|
17
|
-
if (!line) {
|
|
18
|
-
continue;
|
|
19
|
-
}
|
|
20
|
-
// Skip if line contains Logger methods or parseStackTrace
|
|
21
|
-
if (line.includes('parseStackTrace') ||
|
|
22
|
-
line.includes('Logger.') ||
|
|
23
|
-
line.includes('.log(') ||
|
|
24
|
-
line.includes('createStyledOutput')) {
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
// Parse different stack trace formats
|
|
28
|
-
let match;
|
|
29
|
-
// Chrome format: "at functionName (file:line:column)" or "at file:line:column"
|
|
30
|
-
const chromeMatch = line.match(/at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?$/);
|
|
31
|
-
if (chromeMatch) {
|
|
32
|
-
match = chromeMatch;
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
// Firefox format: "functionName@file:line:column"
|
|
36
|
-
const firefoxMatch = line.match(/(.+?)@(.+?):(\d+):(\d+)$/);
|
|
37
|
-
if (firefoxMatch) {
|
|
38
|
-
match = firefoxMatch;
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
// Safari/other formats
|
|
42
|
-
const safariMatch = line.match(/(\S+)?@(.+?):(\d+):(\d+)$/);
|
|
43
|
-
if (safariMatch) {
|
|
44
|
-
match = safariMatch;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (!match) {
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
const [, functionName, file, lineStr, columnStr] = match;
|
|
52
|
-
if (!file) {
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
// Process file path - remove query params and get filename
|
|
56
|
-
const fileParts = file.split('/');
|
|
57
|
-
const fileName = fileParts[fileParts.length - 1];
|
|
58
|
-
if (!fileName) {
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
const cleanFileName = fileName.split('?')[0];
|
|
62
|
-
// Parse line and column numbers
|
|
63
|
-
const lineNum = lineStr ? parseInt(lineStr, 10) : 0;
|
|
64
|
-
const columnNum = columnStr ? parseInt(columnStr, 10) : 0;
|
|
65
|
-
// Clean function name
|
|
66
|
-
const cleanFunction = functionName && functionName.trim()
|
|
67
|
-
? functionName.trim()
|
|
68
|
-
: undefined;
|
|
69
|
-
return {
|
|
70
|
-
file: cleanFileName ? cleanFileName : 'unknown',
|
|
71
|
-
line: lineNum,
|
|
72
|
-
column: columnNum,
|
|
73
|
-
function: cleanFunction
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
catch {
|
|
79
|
-
return null;
|
|
80
|
-
}
|
|
81
|
-
}
|