@mks2508/better-logger 1.0.0 → 1.2.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 +5 -3
- package/CHANGELOG.md +63 -0
- package/bun.lock +10 -0
- package/dist/Logger.d.ts.map +1 -0
- package/dist/ScopedLogger.d.ts.map +1 -0
- package/dist/chunks/{Logger-CTAaDeZi.js → Logger-BynuRJQf.js} +12 -6
- package/dist/chunks/Logger-BynuRJQf.js.map +1 -0
- package/dist/chunks/{Logger-D8pK7XXt.js → Logger-DMjlVQWi.js} +2 -2
- package/dist/chunks/Logger-DMjlVQWi.js.map +1 -0
- package/dist/chunks/{ScopedLogger-hS0qSkZD.js → ScopedLogger-Bl56WovH.js} +2 -2
- package/dist/chunks/{ScopedLogger-hS0qSkZD.js.map → ScopedLogger-Bl56WovH.js.map} +1 -1
- package/dist/chunks/{ScopedLogger-D-7q8uVP.js → ScopedLogger-D2HzayKH.js} +2 -2
- package/dist/chunks/{ScopedLogger-D-7q8uVP.js.map → ScopedLogger-D2HzayKH.js.map} +1 -1
- package/dist/chunks/environment--eaTrhRu.js +4 -0
- package/dist/chunks/environment--eaTrhRu.js.map +1 -0
- package/dist/chunks/environment-BanAyF-K.js +1172 -0
- package/dist/chunks/environment-BanAyF-K.js.map +1 -0
- package/dist/chunks/formatting-BSNvAxLK.js +2 -0
- package/dist/chunks/formatting-BSNvAxLK.js.map +1 -0
- package/dist/chunks/formatting-CgQSWgXR.js +380 -0
- package/dist/chunks/formatting-CgQSWgXR.js.map +1 -0
- package/dist/cli/CommandProcessor.d.ts.map +1 -0
- package/dist/cli/commands/ConfigCommand.d.ts.map +1 -0
- package/dist/cli/commands/ExportCommand.d.ts.map +1 -0
- package/dist/cli/commands/HistoryCommand.d.ts.map +1 -0
- package/dist/cli/commands/StatusCommand.d.ts.map +1 -0
- package/dist/cli/commands/ThemeCommand.d.ts.map +1 -0
- package/dist/cli/help.d.ts.map +1 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/{types/constants.d.ts → constants.d.ts} +108 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +127 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +6 -5
- package/dist/core.js.map +1 -1
- package/dist/example.d.ts.map +1 -0
- package/dist/exports-module.d.ts.map +1 -0
- package/dist/exports.cjs +1 -1
- package/dist/exports.js +2 -2
- package/dist/handlers/AnalyticsLogHandler.d.ts.map +1 -0
- package/dist/handlers/ExportLogHandler.d.ts.map +1 -0
- package/dist/handlers/FileLogHandler.d.ts.map +1 -0
- package/dist/handlers/RemoteLogHandler.d.ts.map +1 -0
- package/dist/handlers/index.d.ts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +124 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -5
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -0
- package/dist/styling/LogStyleBuilder.d.ts.map +1 -0
- package/dist/styling/SemanticStyles.d.ts.map +1 -0
- package/dist/styling/SmartPresets.d.ts.map +1 -0
- package/dist/styling/StyleBuilder.d.ts.map +1 -0
- package/dist/styling/banners.d.ts.map +1 -0
- package/dist/styling/index.d.ts.map +1 -0
- package/dist/styling/themes.d.ts.map +1 -0
- package/dist/styling-module.d.ts.map +1 -0
- package/dist/styling.cjs +1 -1
- package/dist/styling.js +3 -3
- package/dist/terminal/terminal-renderer.d.ts +63 -0
- package/dist/terminal/terminal-renderer.d.ts.map +1 -0
- package/dist/types/core.d.ts +229 -122
- package/dist/types/core.d.ts.map +1 -1
- package/dist/types/handlers.d.ts.map +1 -0
- package/dist/types/index.d.ts +4 -119
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/adapter.d.ts +48 -0
- package/dist/utils/adapter.d.ts.map +1 -0
- package/dist/utils/ansi-colors.d.ts +156 -0
- package/dist/utils/ansi-colors.d.ts.map +1 -0
- package/dist/utils/environment-detector.d.ts +35 -0
- package/dist/utils/environment-detector.d.ts.map +1 -0
- package/dist/{types/utils → utils}/environment.d.ts +1 -1
- package/dist/utils/environment.d.ts.map +1 -0
- package/dist/{types/utils → utils}/formatting.d.ts +22 -1
- package/dist/utils/formatting.d.ts.map +1 -0
- package/dist/{types/utils → utils}/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/opentui-detection.d.ts.map +1 -0
- package/dist/{types/utils → utils}/output.d.ts +7 -2
- package/dist/utils/output.d.ts.map +1 -0
- package/dist/utils/stackTrace.d.ts.map +1 -0
- package/dist/utils/timestamps.d.ts.map +1 -0
- package/package.json +10 -2
- package/src/Logger.ts +24 -19
- package/src/constants.ts +131 -1
- package/src/core.ts +11 -7
- package/src/handlers/ExportLogHandler.ts +2 -1
- package/src/index.ts +30 -2
- package/src/styling/SemanticStyles.ts +1 -1
- package/src/terminal/terminal-renderer.ts +339 -0
- package/src/types/core.ts +15 -1
- package/src/types/index.ts +1 -0
- package/src/utils/adapter.ts +291 -0
- package/src/utils/ansi-colors.ts +333 -0
- package/src/utils/environment-detector.ts +148 -0
- package/src/utils/formatting.ts +196 -6
- package/src/utils/index.ts +23 -11
- package/src/utils/output.ts +43 -1
- package/vite.config.ts +1 -1
- package/dist/chunks/Logger-CTAaDeZi.js.map +0 -1
- package/dist/chunks/Logger-D8pK7XXt.js.map +0 -1
- package/dist/chunks/environment-Bxbnw4pd.js +0 -544
- 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/types/Logger.d.ts.map +0 -1
- package/dist/types/ScopedLogger.d.ts.map +0 -1
- package/dist/types/cli/CommandProcessor.d.ts.map +0 -1
- package/dist/types/cli/commands/ConfigCommand.d.ts.map +0 -1
- package/dist/types/cli/commands/ExportCommand.d.ts.map +0 -1
- package/dist/types/cli/commands/HistoryCommand.d.ts.map +0 -1
- package/dist/types/cli/commands/StatusCommand.d.ts.map +0 -1
- package/dist/types/cli/commands/ThemeCommand.d.ts.map +0 -1
- package/dist/types/cli/help.d.ts.map +0 -1
- package/dist/types/cli/index.d.ts.map +0 -1
- package/dist/types/constants.d.ts.map +0 -1
- package/dist/types/example.d.ts.map +0 -1
- package/dist/types/exports-module.d.ts.map +0 -1
- package/dist/types/handlers/AnalyticsLogHandler.d.ts.map +0 -1
- package/dist/types/handlers/ExportLogHandler.d.ts.map +0 -1
- package/dist/types/handlers/FileLogHandler.d.ts.map +0 -1
- package/dist/types/handlers/RemoteLogHandler.d.ts.map +0 -1
- package/dist/types/handlers/index.d.ts.map +0 -1
- package/dist/types/main.d.ts.map +0 -1
- package/dist/types/styling/LogStyleBuilder.d.ts.map +0 -1
- package/dist/types/styling/SemanticStyles.d.ts.map +0 -1
- package/dist/types/styling/SmartPresets.d.ts.map +0 -1
- package/dist/types/styling/StyleBuilder.d.ts.map +0 -1
- package/dist/types/styling/banners.d.ts.map +0 -1
- package/dist/types/styling/index.d.ts.map +0 -1
- package/dist/types/styling/themes.d.ts.map +0 -1
- 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.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.map +0 -1
- package/dist/types/utils/formatting.d.ts.map +0 -1
- package/dist/types/utils/index.d.ts.map +0 -1
- package/dist/types/utils/opentui-detection.d.ts.map +0 -1
- package/dist/types/utils/output.d.ts.map +0 -1
- package/dist/types/utils/stackTrace.d.ts.map +0 -1
- package/dist/types/utils/timestamps.d.ts.map +0 -1
- /package/dist/{types/Logger.d.ts → Logger.d.ts} +0 -0
- /package/dist/{types/ScopedLogger.d.ts → ScopedLogger.d.ts} +0 -0
- /package/dist/{types/cli → cli}/CommandProcessor.d.ts +0 -0
- /package/dist/{types/cli → cli}/commands/ConfigCommand.d.ts +0 -0
- /package/dist/{types/cli → cli}/commands/ExportCommand.d.ts +0 -0
- /package/dist/{types/cli → cli}/commands/HistoryCommand.d.ts +0 -0
- /package/dist/{types/cli → cli}/commands/StatusCommand.d.ts +0 -0
- /package/dist/{types/cli → cli}/commands/ThemeCommand.d.ts +0 -0
- /package/dist/{types/cli → cli}/help.d.ts +0 -0
- /package/dist/{types/cli → cli}/index.d.ts +0 -0
- /package/dist/{types/example.d.ts → example.d.ts} +0 -0
- /package/dist/{types/exports-module.d.ts → exports-module.d.ts} +0 -0
- /package/dist/{types/handlers → handlers}/AnalyticsLogHandler.d.ts +0 -0
- /package/dist/{types/handlers → handlers}/ExportLogHandler.d.ts +0 -0
- /package/dist/{types/handlers → handlers}/FileLogHandler.d.ts +0 -0
- /package/dist/{types/handlers → handlers}/RemoteLogHandler.d.ts +0 -0
- /package/dist/{types/handlers → handlers}/index.d.ts +0 -0
- /package/dist/{types/main.d.ts → main.d.ts} +0 -0
- /package/dist/{types/styling → styling}/LogStyleBuilder.d.ts +0 -0
- /package/dist/{types/styling → styling}/SemanticStyles.d.ts +0 -0
- /package/dist/{types/styling → styling}/SmartPresets.d.ts +0 -0
- /package/dist/{types/styling → styling}/StyleBuilder.d.ts +0 -0
- /package/dist/{types/styling → styling}/banners.d.ts +0 -0
- /package/dist/{types/styling → styling}/index.d.ts +0 -0
- /package/dist/{types/styling → styling}/themes.d.ts +0 -0
- /package/dist/{types/styling-module.d.ts → styling-module.d.ts} +0 -0
- /package/dist/types/{types/handlers.d.ts → handlers.d.ts} +0 -0
- /package/dist/{types/utils → utils}/opentui-detection.d.ts +0 -0
- /package/dist/{types/utils → utils}/stackTrace.d.ts +0 -0
- /package/dist/{types/utils → utils}/timestamps.d.ts +0 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { LogLevel } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* ANSI color codes for terminal styling
|
|
4
|
+
*/
|
|
5
|
+
export declare const ANSI_CODES: {
|
|
6
|
+
readonly black: 30;
|
|
7
|
+
readonly red: 31;
|
|
8
|
+
readonly green: 32;
|
|
9
|
+
readonly yellow: 33;
|
|
10
|
+
readonly blue: 34;
|
|
11
|
+
readonly magenta: 35;
|
|
12
|
+
readonly cyan: 36;
|
|
13
|
+
readonly white: 37;
|
|
14
|
+
readonly brightBlack: 90;
|
|
15
|
+
readonly brightRed: 91;
|
|
16
|
+
readonly brightGreen: 92;
|
|
17
|
+
readonly brightYellow: 93;
|
|
18
|
+
readonly brightBlue: 94;
|
|
19
|
+
readonly brightMagenta: 95;
|
|
20
|
+
readonly brightCyan: 96;
|
|
21
|
+
readonly brightWhite: 97;
|
|
22
|
+
readonly bgBlack: 40;
|
|
23
|
+
readonly bgRed: 41;
|
|
24
|
+
readonly bgGreen: 42;
|
|
25
|
+
readonly bgYellow: 43;
|
|
26
|
+
readonly bgBlue: 44;
|
|
27
|
+
readonly bgMagenta: 45;
|
|
28
|
+
readonly bgCyan: 46;
|
|
29
|
+
readonly bgWhite: 47;
|
|
30
|
+
readonly bgBrightBlack: 100;
|
|
31
|
+
readonly bgBrightRed: 101;
|
|
32
|
+
readonly bgBrightGreen: 102;
|
|
33
|
+
readonly bgBrightYellow: 103;
|
|
34
|
+
readonly bgBrightBlue: 104;
|
|
35
|
+
readonly bgBrightMagenta: 105;
|
|
36
|
+
readonly bgBrightCyan: 106;
|
|
37
|
+
readonly bgBrightWhite: 107;
|
|
38
|
+
readonly reset: 0;
|
|
39
|
+
readonly bold: 1;
|
|
40
|
+
readonly dim: 2;
|
|
41
|
+
readonly italic: 3;
|
|
42
|
+
readonly underline: 4;
|
|
43
|
+
readonly blink: 5;
|
|
44
|
+
readonly inverse: 7;
|
|
45
|
+
readonly hidden: 8;
|
|
46
|
+
readonly strikethrough: 9;
|
|
47
|
+
readonly resetBold: 22;
|
|
48
|
+
readonly resetDim: 22;
|
|
49
|
+
readonly resetItalic: 23;
|
|
50
|
+
readonly resetUnderline: 24;
|
|
51
|
+
readonly resetBlink: 25;
|
|
52
|
+
readonly resetInverse: 27;
|
|
53
|
+
readonly resetHidden: 28;
|
|
54
|
+
readonly resetStrikethrough: 29;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* ANSI color presets for different log levels
|
|
58
|
+
*/
|
|
59
|
+
export declare const ANSI_LEVEL_STYLES: Record<LogLevel | 'success', {
|
|
60
|
+
color: number;
|
|
61
|
+
background?: number;
|
|
62
|
+
styles: number[];
|
|
63
|
+
emoji: string;
|
|
64
|
+
}>;
|
|
65
|
+
/**
|
|
66
|
+
* Applies ANSI styling to text
|
|
67
|
+
*/
|
|
68
|
+
export declare function ansiStyle(text: string, codes: number[]): string;
|
|
69
|
+
/**
|
|
70
|
+
* Applies color to text
|
|
71
|
+
*/
|
|
72
|
+
export declare function ansiColor(text: string, color: number): string;
|
|
73
|
+
/**
|
|
74
|
+
* Applies background color to text
|
|
75
|
+
*/
|
|
76
|
+
export declare function ansiBackground(text: string, bg: number, color?: number): string;
|
|
77
|
+
/**
|
|
78
|
+
* Makes text bold
|
|
79
|
+
*/
|
|
80
|
+
export declare function ansiBold(text: string): string;
|
|
81
|
+
/**
|
|
82
|
+
* Makes text dim
|
|
83
|
+
*/
|
|
84
|
+
export declare function ansiDim(text: string): string;
|
|
85
|
+
/**
|
|
86
|
+
* Underlines text
|
|
87
|
+
*/
|
|
88
|
+
export declare function ansiUnderline(text: string): string;
|
|
89
|
+
/**
|
|
90
|
+
* Specialized formatters for different contexts
|
|
91
|
+
*/
|
|
92
|
+
/**
|
|
93
|
+
* Format timestamp for terminal
|
|
94
|
+
*/
|
|
95
|
+
export declare function formatTimestampANSI(timestamp: string): string;
|
|
96
|
+
/**
|
|
97
|
+
* Format log level for terminal
|
|
98
|
+
*/
|
|
99
|
+
export declare function formatLogLevelANSI(level: LogLevel, useEmojis?: boolean): string;
|
|
100
|
+
/**
|
|
101
|
+
* Format success message for terminal
|
|
102
|
+
*/
|
|
103
|
+
export declare function formatSuccessANSI(message: string, useEmojis?: boolean): string;
|
|
104
|
+
/**
|
|
105
|
+
* Format prefix for terminal
|
|
106
|
+
*/
|
|
107
|
+
export declare function formatPrefixANSI(prefix: string): string;
|
|
108
|
+
/**
|
|
109
|
+
* Format file location for terminal
|
|
110
|
+
*/
|
|
111
|
+
export declare function formatLocationANSI(location: string): string;
|
|
112
|
+
/**
|
|
113
|
+
* Format build-specific messages
|
|
114
|
+
*/
|
|
115
|
+
export declare const BUILD_FORMATTERS: {
|
|
116
|
+
/**
|
|
117
|
+
* Format compilation step
|
|
118
|
+
*/
|
|
119
|
+
compilation: (step: string, status?: "starting" | "completed" | "failed") => string;
|
|
120
|
+
/**
|
|
121
|
+
* Format warning message
|
|
122
|
+
*/
|
|
123
|
+
warning: (message: string) => string;
|
|
124
|
+
/**
|
|
125
|
+
* Format error message
|
|
126
|
+
*/
|
|
127
|
+
error: (message: string) => string;
|
|
128
|
+
/**
|
|
129
|
+
* Format success message
|
|
130
|
+
*/
|
|
131
|
+
success: (message: string) => string;
|
|
132
|
+
/**
|
|
133
|
+
* Format info message
|
|
134
|
+
*/
|
|
135
|
+
info: (message: string) => string;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Terminal-friendly emoji alternatives for environments that don't support them
|
|
139
|
+
*/
|
|
140
|
+
export declare const EMOJI_ALTERNATIVES: {
|
|
141
|
+
'\uD83D\uDD0D': string;
|
|
142
|
+
ℹ️: string;
|
|
143
|
+
'\u26A0\uFE0F': string;
|
|
144
|
+
'\u274C': string;
|
|
145
|
+
'\uD83D\uDEA8': string;
|
|
146
|
+
'\u2705': string;
|
|
147
|
+
'\u2713': string;
|
|
148
|
+
'\u2717': string;
|
|
149
|
+
'\u2699\uFE0F': string;
|
|
150
|
+
'\uD83D\uDCE6': string;
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Replace emojis with text alternatives for non-emoji terminals
|
|
154
|
+
*/
|
|
155
|
+
export declare function sanitizeEmojis(text: string): string;
|
|
156
|
+
//# sourceMappingURL=ansi-colors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ansi-colors.d.ts","sourceRoot":"","sources":["../../src/utils/ansi-colors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAGlD;;GAEG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6Db,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,QAAQ,GAAG,SAAS,EAAE;IACzD,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACjB,CAmCA,CAAC;AAUF;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAG/D;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAK/E;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD;AAED;;GAEG;AAEH;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,QAAQ,EAAE,SAAS,GAAE,OAAc,GAAG,MAAM,CAerF;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,GAAE,OAAc,GAAG,MAAM,CAUpF;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAMvD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAM3D;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB;IACzB;;OAEG;wBACiB,MAAM,WAAU,UAAU,GAAG,WAAW,GAAG,QAAQ;IAevE;;OAEG;uBACgB,MAAM;IAIzB;;OAEG;qBACc,MAAM;IAIvB;;OAEG;uBACgB,MAAM;IAIzB;;OAEG;oBACa,MAAM;CAGzB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;CAW9B,CAAC;AAEF;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAqBnD"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment Detector - Robust environment detection for logger
|
|
3
|
+
* Detects browser, terminal, server, and other runtime environments
|
|
4
|
+
*/
|
|
5
|
+
export type Environment = 'browser' | 'terminal' | 'server' | 'webworker' | 'deno' | 'unknown';
|
|
6
|
+
/**
|
|
7
|
+
* Main environment detection function
|
|
8
|
+
*/
|
|
9
|
+
export declare function getEnvironment(): Environment;
|
|
10
|
+
/**
|
|
11
|
+
* Check if running in an interactive terminal
|
|
12
|
+
*/
|
|
13
|
+
export declare function isRunningInTerminal(): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Check if environment supports ANSI colors
|
|
16
|
+
*/
|
|
17
|
+
export declare function supportsANSI(): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Get environment-specific color capability
|
|
20
|
+
*/
|
|
21
|
+
export declare function getColorCapability(): 'full' | 'basic' | 'none';
|
|
22
|
+
/**
|
|
23
|
+
* Environment information for debugging
|
|
24
|
+
*/
|
|
25
|
+
export declare function getEnvironmentInfo(): {
|
|
26
|
+
environment: Environment;
|
|
27
|
+
supportsANSI: boolean;
|
|
28
|
+
colorCapability: "none" | "full" | "basic";
|
|
29
|
+
isTTY: boolean;
|
|
30
|
+
platform: string;
|
|
31
|
+
nodeVersion: string | null;
|
|
32
|
+
term: string | null | undefined;
|
|
33
|
+
colorTerm: string | null | undefined;
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=environment-detector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment-detector.d.ts","sourceRoot":"","sources":["../../src/utils/environment-detector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,UAAU,GAAG,QAAQ,GAAG,WAAW,GAAG,MAAM,GAAG,SAAS,CAAC;AAE/F;;GAEG;AACH,wBAAgB,cAAc,IAAI,WAAW,CA0B5C;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CAiC7C;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,OAAO,CAQtC;AAmBD;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,GAAG,OAAO,GAAG,MAAM,CAsB9D;AAED;;GAEG;AACH,wBAAgB,kBAAkB;;;;;;;;;EAWjC"}
|
|
@@ -37,7 +37,7 @@ export declare function supportsANSIColors(): boolean;
|
|
|
37
37
|
* Gets environment-specific information
|
|
38
38
|
*/
|
|
39
39
|
export declare function getEnvironmentInfo(): {
|
|
40
|
-
runtime: "unknown" | "
|
|
40
|
+
runtime: "unknown" | "browser" | "webworker" | "deno" | "node";
|
|
41
41
|
supportsColors: boolean;
|
|
42
42
|
supportsCSSColors: boolean;
|
|
43
43
|
supportsANSIColors: boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../../src/utils/environment.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,eAAO,MAAM,MAAM,gBAEwB,CAAC;AAE5C;;GAEG;AACH,eAAO,MAAM,SAAS,SACmC,CAAC;AAE1D;;GAEG;AACH,eAAO,MAAM,WAAW,SACqD,CAAC;AAE9E;;GAEG;AACH,eAAO,MAAM,MAAM,SACuB,CAAC;AAE3C;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,GAAG,SAAS,GAAG,WAAW,GAAG,MAAM,GAAG,SAAS,CAM7F;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,OAAO,CAcxC;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,OAAO,CAQ5C;AAED;;GAEG;AACH,wBAAgB,kBAAkB;;;;;;;EAWjC"}
|
|
@@ -1,9 +1,30 @@
|
|
|
1
|
-
import { LogLevel, StackInfo } from '../types/index.js';
|
|
1
|
+
import { LogLevel, StackInfo, OutputFormat } from '../types/index.js';
|
|
2
|
+
export type { OutputFormat } from '../types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates output based on environment and format preference
|
|
5
|
+
*/
|
|
6
|
+
export declare function createOutput(level: LogLevel, message: string, prefix?: string, stackInfo?: StackInfo | null, format?: OutputFormat): string;
|
|
2
7
|
/**
|
|
3
8
|
* Creates plain text output for any environment
|
|
4
9
|
* No colors, no styling - maximum compatibility
|
|
5
10
|
*/
|
|
6
11
|
export declare function createPlainOutput(level: LogLevel, message: string, prefix?: string, stackInfo?: StackInfo | null): string;
|
|
12
|
+
/**
|
|
13
|
+
* Creates ANSI-colored output for terminals
|
|
14
|
+
*/
|
|
15
|
+
export declare function createANSIOutput(level: LogLevel, message: string, prefix?: string, stackInfo?: StackInfo | null): string;
|
|
16
|
+
/**
|
|
17
|
+
* Creates build-friendly output (optimized for Next.js builds, webpack, etc.)
|
|
18
|
+
*/
|
|
19
|
+
export declare function createBuildOutput(level: LogLevel, message: string, prefix?: string, stackInfo?: StackInfo | null): string;
|
|
20
|
+
/**
|
|
21
|
+
* Creates CI-friendly output (no emojis, simple formatting)
|
|
22
|
+
*/
|
|
23
|
+
export declare function createCIOutput(level: LogLevel, message: string, prefix?: string, stackInfo?: StackInfo | null): string;
|
|
24
|
+
/**
|
|
25
|
+
* Detects the optimal output format based on environment
|
|
26
|
+
*/
|
|
27
|
+
export declare function detectOptimalFormat(): OutputFormat;
|
|
7
28
|
/**
|
|
8
29
|
* Gets the appropriate log method for the level
|
|
9
30
|
* Uses different console methods for better semantics
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatting.d.ts","sourceRoot":"","sources":["../../src/utils/formatting.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAa3E,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;GAEG;AACH,wBAAgB,YAAY,CACxB,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,SAAS,GAAG,IAAI,EAC5B,MAAM,GAAE,YAAqB,GAC9B,MAAM,CAcR;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC7B,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,SAAS,GAAG,IAAI,GAC7B,MAAM,CAiBR;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC5B,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,SAAS,GAAG,IAAI,GAC7B,MAAM,CA0BR;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC7B,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,SAAS,GAAG,IAAI,GAC7B,MAAM,CAyCR;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC1B,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,SAAS,GAAG,IAAI,GAC7B,MAAM,CAkBR;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,YAAY,CAiClD;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,QAAQ,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAcnF;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC1B,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,GAAG,EAAE,EACX,MAAM,CAAC,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,SAAS,GAAG,IAAI;;;;;;;;;;;;;EAgB/B;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CA+BtE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,GAAE,MAAU,EAAE,YAAY,GAAE,MAAU,GAAG,GAAG,CAqB3F"}
|
|
@@ -4,4 +4,5 @@
|
|
|
4
4
|
export { parseStackTrace } from './stackTrace.js';
|
|
5
5
|
export { formatTimestamp, parseRelativeTime, parseTimeInput, formatDisplayTime } from './timestamps.js';
|
|
6
6
|
export { createStyledOutput, generateLogId, escapeHtml, safeStringify, detectDevToolsTheme, getAdaptiveColor, setupThemeChangeListener, type LevelStyleConfig } from './output.js';
|
|
7
|
+
export { createPlainOutput, createOutput, createANSIOutput, createBuildOutput, createCIOutput, detectOptimalFormat, getConsoleMethod, createLogEntry, formatTablePlain, safeSerialize } from './formatting.js';
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EACH,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,iBAAiB,EACpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACH,kBAAkB,EAClB,aAAa,EACb,UAAU,EACV,aAAa,EACb,mBAAmB,EACnB,gBAAgB,EAChB,wBAAwB,EACxB,KAAK,gBAAgB,EACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EACH,iBAAiB,EACjB,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,aAAa,EAChB,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opentui-detection.d.ts","sourceRoot":"","sources":["../../src/utils/opentui-detection.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;GAEG;AACH,wBAAsB,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC,CAanD;AAED;;GAEG;AACH,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,OAAO,CAAC,CAY7D;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CAAC,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,CAkCzE;AAED;;GAEG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC;IAC5C,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,EAAE,OAAO,CAAC;IACvB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,eAAe,EAAE,OAAO,CAAC;CAC5B,CAAC,CAaD;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC;IAC1D,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,SAAS,GAAG,MAAM,GAAG,OAAO,CAAC;IACrC,IAAI,CAAC,EAAE,GAAG,CAAC;CACd,CAAC,CA0BD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LogLevel, StackInfo, DevToolsTheme, AdaptiveColors } from '../types/index.js';
|
|
1
|
+
import { LogLevel, StackInfo, DevToolsTheme, AdaptiveColors, LogStyles } from '../types/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Style configuration for each log level
|
|
4
4
|
*/
|
|
@@ -24,8 +24,9 @@ export declare function getAdaptiveColor(colors: AdaptiveColors, theme?: DevTool
|
|
|
24
24
|
export declare function setupThemeChangeListener(callback: (theme: DevToolsTheme) => void): (() => void) | null;
|
|
25
25
|
/**
|
|
26
26
|
* Creates styled console output with multiple %c formatters
|
|
27
|
+
* Automatically adapts to browser or terminal environment
|
|
27
28
|
*/
|
|
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
|
+
export declare function createStyledOutput(level: LogLevel, levelStyles: Record<LogLevel | 'success', LevelStyleConfig>, prefix: string | undefined, message: string, stackInfo: StackInfo | null, autoDetectTheme?: boolean, presetStyles?: LogStyles, presetName?: string): [string, ...string[]];
|
|
29
30
|
/**
|
|
30
31
|
* Create a unique ID for log entries
|
|
31
32
|
*/
|
|
@@ -38,4 +39,8 @@ export declare function escapeHtml(text: string): string;
|
|
|
38
39
|
* Convert objects to safe string representation for logging
|
|
39
40
|
*/
|
|
40
41
|
export declare function safeStringify(obj: any, _maxDepth?: number): string;
|
|
42
|
+
/**
|
|
43
|
+
* Create terminal output with ANSI colors and formatting
|
|
44
|
+
*/
|
|
45
|
+
export declare function createTerminalOutput(level: LogLevel, message: string, timestamp?: string, prefix?: string, stackInfo?: StackInfo | null, presetStyles?: LogStyles, presetName?: string): [string, ...string[]];
|
|
41
46
|
//# sourceMappingURL=output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;AAM5F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD;;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;;;GAGG;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,EAC/B,YAAY,CAAC,EAAE,SAAS,EACxB,UAAU,CAAC,EAAE,MAAM,GACpB,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAwEvB;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;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAChC,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,SAAS,GAAG,IAAI,EAC5B,YAAY,CAAC,EAAE,SAAS,EACxB,UAAU,CAAC,EAAE,MAAM,GACpB,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAevB"}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mks2508/better-logger",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "Logger avanzado para consola con estilos CSS, temas adaptativos, badges automáticos, SVG, animaciones y
|
|
5
|
+
"description": "Logger avanzado para consola con estilos CSS, temas adaptativos, badges automáticos, SVG, animaciones, CLI integrado y soporte dual browser/terminal con colores ANSI",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"keywords": [
|
|
@@ -18,6 +18,11 @@
|
|
|
18
18
|
"debug",
|
|
19
19
|
"consola",
|
|
20
20
|
"registro",
|
|
21
|
+
"terminal",
|
|
22
|
+
"ansi",
|
|
23
|
+
"chalk",
|
|
24
|
+
"server",
|
|
25
|
+
"nodejs",
|
|
21
26
|
"depuración",
|
|
22
27
|
"temas",
|
|
23
28
|
"badges",
|
|
@@ -88,5 +93,8 @@
|
|
|
88
93
|
"typescript": "~5.8.3",
|
|
89
94
|
"vite": "^7.1.2",
|
|
90
95
|
"vite-plugin-dts": "^4.5.4"
|
|
96
|
+
},
|
|
97
|
+
"dependencies": {
|
|
98
|
+
"chalk": "^5.6.2"
|
|
91
99
|
}
|
|
92
100
|
}
|
package/src/Logger.ts
CHANGED
|
@@ -21,12 +21,10 @@ import type {
|
|
|
21
21
|
} from './types/index.js';
|
|
22
22
|
|
|
23
23
|
// Utility imports
|
|
24
|
-
import {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
setupThemeChangeListener
|
|
29
|
-
} from './utils/index.js';
|
|
24
|
+
import { parseStackTrace } from './utils/stackTrace.js';
|
|
25
|
+
import { formatTimestamp } from './utils/timestamps.js';
|
|
26
|
+
import { createStyledOutput, setupThemeChangeListener } from './utils/output.js';
|
|
27
|
+
import { getEnvironment } from './utils/environment-detector.js';
|
|
30
28
|
|
|
31
29
|
// Styling imports
|
|
32
30
|
import {
|
|
@@ -386,12 +384,15 @@ export class Logger {
|
|
|
386
384
|
// Apply the smart preset configuration
|
|
387
385
|
this.displaySettings.showTimestamp = presetConfig.timestamp?.show ?? true;
|
|
388
386
|
this.displaySettings.showLocation = presetConfig.location?.show ?? true;
|
|
389
|
-
|
|
387
|
+
|
|
390
388
|
// Store the preset config for use in createStyledOutput
|
|
391
389
|
(this as any)._activePreset = presetConfig;
|
|
392
390
|
(this as any)._activePresetName = name;
|
|
393
|
-
|
|
394
|
-
|
|
391
|
+
|
|
392
|
+
// Only show success message in browser to avoid verbose terminal logs
|
|
393
|
+
if (getEnvironment() === 'browser') {
|
|
394
|
+
this.success(`Applied preset: ${name}`);
|
|
395
|
+
}
|
|
395
396
|
}
|
|
396
397
|
}
|
|
397
398
|
|
|
@@ -701,12 +702,14 @@ export class Logger {
|
|
|
701
702
|
|
|
702
703
|
// Create styled output with theme detection and display settings
|
|
703
704
|
const [format, ...styles] = createStyledOutput(
|
|
704
|
-
level,
|
|
705
|
-
LEVEL_STYLES,
|
|
706
|
-
prefix,
|
|
707
|
-
message,
|
|
705
|
+
level,
|
|
706
|
+
LEVEL_STYLES,
|
|
707
|
+
prefix,
|
|
708
|
+
message,
|
|
708
709
|
this.displaySettings.showLocation ? stackInfo : null,
|
|
709
|
-
this.config.autoDetectTheme
|
|
710
|
+
this.config.autoDetectTheme,
|
|
711
|
+
(this as any)._activePreset,
|
|
712
|
+
(this as any)._activePresetName
|
|
710
713
|
);
|
|
711
714
|
|
|
712
715
|
// Add group indentation
|
|
@@ -827,12 +830,14 @@ export class Logger {
|
|
|
827
830
|
|
|
828
831
|
// Handle success as special case - use info level with success styling
|
|
829
832
|
const [format, ...styles] = createStyledOutput(
|
|
830
|
-
'info',
|
|
831
|
-
LEVEL_STYLES,
|
|
832
|
-
prefix,
|
|
833
|
-
message,
|
|
833
|
+
'info',
|
|
834
|
+
LEVEL_STYLES,
|
|
835
|
+
prefix,
|
|
836
|
+
message,
|
|
834
837
|
this.displaySettings.showLocation ? stackInfo : null,
|
|
835
|
-
this.config.autoDetectTheme
|
|
838
|
+
this.config.autoDetectTheme,
|
|
839
|
+
(this as any)._activePreset,
|
|
840
|
+
(this as any)._activePresetName
|
|
836
841
|
);
|
|
837
842
|
|
|
838
843
|
// Override with success styling
|
package/src/constants.ts
CHANGED
|
@@ -17,6 +17,7 @@ export const DEFAULT_CONFIG = {
|
|
|
17
17
|
bannerType: 'simple' as const,
|
|
18
18
|
bufferSize: 1000,
|
|
19
19
|
autoDetectTheme: true,
|
|
20
|
+
outputFormat: 'auto' as const,
|
|
20
21
|
} as const;
|
|
21
22
|
|
|
22
23
|
/**
|
|
@@ -168,4 +169,133 @@ export const ADAPTIVE_COLORS = {
|
|
|
168
169
|
light: '#718096',
|
|
169
170
|
dark: '#a0aec0',
|
|
170
171
|
},
|
|
171
|
-
} as const satisfies Record<string, AdaptiveColors>;
|
|
172
|
+
} as const satisfies Record<string, AdaptiveColors>;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Presets específicos para diferentes entornos de build
|
|
176
|
+
*/
|
|
177
|
+
export const BUILD_PRESETS = {
|
|
178
|
+
/**
|
|
179
|
+
* Configuración optimizada para Next.js builds
|
|
180
|
+
*/
|
|
181
|
+
nextjs: {
|
|
182
|
+
verbosity: 'info' as const,
|
|
183
|
+
enableColors: true,
|
|
184
|
+
enableTimestamps: false,
|
|
185
|
+
enableStackTrace: false,
|
|
186
|
+
autoDetectTheme: false,
|
|
187
|
+
outputFormat: 'build' as const,
|
|
188
|
+
},
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Configuración para Webpack builds
|
|
192
|
+
*/
|
|
193
|
+
webpack: {
|
|
194
|
+
verbosity: 'info' as const,
|
|
195
|
+
enableColors: true,
|
|
196
|
+
enableTimestamps: true,
|
|
197
|
+
enableStackTrace: false,
|
|
198
|
+
autoDetectTheme: false,
|
|
199
|
+
outputFormat: 'build' as const,
|
|
200
|
+
},
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Configuración para CI/CD environments
|
|
204
|
+
*/
|
|
205
|
+
ci: {
|
|
206
|
+
verbosity: 'info' as const,
|
|
207
|
+
enableColors: false,
|
|
208
|
+
enableTimestamps: true,
|
|
209
|
+
enableStackTrace: true,
|
|
210
|
+
autoDetectTheme: false,
|
|
211
|
+
outputFormat: 'ci' as const,
|
|
212
|
+
},
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Configuración para desarrollo terminal
|
|
216
|
+
*/
|
|
217
|
+
terminal: {
|
|
218
|
+
verbosity: 'debug' as const,
|
|
219
|
+
enableColors: true,
|
|
220
|
+
enableTimestamps: true,
|
|
221
|
+
enableStackTrace: true,
|
|
222
|
+
autoDetectTheme: false,
|
|
223
|
+
outputFormat: 'ansi' as const,
|
|
224
|
+
}
|
|
225
|
+
} as const;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Mapeo de variables de entorno a presets
|
|
229
|
+
*/
|
|
230
|
+
export const ENVIRONMENT_DETECTION = {
|
|
231
|
+
// Next.js detection
|
|
232
|
+
isNextJS: typeof process !== 'undefined' && (
|
|
233
|
+
process.env.NEXT_RUNTIME ||
|
|
234
|
+
process.env.NEXT_PUBLIC_VERCEL_ENV ||
|
|
235
|
+
(process.argv && process.argv.some(arg => arg.includes('next')))
|
|
236
|
+
),
|
|
237
|
+
|
|
238
|
+
// Webpack detection
|
|
239
|
+
isWebpack: typeof process !== 'undefined' && (
|
|
240
|
+
process.env.WEBPACK_ENV ||
|
|
241
|
+
process.env.WEBPACK_BUILD ||
|
|
242
|
+
(process.argv && process.argv.some(arg => arg.includes('webpack')))
|
|
243
|
+
),
|
|
244
|
+
|
|
245
|
+
// CI/CD detection
|
|
246
|
+
isCI: typeof process !== 'undefined' && (
|
|
247
|
+
process.env.CI ||
|
|
248
|
+
process.env.GITHUB_ACTIONS ||
|
|
249
|
+
process.env.JENKINS_URL ||
|
|
250
|
+
process.env.GITLAB_CI ||
|
|
251
|
+
process.env.TRAVIS ||
|
|
252
|
+
process.env.CIRCLECI
|
|
253
|
+
),
|
|
254
|
+
|
|
255
|
+
// Build detection
|
|
256
|
+
isBuild: typeof process !== 'undefined' && (
|
|
257
|
+
process.env.NODE_ENV === 'production' ||
|
|
258
|
+
process.env.BUILD_MODE === 'production' ||
|
|
259
|
+
(process.argv && process.argv.some(arg => arg.includes('build')))
|
|
260
|
+
),
|
|
261
|
+
|
|
262
|
+
// Terminal with ANSI support
|
|
263
|
+
isTerminal: typeof process !== 'undefined' && (
|
|
264
|
+
process.stdout?.isTTY === true &&
|
|
265
|
+
process.env.TERM !== 'dumb'
|
|
266
|
+
)
|
|
267
|
+
} as const;
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Auto-detects the best preset based on current environment
|
|
271
|
+
*/
|
|
272
|
+
export function detectEnvironmentPreset(): keyof typeof BUILD_PRESETS {
|
|
273
|
+
if (ENVIRONMENT_DETECTION.isCI) {
|
|
274
|
+
return 'ci';
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (ENVIRONMENT_DETECTION.isNextJS) {
|
|
278
|
+
return 'nextjs';
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (ENVIRONMENT_DETECTION.isWebpack) {
|
|
282
|
+
return 'webpack';
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (ENVIRONMENT_DETECTION.isTerminal) {
|
|
286
|
+
return 'terminal';
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return 'terminal'; // Default fallback
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Gets the optimal configuration for current environment
|
|
294
|
+
*/
|
|
295
|
+
export function getOptimalConfig() {
|
|
296
|
+
const preset = detectEnvironmentPreset();
|
|
297
|
+
return {
|
|
298
|
+
...DEFAULT_CONFIG,
|
|
299
|
+
...BUILD_PRESETS[preset]
|
|
300
|
+
};
|
|
301
|
+
}
|
package/src/core.ts
CHANGED
|
@@ -25,10 +25,13 @@ import {
|
|
|
25
25
|
// Universal formatting and environment detection
|
|
26
26
|
import {
|
|
27
27
|
createPlainOutput,
|
|
28
|
+
createOutput,
|
|
28
29
|
getConsoleMethod,
|
|
29
30
|
createLogEntry,
|
|
30
31
|
formatTablePlain,
|
|
31
|
-
safeSerialize
|
|
32
|
+
safeSerialize,
|
|
33
|
+
detectOptimalFormat,
|
|
34
|
+
type OutputFormat
|
|
32
35
|
} from './utils/formatting.js';
|
|
33
36
|
|
|
34
37
|
import {
|
|
@@ -75,7 +78,8 @@ export class CoreLogger {
|
|
|
75
78
|
enableColors: config.enableColors ?? (isBrowser ? true : false),
|
|
76
79
|
enableTimestamps: config.enableTimestamps ?? true,
|
|
77
80
|
enableStackTrace: config.enableStackTrace ?? false,
|
|
78
|
-
autoDetectTheme: config.autoDetectTheme ?? true
|
|
81
|
+
autoDetectTheme: config.autoDetectTheme ?? true,
|
|
82
|
+
outputFormat: config.outputFormat ?? 'auto'
|
|
79
83
|
};
|
|
80
84
|
}
|
|
81
85
|
|
|
@@ -148,7 +152,7 @@ export class CoreLogger {
|
|
|
148
152
|
const message = String(args[0] || '');
|
|
149
153
|
const stackInfo = this.config.enableStackTrace ? parseStackTrace() : null;
|
|
150
154
|
const consoleMethod = getConsoleMethod(level);
|
|
151
|
-
|
|
155
|
+
|
|
152
156
|
// Choose formatting based on environment and configuration
|
|
153
157
|
if (isBrowser && this.config.enableColors && supportsCSSColors()) {
|
|
154
158
|
// Browser with CSS styling
|
|
@@ -163,14 +167,14 @@ export class CoreLogger {
|
|
|
163
167
|
);
|
|
164
168
|
console[consoleMethod](format, ...styles, ...args.slice(1));
|
|
165
169
|
} catch (error) {
|
|
166
|
-
// Fallback to
|
|
167
|
-
const output =
|
|
170
|
+
// Fallback to universal formatting if CSS fails
|
|
171
|
+
const output = createOutput(level, message, prefix, stackInfo, this.config.outputFormat);
|
|
168
172
|
console[consoleMethod](output, ...args.slice(1));
|
|
169
173
|
}
|
|
170
174
|
} else {
|
|
171
|
-
// Node.js or browser without colors - use
|
|
175
|
+
// Node.js or browser without colors - use universal formatting
|
|
172
176
|
const groupIndent = ' '.repeat(this.groupDepth);
|
|
173
|
-
const output = groupIndent +
|
|
177
|
+
const output = groupIndent + createOutput(level, message, prefix, stackInfo, this.config.outputFormat);
|
|
174
178
|
console[consoleMethod](output, ...args.slice(1));
|
|
175
179
|
}
|
|
176
180
|
|
|
@@ -13,7 +13,8 @@ import type {
|
|
|
13
13
|
BufferStats,
|
|
14
14
|
ExportFormat
|
|
15
15
|
} from '../types/index.js';
|
|
16
|
-
import { parseTimeInput, formatDisplayTime
|
|
16
|
+
import { parseTimeInput, formatDisplayTime } from '../utils/timestamps.js';
|
|
17
|
+
import { safeStringify, escapeHtml, generateLogId } from '../utils/output.js';
|
|
17
18
|
import { BUFFER_LIMITS } from '../constants.js';
|
|
18
19
|
|
|
19
20
|
/**
|
package/src/index.ts
CHANGED
|
@@ -121,7 +121,8 @@ export type {
|
|
|
121
121
|
LoggerConfig,
|
|
122
122
|
LogMetadata,
|
|
123
123
|
StackInfo,
|
|
124
|
-
TimerEntry
|
|
124
|
+
TimerEntry,
|
|
125
|
+
OutputFormat
|
|
125
126
|
} from './types/index.js';
|
|
126
127
|
|
|
127
128
|
// Styling utilities
|
|
@@ -146,9 +147,36 @@ export { DEFAULT_CONFIG } from './constants.js';
|
|
|
146
147
|
// Utility exports
|
|
147
148
|
export {
|
|
148
149
|
parseStackTrace,
|
|
149
|
-
formatTimestamp
|
|
150
|
+
formatTimestamp,
|
|
151
|
+
detectOptimalFormat,
|
|
152
|
+
createOutput,
|
|
153
|
+
createANSIOutput,
|
|
154
|
+
createBuildOutput,
|
|
155
|
+
createCIOutput
|
|
150
156
|
} from './utils/index.js';
|
|
151
157
|
|
|
158
|
+
// ANSI color utilities
|
|
159
|
+
export {
|
|
160
|
+
ansiStyle,
|
|
161
|
+
ansiColor,
|
|
162
|
+
ansiBackground,
|
|
163
|
+
ansiBold,
|
|
164
|
+
ansiDim,
|
|
165
|
+
ansiUnderline,
|
|
166
|
+
formatLogLevelANSI,
|
|
167
|
+
formatSuccessANSI,
|
|
168
|
+
BUILD_FORMATTERS,
|
|
169
|
+
sanitizeEmojis
|
|
170
|
+
} from './utils/ansi-colors.js';
|
|
171
|
+
|
|
172
|
+
// Environment detection and presets
|
|
173
|
+
export {
|
|
174
|
+
BUILD_PRESETS,
|
|
175
|
+
ENVIRONMENT_DETECTION,
|
|
176
|
+
detectEnvironmentPreset,
|
|
177
|
+
getOptimalConfig
|
|
178
|
+
} from './constants.js';
|
|
179
|
+
|
|
152
180
|
/**
|
|
153
181
|
* Utilidades de estilo para crear estilos personalizados de consola
|
|
154
182
|
*
|