@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
package/src/utils/index.ts
CHANGED
|
@@ -3,19 +3,31 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
export { parseStackTrace } from './stackTrace.js';
|
|
6
|
-
export {
|
|
7
|
-
formatTimestamp,
|
|
8
|
-
parseRelativeTime,
|
|
9
|
-
parseTimeInput,
|
|
10
|
-
formatDisplayTime
|
|
6
|
+
export {
|
|
7
|
+
formatTimestamp,
|
|
8
|
+
parseRelativeTime,
|
|
9
|
+
parseTimeInput,
|
|
10
|
+
formatDisplayTime
|
|
11
11
|
} from './timestamps.js';
|
|
12
|
-
export {
|
|
13
|
-
createStyledOutput,
|
|
14
|
-
generateLogId,
|
|
15
|
-
escapeHtml,
|
|
12
|
+
export {
|
|
13
|
+
createStyledOutput,
|
|
14
|
+
generateLogId,
|
|
15
|
+
escapeHtml,
|
|
16
16
|
safeStringify,
|
|
17
17
|
detectDevToolsTheme,
|
|
18
18
|
getAdaptiveColor,
|
|
19
19
|
setupThemeChangeListener,
|
|
20
|
-
type LevelStyleConfig
|
|
21
|
-
} from './output.js';
|
|
20
|
+
type LevelStyleConfig
|
|
21
|
+
} from './output.js';
|
|
22
|
+
export {
|
|
23
|
+
createPlainOutput,
|
|
24
|
+
createOutput,
|
|
25
|
+
createANSIOutput,
|
|
26
|
+
createBuildOutput,
|
|
27
|
+
createCIOutput,
|
|
28
|
+
detectOptimalFormat,
|
|
29
|
+
getConsoleMethod,
|
|
30
|
+
createLogEntry,
|
|
31
|
+
formatTablePlain,
|
|
32
|
+
safeSerialize
|
|
33
|
+
} from './formatting.js';
|
package/src/utils/output.ts
CHANGED
|
@@ -6,6 +6,9 @@ import type { LogLevel, StackInfo, DevToolsTheme, AdaptiveColors } from '../type
|
|
|
6
6
|
import { formatTimestamp } from './timestamps.js';
|
|
7
7
|
import { StyleBuilder } from '../styling/index.js';
|
|
8
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';
|
|
9
12
|
|
|
10
13
|
/**
|
|
11
14
|
* Style configuration for each log level
|
|
@@ -77,6 +80,7 @@ export function setupThemeChangeListener(callback: (theme: DevToolsTheme) => voi
|
|
|
77
80
|
|
|
78
81
|
/**
|
|
79
82
|
* Creates styled console output with multiple %c formatters
|
|
83
|
+
* Automatically adapts to browser or terminal environment
|
|
80
84
|
*/
|
|
81
85
|
export function createStyledOutput(
|
|
82
86
|
level: LogLevel,
|
|
@@ -84,10 +88,20 @@ export function createStyledOutput(
|
|
|
84
88
|
prefix: string | undefined,
|
|
85
89
|
message: string,
|
|
86
90
|
stackInfo: StackInfo | null,
|
|
87
|
-
autoDetectTheme: boolean = true
|
|
91
|
+
autoDetectTheme: boolean = true,
|
|
92
|
+
presetStyles?: LogStyles,
|
|
93
|
+
presetName?: string
|
|
88
94
|
): [string, ...string[]] {
|
|
89
95
|
const levelConfig = levelStyles[level];
|
|
90
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)
|
|
91
105
|
const currentTheme = autoDetectTheme ? detectDevToolsTheme() : 'light';
|
|
92
106
|
|
|
93
107
|
// Base styles with adaptive colors
|
|
@@ -182,4 +196,32 @@ export function safeStringify(obj: any, _maxDepth = 3): string {
|
|
|
182
196
|
} catch (error) {
|
|
183
197
|
return String(obj);
|
|
184
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];
|
|
185
227
|
}
|