@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.
Files changed (162) hide show
  1. package/dist/chunks/{Logger-Cbi1f10o.js → Logger-CKqzXDh3.js} +2 -2
  2. package/dist/chunks/{Logger-Cbi1f10o.js.map → Logger-CKqzXDh3.js.map} +1 -1
  3. package/dist/chunks/{Logger-BZ7B7OXE.js → Logger-D_vuKP4l.js} +2 -2
  4. package/dist/chunks/{Logger-BZ7B7OXE.js.map → Logger-D_vuKP4l.js.map} +1 -1
  5. package/dist/chunks/cli-module-B-njrTWb.js +2 -0
  6. package/dist/chunks/cli-module-B-njrTWb.js.map +1 -0
  7. package/dist/chunks/{cli-module-ClIJmaT8.js → cli-module-Cx7qotPY.js} +16 -9
  8. package/dist/chunks/cli-module-Cx7qotPY.js.map +1 -0
  9. package/dist/cli.cjs +1 -1
  10. package/dist/cli.js +1 -1
  11. package/dist/exports.cjs +1 -1
  12. package/dist/exports.js +1 -1
  13. package/dist/index.cjs +1 -1
  14. package/dist/index.js +3 -3
  15. package/dist/styling.cjs +1 -1
  16. package/dist/styling.js +2 -2
  17. package/dist/terminal/formatter.d.ts.map +1 -1
  18. package/package.json +5 -1
  19. package/.claude/settings.local.json +0 -48
  20. package/.github/workflows/ci-quality.yml +0 -357
  21. package/.github/workflows/docs-demo.yml +0 -119
  22. package/.github/workflows/releases-core.yml +0 -512
  23. package/.github/workflows/releases-full.yml +0 -582
  24. package/.github/workflows-backup/ci.yml +0 -221
  25. package/.github/workflows-backup/nightly.yml +0 -196
  26. package/.github/workflows-backup/release-optimized.yml +0 -373
  27. package/.github/workflows-backup/release.yml +0 -269
  28. package/.release-notes-0.2.0.md +0 -129
  29. package/.yamllint +0 -28
  30. package/CHANGELOG.json +0 -1076
  31. package/CHANGELOG.md +0 -209
  32. package/CLAUDE.md +0 -217
  33. package/bun.lock +0 -333
  34. package/demo.html +0 -847
  35. package/dist/chunks/cli-module-CadqgZ1Z.js +0 -2
  36. package/dist/chunks/cli-module-CadqgZ1Z.js.map +0 -1
  37. package/dist/chunks/cli-module-ClIJmaT8.js.map +0 -1
  38. package/docs/API.md +0 -918
  39. package/docs/CORE.md +0 -264
  40. package/docs/DEVELOPMENT.md +0 -731
  41. package/docs/EXPORTS.md +0 -467
  42. package/docs/PACKAGES.md +0 -244
  43. package/docs/STYLING.md +0 -405
  44. package/docs/_config.yml +0 -36
  45. package/docs/index.md +0 -179
  46. package/examples/README.md +0 -208
  47. package/examples/basic-logging.js +0 -75
  48. package/examples/data-export.js +0 -234
  49. package/examples/package.json +0 -16
  50. package/examples/performance-timing.js +0 -170
  51. package/examples/simplified-api.js +0 -124
  52. package/examples/styling-themes.js +0 -207
  53. package/index.html +0 -358
  54. package/packages/core/package.json +0 -57
  55. package/packages/exports/package.json +0 -41
  56. package/packages/nodejs-opentui/README.md +0 -232
  57. package/packages/nodejs-opentui/package.json +0 -72
  58. package/packages/nodejs-opentui/src/LogRenderer.ts +0 -171
  59. package/packages/nodejs-opentui/src/OpenTUILogHandler.ts +0 -178
  60. package/packages/nodejs-opentui/src/components/LogBadge.tsx +0 -131
  61. package/packages/nodejs-opentui/src/index.ts +0 -133
  62. package/packages/nodejs-opentui/src/types.ts +0 -158
  63. package/packages/nodejs-opentui/tsconfig.json +0 -20
  64. package/packages/styling/package.json +0 -41
  65. package/playground/demo-all.ts +0 -95
  66. package/playground/demo-box.ts +0 -85
  67. package/playground/demo-levels.ts +0 -56
  68. package/playground/demo-real-world.ts +0 -98
  69. package/playground/demo-spinner.ts +0 -77
  70. package/playground/demo-steps.ts +0 -72
  71. package/playground/demo-table.ts +0 -83
  72. package/project-utils/README.md +0 -172
  73. package/project-utils/auto-release-gemini.ts +0 -1193
  74. package/project-utils/auto-release-ui.ts +0 -1329
  75. package/project-utils/commit-generator.ts +0 -1385
  76. package/project-utils/commit-ui.ts +0 -264
  77. package/project-utils/git-utils.ts +0 -199
  78. package/project-utils/github-release-manager.ts +0 -466
  79. package/project-utils/project-config.ts +0 -260
  80. package/project-utils/prompt-templates.js +0 -345
  81. package/project-utils/prompt-templates.ts +0 -422
  82. package/project-utils/version-manager.ts +0 -1078
  83. package/public/vite.svg +0 -1
  84. package/src/Logger.ts +0 -1858
  85. package/src/ScopedLogger.ts +0 -256
  86. package/src/cli/CommandProcessor.ts +0 -248
  87. package/src/cli/commands/ConfigCommand.ts +0 -93
  88. package/src/cli/commands/ExportCommand.ts +0 -276
  89. package/src/cli/commands/HistoryCommand.ts +0 -117
  90. package/src/cli/commands/StatusCommand.ts +0 -112
  91. package/src/cli/commands/ThemeCommand.ts +0 -88
  92. package/src/cli/help.ts +0 -127
  93. package/src/cli/index.ts +0 -71
  94. package/src/cli-module.ts +0 -21
  95. package/src/cli-primitives/box.ts +0 -86
  96. package/src/cli-primitives/cli-table.ts +0 -62
  97. package/src/cli-primitives/divider.ts +0 -17
  98. package/src/cli-primitives/header.ts +0 -18
  99. package/src/cli-primitives/index.ts +0 -13
  100. package/src/cli-primitives/server-fallback.ts +0 -54
  101. package/src/cli-primitives/spinner.ts +0 -133
  102. package/src/cli-primitives/step.ts +0 -22
  103. package/src/constants.ts +0 -313
  104. package/src/core.ts +0 -397
  105. package/src/example.ts +0 -210
  106. package/src/exports-module.ts +0 -311
  107. package/src/handlers/AnalyticsLogHandler.ts +0 -22
  108. package/src/handlers/ExportLogHandler.ts +0 -610
  109. package/src/handlers/FileLogHandler.ts +0 -169
  110. package/src/handlers/RemoteLogHandler.ts +0 -42
  111. package/src/handlers/index.ts +0 -8
  112. package/src/hooks/HookManager.ts +0 -177
  113. package/src/hooks/index.ts +0 -1
  114. package/src/index.ts +0 -395
  115. package/src/main.ts +0 -196
  116. package/src/serializers/SerializerRegistry.ts +0 -173
  117. package/src/serializers/index.ts +0 -1
  118. package/src/style.css +0 -96
  119. package/src/styling/LogStyleBuilder.ts +0 -355
  120. package/src/styling/SemanticStyles.ts +0 -380
  121. package/src/styling/SmartPresets.ts +0 -288
  122. package/src/styling/StyleBuilder.ts +0 -319
  123. package/src/styling/StyleCache.ts +0 -131
  124. package/src/styling/banners.ts +0 -168
  125. package/src/styling/index.ts +0 -27
  126. package/src/styling/themes.ts +0 -235
  127. package/src/styling-module.ts +0 -244
  128. package/src/terminal/color-converter.ts +0 -315
  129. package/src/terminal/formatter.ts +0 -236
  130. package/src/terminal/terminal-renderer.ts +0 -342
  131. package/src/transports/ConsoleTransport.ts +0 -28
  132. package/src/transports/FileTransport.ts +0 -53
  133. package/src/transports/HttpTransport.ts +0 -56
  134. package/src/transports/TransportManager.ts +0 -130
  135. package/src/transports/index.ts +0 -4
  136. package/src/types/core.ts +0 -417
  137. package/src/types/handlers.ts +0 -95
  138. package/src/types/hooks.ts +0 -45
  139. package/src/types/index.ts +0 -83
  140. package/src/types/serializers.ts +0 -30
  141. package/src/types/transports.ts +0 -52
  142. package/src/typescript.svg +0 -1
  143. package/src/utils/adapter.ts +0 -291
  144. package/src/utils/ansi-colors.ts +0 -333
  145. package/src/utils/environment-detector.ts +0 -170
  146. package/src/utils/environment.ts +0 -94
  147. package/src/utils/formatting.ts +0 -332
  148. package/src/utils/index.ts +0 -33
  149. package/src/utils/opentui-detection.ts +0 -138
  150. package/src/utils/output.ts +0 -227
  151. package/src/utils/stackTrace.ts +0 -144
  152. package/src/utils/timestamps.ts +0 -80
  153. package/src/vite-env.d.ts +0 -1
  154. package/src/writers/BufferWriter.ts +0 -157
  155. package/src/writers/index.ts +0 -6
  156. package/test-core-browser.html +0 -237
  157. package/test-core-node.js +0 -63
  158. package/tests/test-conflict-resolution.ts +0 -391
  159. package/tests/validate-workflows.sh +0 -131
  160. package/tests/yaml-autofix.sh +0 -146
  161. package/tsconfig.json +0 -50
  162. package/vite.config.ts +0 -256
@@ -1,170 +0,0 @@
1
- /**
2
- * Environment Detector - Robust environment detection for logger
3
- * Detects browser, terminal, server, and other runtime environments
4
- */
5
-
6
- export type Environment = 'browser' | 'terminal' | 'server' | 'webworker' | 'deno' | 'unknown';
7
-
8
- /**
9
- * Main environment detection function
10
- */
11
- export function getEnvironment(): Environment {
12
- // Check for Deno first
13
- if (typeof globalThis !== 'undefined' && (globalThis as any).Deno) {
14
- return 'deno';
15
- }
16
-
17
- // Check for WebWorker
18
- if (typeof window === 'undefined' && typeof self !== 'undefined' && typeof (self as any).importScripts === 'function') {
19
- return 'webworker';
20
- }
21
-
22
- // Check for Node.js (server environment)
23
- if (typeof process !== 'undefined' && process.versions && process.versions.node) {
24
- // Determine if it's running in a terminal or as a server
25
- if (isRunningInTerminal()) {
26
- return 'terminal';
27
- }
28
- return 'server';
29
- }
30
-
31
- // Check for browser
32
- if (typeof window !== 'undefined' && typeof document !== 'undefined') {
33
- return 'browser';
34
- }
35
-
36
- return 'unknown';
37
- }
38
-
39
- /**
40
- * Check if running in an interactive terminal
41
- */
42
- export function isRunningInTerminal(): boolean {
43
- // Check for common terminal indicators
44
- if (typeof process === 'undefined') return false;
45
-
46
- const isTTY = process.stdout && process.stdout.isTTY;
47
- const hasTerminalEnv = process.env && (
48
- process.env.TERM ||
49
- process.env.TERM_PROGRAM ||
50
- process.env.SSH_TTY ||
51
- process.env.TERM_SESSION_ID
52
- );
53
-
54
- // Check if we're running in common terminal programs
55
- const terminalPrograms = [
56
- 'vscode',
57
- 'hyper',
58
- 'iterm',
59
- 'terminal',
60
- 'alacritty',
61
- 'kitty',
62
- 'gnome-terminal',
63
- 'konsole',
64
- 'xterm',
65
- 'tmux',
66
- 'screen'
67
- ];
68
-
69
- const isTerminalProgram = hasTerminalEnv && terminalPrograms.some(program =>
70
- process.env.TERM_PROGRAM?.toLowerCase().includes(program) ||
71
- process.env.TERM?.toLowerCase().includes(program)
72
- );
73
-
74
- return Boolean(isTTY || hasTerminalEnv || isTerminalProgram);
75
- }
76
-
77
- /**
78
- * Check if environment supports ANSI colors
79
- */
80
- export function supportsANSI(): boolean {
81
- const env = getEnvironment();
82
-
83
- if (env === 'browser') return false;
84
- if (env === 'terminal') return true;
85
- if (env === 'server') return checkServerANSISupport();
86
-
87
- return false;
88
- }
89
-
90
- /**
91
- * Check if server environment supports ANSI colors
92
- */
93
- function checkServerANSISupport(): boolean {
94
- if (typeof process === 'undefined') return false;
95
-
96
- // Check common environment variables that indicate ANSI support
97
- const supportsANSI = process.env && (
98
- process.env.COLORTERM ||
99
- process.env.FORCE_COLOR ||
100
- (process.env.TERM && process.env.TERM !== 'dumb') ||
101
- process.env.TERM_PROGRAM
102
- );
103
-
104
- return Boolean(supportsANSI);
105
- }
106
-
107
- /**
108
- * Get environment-specific color capability
109
- */
110
- export function getColorCapability(): 'full' | 'basic' | 'none' {
111
- const env = getEnvironment();
112
-
113
- if (env === 'browser') {
114
- return 'full'; // CSS colors
115
- }
116
-
117
- if (!supportsANSI()) {
118
- return 'none';
119
- }
120
-
121
- // Check for 256-color or truecolor support
122
- if (typeof process !== 'undefined' && process.env) {
123
- const hasTrueColor = process.env.COLORTERM === 'truecolor' || process.env.COLORTERM === '24bit';
124
- const has256Colors = process.env.TERM && process.env.TERM.includes('256');
125
-
126
- if (hasTrueColor || has256Colors) {
127
- return 'full';
128
- }
129
- }
130
-
131
- return 'basic'; // Basic 16 colors
132
- }
133
-
134
- /**
135
- * Get terminal width in columns
136
- */
137
- export function getTerminalWidth(): number {
138
- if (typeof process !== 'undefined' && process.stdout?.columns) {
139
- return process.stdout.columns;
140
- }
141
- return 80;
142
- }
143
-
144
- /**
145
- * Get terminal height in rows
146
- */
147
- export function getTerminalHeight(): number {
148
- if (typeof process !== 'undefined' && process.stdout?.rows) {
149
- return process.stdout.rows;
150
- }
151
- return 24;
152
- }
153
-
154
- /**
155
- * Environment information for debugging
156
- */
157
- export function getEnvironmentInfo() {
158
- return {
159
- environment: getEnvironment(),
160
- supportsANSI: supportsANSI(),
161
- colorCapability: getColorCapability(),
162
- isTTY: typeof process !== 'undefined' ? Boolean(process.stdout?.isTTY) : false,
163
- platform: typeof process !== 'undefined' ? process.platform : 'unknown',
164
- nodeVersion: typeof process !== 'undefined' ? process.versions?.node : null,
165
- term: typeof process !== 'undefined' ? process.env?.TERM : null,
166
- colorTerm: typeof process !== 'undefined' ? process.env?.COLORTERM : null,
167
- terminalWidth: getTerminalWidth(),
168
- terminalHeight: getTerminalHeight()
169
- };
170
- }
@@ -1,94 +0,0 @@
1
- /**
2
- * @fileoverview Environment detection utilities for Universal Logger
3
- */
4
-
5
- /**
6
- * Checks if running in Node.js environment
7
- */
8
- export const isNode = typeof process !== 'undefined' &&
9
- process.versions &&
10
- process.versions.node;
11
-
12
- /**
13
- * Checks if running in browser environment
14
- */
15
- export const isBrowser = typeof window !== 'undefined' &&
16
- typeof document !== 'undefined';
17
-
18
- /**
19
- * Checks if running in web worker environment
20
- */
21
- export const isWebWorker = typeof self !== 'undefined' &&
22
- typeof (self as any).importScripts === 'function';
23
-
24
- /**
25
- * Checks if running in Deno environment
26
- */
27
- export const isDeno = typeof globalThis !== 'undefined' &&
28
- 'Deno' in globalThis;
29
-
30
- /**
31
- * Gets the current runtime environment
32
- */
33
- export function getRuntimeEnvironment(): 'node' | 'browser' | 'webworker' | 'deno' | 'unknown' {
34
- if (isNode) return 'node';
35
- if (isBrowser) return 'browser';
36
- if (isWebWorker) return 'webworker';
37
- if (isDeno) return 'deno';
38
- return 'unknown';
39
- }
40
-
41
- /**
42
- * Checks if colors/styling should be supported in current environment
43
- */
44
- export function supportsColors(): boolean {
45
- if (isBrowser) {
46
- // Browser always supports CSS colors
47
- return true;
48
- }
49
-
50
- if (isNode) {
51
- // Check if Node.js supports colors
52
- return process.stdout?.isTTY === true ||
53
- process.env.FORCE_COLOR === '1' ||
54
- process.env.FORCE_COLOR === 'true';
55
- }
56
-
57
- return false;
58
- }
59
-
60
- /**
61
- * Checks if CSS styling is supported (browser-only feature)
62
- */
63
- export function supportsCSSColors(): boolean {
64
- return isBrowser;
65
- }
66
-
67
- /**
68
- * Checks if ANSI colors are supported (terminal environments)
69
- */
70
- export function supportsANSIColors(): boolean {
71
- if (isNode) {
72
- return process.stdout?.isTTY === true ||
73
- process.env.FORCE_COLOR === '1' ||
74
- process.env.FORCE_COLOR === 'true';
75
- }
76
-
77
- return false;
78
- }
79
-
80
- /**
81
- * Gets environment-specific information
82
- */
83
- export function getEnvironmentInfo() {
84
- const env = getRuntimeEnvironment();
85
-
86
- return {
87
- runtime: env,
88
- supportsColors: supportsColors(),
89
- supportsCSSColors: supportsCSSColors(),
90
- supportsANSIColors: supportsANSIColors(),
91
- isProduction: isNode ? process.env.NODE_ENV === 'production' : false,
92
- version: isNode ? process.versions.node : (isBrowser ? navigator.userAgent : 'unknown')
93
- };
94
- }
@@ -1,332 +0,0 @@
1
- /**
2
- * @fileoverview Formatting utilities for Universal Logger
3
- */
4
-
5
- import type { LogLevel, StackInfo, OutputFormat } from '../types/index.js';
6
- import { formatTimestamp } from './timestamps.js';
7
- import { isNode, supportsANSIColors } from './environment.js';
8
- import {
9
- formatLogLevelANSI,
10
- formatTimestampANSI,
11
- formatPrefixANSI,
12
- formatLocationANSI,
13
- sanitizeEmojis,
14
- BUILD_FORMATTERS
15
- } from './ansi-colors.js';
16
-
17
- // Re-export the type for convenience
18
- export type { OutputFormat } from '../types/index.js';
19
-
20
- /**
21
- * Creates output based on environment and format preference
22
- */
23
- export function createOutput(
24
- level: LogLevel,
25
- message: string,
26
- prefix?: string,
27
- stackInfo?: StackInfo | null,
28
- format: OutputFormat = 'auto'
29
- ): string {
30
- const detectedFormat = format === 'auto' ? detectOptimalFormat() : format;
31
-
32
- switch (detectedFormat) {
33
- case 'ansi':
34
- return createANSIOutput(level, message, prefix, stackInfo);
35
- case 'build':
36
- return createBuildOutput(level, message, prefix, stackInfo);
37
- case 'ci':
38
- return createCIOutput(level, message, prefix, stackInfo);
39
- case 'plain':
40
- default:
41
- return createPlainOutput(level, message, prefix, stackInfo);
42
- }
43
- }
44
-
45
- /**
46
- * Creates plain text output for any environment
47
- * No colors, no styling - maximum compatibility
48
- */
49
- export function createPlainOutput(
50
- level: LogLevel,
51
- message: string,
52
- prefix?: string,
53
- stackInfo?: StackInfo | null
54
- ): string {
55
- const timestamp = formatTimestamp();
56
- const timeStr = timestamp.slice(11, 23); // HH:MM:SS.mmm
57
-
58
- let output = `[${timeStr}] [${level.toUpperCase()}]`;
59
-
60
- if (prefix) {
61
- output += ` [${prefix}]`;
62
- }
63
-
64
- output += ` ${message}`;
65
-
66
- if (stackInfo) {
67
- output += ` (${stackInfo.file}:${stackInfo.line}:${stackInfo.column})`;
68
- }
69
-
70
- return output;
71
- }
72
-
73
- /**
74
- * Creates ANSI-colored output for terminals
75
- */
76
- export function createANSIOutput(
77
- level: LogLevel,
78
- message: string,
79
- prefix?: string,
80
- stackInfo?: StackInfo | null
81
- ): string {
82
- const timestamp = formatTimestamp();
83
- const timeStr = timestamp.slice(11, 23);
84
-
85
- let output = '';
86
-
87
- // Timestamp
88
- output += formatTimestampANSI(`[${timeStr}]`) + ' ';
89
-
90
- // Log level with colors
91
- output += formatLogLevelANSI(level) + ' ';
92
-
93
- // Prefix if provided
94
- if (prefix) {
95
- output += formatPrefixANSI(prefix) + ' ';
96
- }
97
-
98
- // Message
99
- output += message;
100
-
101
- // Stack info if provided
102
- if (stackInfo) {
103
- output += ' ' + formatLocationANSI(`(${stackInfo.file}:${stackInfo.line}:${stackInfo.column})`);
104
- }
105
-
106
- return sanitizeEmojis(output);
107
- }
108
-
109
- /**
110
- * Creates build-friendly output (optimized for Next.js builds, webpack, etc.)
111
- */
112
- export function createBuildOutput(
113
- level: LogLevel,
114
- message: string,
115
- prefix?: string,
116
- stackInfo?: StackInfo | null
117
- ): string {
118
- const timestamp = formatTimestamp();
119
- const timeStr = timestamp.slice(11, 23);
120
-
121
- let output = '';
122
-
123
- // Use ANSI colors if supported
124
- if (supportsANSIColors()) {
125
- output += formatTimestampANSI(`[${timeStr}]`) + ' ';
126
-
127
- // Use build-specific formatters
128
- switch (level) {
129
- case 'info':
130
- output += BUILD_FORMATTERS.info(message);
131
- break;
132
- case 'warn':
133
- output += BUILD_FORMATTERS.warning(message);
134
- break;
135
- case 'error':
136
- case 'critical':
137
- output += BUILD_FORMATTERS.error(message);
138
- break;
139
- default:
140
- output += `${formatLogLevelANSI(level)} ${message}`;
141
- }
142
- } else {
143
- // Fallback to plain text
144
- output = `[${timeStr}] [${level.toUpperCase()}]`;
145
-
146
- if (prefix) {
147
- output += ` [${prefix}]`;
148
- }
149
-
150
- output += ` ${message}`;
151
- }
152
-
153
- if (stackInfo) {
154
- output += ` (${stackInfo.file}:${stackInfo.line}:${stackInfo.column})`;
155
- }
156
-
157
- return sanitizeEmojis(output);
158
- }
159
-
160
- /**
161
- * Creates CI-friendly output (no emojis, simple formatting)
162
- */
163
- export function createCIOutput(
164
- level: LogLevel,
165
- message: string,
166
- prefix?: string,
167
- stackInfo?: StackInfo | null
168
- ): string {
169
- const timestamp = formatTimestamp();
170
- const timeStr = timestamp.slice(11, 23);
171
-
172
- let output = `[${timeStr}] [${level.toUpperCase()}]`;
173
-
174
- if (prefix) {
175
- output += ` [${prefix}]`;
176
- }
177
-
178
- output += ` ${message}`;
179
-
180
- if (stackInfo) {
181
- output += ` (${stackInfo.file}:${stackInfo.line}:${stackInfo.column})`;
182
- }
183
-
184
- // Always remove emojis for CI
185
- return sanitizeEmojis(output);
186
- }
187
-
188
- /**
189
- * Detects the optimal output format based on environment
190
- */
191
- export function detectOptimalFormat(): OutputFormat {
192
- // Check for specific environment variables
193
- const isCI = process.env.CI ||
194
- process.env.GITHUB_ACTIONS ||
195
- process.env.JENKINS_URL ||
196
- process.env.GITLAB_CI ||
197
- process.env.TRAVIS ||
198
- process.env.CIRCLECI;
199
-
200
- const isBuild = process.env.NODE_ENV === 'production' ||
201
- process.env.BUILD_MODE === 'production' ||
202
- process.argv.some(arg => arg.includes('build') || arg.includes('webpack'));
203
-
204
- const isNextJS = process.env.NEXT_RUNTIME ||
205
- process.argv.some(arg => arg.includes('next'));
206
-
207
- // CI environment - always use plain text
208
- if (isCI) {
209
- return 'ci';
210
- }
211
-
212
- // Next.js build environment
213
- if (isNextJS || isBuild) {
214
- return 'build';
215
- }
216
-
217
- // Node.js with ANSI support
218
- if (isNode && supportsANSIColors()) {
219
- return 'ansi';
220
- }
221
-
222
- // Default to plain text
223
- return 'plain';
224
- }
225
-
226
- /**
227
- * Gets the appropriate log method for the level
228
- * Uses different console methods for better semantics
229
- */
230
- export function getConsoleMethod(level: LogLevel): 'log' | 'info' | 'warn' | 'error' {
231
- switch (level) {
232
- case 'debug':
233
- return 'log';
234
- case 'info':
235
- return 'info';
236
- case 'warn':
237
- return 'warn';
238
- case 'error':
239
- case 'critical':
240
- return 'error';
241
- default:
242
- return 'log';
243
- }
244
- }
245
-
246
- /**
247
- * Create a simple log entry object for handlers
248
- */
249
- export function createLogEntry(
250
- level: LogLevel,
251
- message: string,
252
- args: any[],
253
- prefix?: string,
254
- stackInfo?: StackInfo | null
255
- ) {
256
- return {
257
- timestamp: formatTimestamp(),
258
- level: level.toUpperCase(),
259
- prefix,
260
- message,
261
- args: args.slice(1), // Exclude the first message argument
262
- location: stackInfo ? {
263
- file: stackInfo.file,
264
- line: stackInfo.line,
265
- column: stackInfo.column,
266
- function: stackInfo.function
267
- } : undefined,
268
- raw: args
269
- };
270
- }
271
-
272
- /**
273
- * Format data for table display in plain text
274
- */
275
- export function formatTablePlain(data: any, columns?: string[]): string {
276
- try {
277
- if (Array.isArray(data)) {
278
- if (data.length === 0) return '[Empty Array]';
279
-
280
- // Simple array formatting
281
- if (typeof data[0] !== 'object') {
282
- return data.map((item, i) => `${i}: ${item}`).join('\n');
283
- }
284
-
285
- // Object array formatting
286
- const keys = columns || Object.keys(data[0] || {});
287
- const header = keys.join('\t');
288
- const rows = data.map(item =>
289
- keys.map(key => String(item[key] || '')).join('\t')
290
- );
291
-
292
- return [header, ...rows].join('\n');
293
- }
294
-
295
- if (typeof data === 'object' && data !== null) {
296
- // Simple object formatting
297
- return Object.entries(data)
298
- .map(([key, value]) => `${key}: ${value}`)
299
- .join('\n');
300
- }
301
-
302
- return String(data);
303
- } catch (error) {
304
- return `[Error formatting table: ${error}]`;
305
- }
306
- }
307
-
308
- /**
309
- * Safe object serialization for logging
310
- */
311
- export function safeSerialize(obj: any, maxDepth: number = 3, currentDepth: number = 0): any {
312
- if (currentDepth >= maxDepth) {
313
- return '[Max Depth Reached]';
314
- }
315
-
316
- if (obj === null) return null;
317
- if (obj === undefined) return '[undefined]';
318
- if (typeof obj === 'function') return '[Function]';
319
- if (obj instanceof Error) return `[Error: ${obj.message}]`;
320
- if (obj instanceof Date) return obj.toISOString();
321
- if (typeof obj !== 'object') return obj;
322
-
323
- if (Array.isArray(obj)) {
324
- return obj.map(item => safeSerialize(item, maxDepth, currentDepth + 1));
325
- }
326
-
327
- const result: any = {};
328
- for (const [key, value] of Object.entries(obj)) {
329
- result[key] = safeSerialize(value, maxDepth, currentDepth + 1);
330
- }
331
- return result;
332
- }
@@ -1,33 +0,0 @@
1
- /**
2
- * @fileoverview Utility functions exports for Advanced Logger
3
- */
4
-
5
- export { parseStackTrace } from './stackTrace.js';
6
- export {
7
- formatTimestamp,
8
- parseRelativeTime,
9
- parseTimeInput,
10
- formatDisplayTime
11
- } from './timestamps.js';
12
- export {
13
- createStyledOutput,
14
- generateLogId,
15
- escapeHtml,
16
- safeStringify,
17
- detectDevToolsTheme,
18
- getAdaptiveColor,
19
- setupThemeChangeListener,
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';