@mks2508/better-logger 5.0.0 → 5.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/{Logger-Cbi1f10o.js → Logger-CKqzXDh3.js} +2 -2
- package/dist/chunks/{Logger-Cbi1f10o.js.map → Logger-CKqzXDh3.js.map} +1 -1
- package/dist/chunks/{Logger-BZ7B7OXE.js → Logger-D_vuKP4l.js} +2 -2
- package/dist/chunks/{Logger-BZ7B7OXE.js.map → Logger-D_vuKP4l.js.map} +1 -1
- package/dist/chunks/cli-module-B-njrTWb.js +2 -0
- package/dist/chunks/cli-module-B-njrTWb.js.map +1 -0
- package/dist/chunks/{cli-module-ClIJmaT8.js → cli-module-Cx7qotPY.js} +16 -9
- package/dist/chunks/cli-module-Cx7qotPY.js.map +1 -0
- package/dist/cli.cjs +1 -1
- package/dist/cli.js +1 -1
- package/dist/exports.cjs +1 -1
- package/dist/exports.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +3 -3
- package/dist/styling.cjs +1 -1
- package/dist/styling.js +2 -2
- package/dist/terminal/formatter.d.ts.map +1 -1
- package/package.json +5 -1
- package/.claude/settings.local.json +0 -48
- package/.github/workflows/ci-quality.yml +0 -357
- package/.github/workflows/docs-demo.yml +0 -119
- package/.github/workflows/releases-core.yml +0 -512
- package/.github/workflows/releases-full.yml +0 -582
- package/.github/workflows-backup/ci.yml +0 -221
- package/.github/workflows-backup/nightly.yml +0 -196
- package/.github/workflows-backup/release-optimized.yml +0 -373
- package/.github/workflows-backup/release.yml +0 -269
- package/.release-notes-0.2.0.md +0 -129
- package/.yamllint +0 -28
- package/CHANGELOG.json +0 -1076
- package/CHANGELOG.md +0 -209
- package/CLAUDE.md +0 -217
- package/bun.lock +0 -333
- package/demo.html +0 -847
- package/dist/chunks/cli-module-CadqgZ1Z.js +0 -2
- package/dist/chunks/cli-module-CadqgZ1Z.js.map +0 -1
- package/dist/chunks/cli-module-ClIJmaT8.js.map +0 -1
- package/docs/API.md +0 -918
- package/docs/CORE.md +0 -264
- package/docs/DEVELOPMENT.md +0 -731
- package/docs/EXPORTS.md +0 -467
- package/docs/PACKAGES.md +0 -244
- package/docs/STYLING.md +0 -405
- package/docs/_config.yml +0 -36
- package/docs/index.md +0 -179
- package/examples/README.md +0 -208
- package/examples/basic-logging.js +0 -75
- package/examples/data-export.js +0 -234
- package/examples/package.json +0 -16
- package/examples/performance-timing.js +0 -170
- package/examples/simplified-api.js +0 -124
- package/examples/styling-themes.js +0 -207
- package/index.html +0 -358
- package/packages/core/package.json +0 -57
- package/packages/exports/package.json +0 -41
- package/packages/nodejs-opentui/README.md +0 -232
- package/packages/nodejs-opentui/package.json +0 -72
- package/packages/nodejs-opentui/src/LogRenderer.ts +0 -171
- package/packages/nodejs-opentui/src/OpenTUILogHandler.ts +0 -178
- package/packages/nodejs-opentui/src/components/LogBadge.tsx +0 -131
- package/packages/nodejs-opentui/src/index.ts +0 -133
- package/packages/nodejs-opentui/src/types.ts +0 -158
- package/packages/nodejs-opentui/tsconfig.json +0 -20
- package/packages/styling/package.json +0 -41
- package/playground/demo-all.ts +0 -95
- package/playground/demo-box.ts +0 -85
- package/playground/demo-levels.ts +0 -56
- package/playground/demo-real-world.ts +0 -98
- package/playground/demo-spinner.ts +0 -77
- package/playground/demo-steps.ts +0 -72
- package/playground/demo-table.ts +0 -83
- package/project-utils/README.md +0 -172
- package/project-utils/auto-release-gemini.ts +0 -1193
- package/project-utils/auto-release-ui.ts +0 -1329
- package/project-utils/commit-generator.ts +0 -1385
- package/project-utils/commit-ui.ts +0 -264
- package/project-utils/git-utils.ts +0 -199
- package/project-utils/github-release-manager.ts +0 -466
- package/project-utils/project-config.ts +0 -260
- package/project-utils/prompt-templates.js +0 -345
- package/project-utils/prompt-templates.ts +0 -422
- package/project-utils/version-manager.ts +0 -1078
- package/public/vite.svg +0 -1
- package/src/Logger.ts +0 -1858
- package/src/ScopedLogger.ts +0 -256
- package/src/cli/CommandProcessor.ts +0 -248
- package/src/cli/commands/ConfigCommand.ts +0 -93
- package/src/cli/commands/ExportCommand.ts +0 -276
- package/src/cli/commands/HistoryCommand.ts +0 -117
- package/src/cli/commands/StatusCommand.ts +0 -112
- package/src/cli/commands/ThemeCommand.ts +0 -88
- package/src/cli/help.ts +0 -127
- package/src/cli/index.ts +0 -71
- package/src/cli-module.ts +0 -21
- package/src/cli-primitives/box.ts +0 -86
- package/src/cli-primitives/cli-table.ts +0 -62
- package/src/cli-primitives/divider.ts +0 -17
- package/src/cli-primitives/header.ts +0 -18
- package/src/cli-primitives/index.ts +0 -13
- package/src/cli-primitives/server-fallback.ts +0 -54
- package/src/cli-primitives/spinner.ts +0 -133
- package/src/cli-primitives/step.ts +0 -22
- package/src/constants.ts +0 -313
- package/src/core.ts +0 -397
- package/src/example.ts +0 -210
- package/src/exports-module.ts +0 -311
- package/src/handlers/AnalyticsLogHandler.ts +0 -22
- package/src/handlers/ExportLogHandler.ts +0 -610
- package/src/handlers/FileLogHandler.ts +0 -169
- package/src/handlers/RemoteLogHandler.ts +0 -42
- package/src/handlers/index.ts +0 -8
- package/src/hooks/HookManager.ts +0 -177
- package/src/hooks/index.ts +0 -1
- package/src/index.ts +0 -395
- package/src/main.ts +0 -196
- package/src/serializers/SerializerRegistry.ts +0 -173
- package/src/serializers/index.ts +0 -1
- package/src/style.css +0 -96
- package/src/styling/LogStyleBuilder.ts +0 -355
- package/src/styling/SemanticStyles.ts +0 -380
- package/src/styling/SmartPresets.ts +0 -288
- package/src/styling/StyleBuilder.ts +0 -319
- package/src/styling/StyleCache.ts +0 -131
- package/src/styling/banners.ts +0 -168
- package/src/styling/index.ts +0 -27
- package/src/styling/themes.ts +0 -235
- package/src/styling-module.ts +0 -244
- package/src/terminal/color-converter.ts +0 -315
- package/src/terminal/formatter.ts +0 -236
- package/src/terminal/terminal-renderer.ts +0 -342
- package/src/transports/ConsoleTransport.ts +0 -28
- package/src/transports/FileTransport.ts +0 -53
- package/src/transports/HttpTransport.ts +0 -56
- package/src/transports/TransportManager.ts +0 -130
- package/src/transports/index.ts +0 -4
- package/src/types/core.ts +0 -417
- package/src/types/handlers.ts +0 -95
- package/src/types/hooks.ts +0 -45
- package/src/types/index.ts +0 -83
- package/src/types/serializers.ts +0 -30
- package/src/types/transports.ts +0 -52
- package/src/typescript.svg +0 -1
- package/src/utils/adapter.ts +0 -291
- package/src/utils/ansi-colors.ts +0 -333
- package/src/utils/environment-detector.ts +0 -170
- package/src/utils/environment.ts +0 -94
- package/src/utils/formatting.ts +0 -332
- package/src/utils/index.ts +0 -33
- package/src/utils/opentui-detection.ts +0 -138
- package/src/utils/output.ts +0 -227
- package/src/utils/stackTrace.ts +0 -144
- package/src/utils/timestamps.ts +0 -80
- package/src/vite-env.d.ts +0 -1
- package/src/writers/BufferWriter.ts +0 -157
- package/src/writers/index.ts +0 -6
- package/test-core-browser.html +0 -237
- package/test-core-node.js +0 -63
- package/tests/test-conflict-resolution.ts +0 -391
- package/tests/validate-workflows.sh +0 -131
- package/tests/yaml-autofix.sh +0 -146
- package/tsconfig.json +0 -50
- package/vite.config.ts +0 -256
package/src/constants.ts
DELETED
|
@@ -1,313 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Global constants for Advanced Logger
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { LogLevel, AdaptiveColors, CLILogLevel, Verbosity } from './types/index.js';
|
|
6
|
-
import type { LevelStyleConfig } from './utils/index.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Default configuration values
|
|
10
|
-
*/
|
|
11
|
-
export const DEFAULT_CONFIG = {
|
|
12
|
-
verbosity: 'info' as const,
|
|
13
|
-
enableColors: true,
|
|
14
|
-
enableTimestamps: true,
|
|
15
|
-
enableStackTrace: true,
|
|
16
|
-
theme: 'default' as const,
|
|
17
|
-
bannerType: 'simple' as const,
|
|
18
|
-
bufferSize: 1000,
|
|
19
|
-
autoDetectTheme: true,
|
|
20
|
-
outputFormat: 'auto' as const,
|
|
21
|
-
} as const;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Basic level styles for core module (minimal CSS styling)
|
|
25
|
-
*/
|
|
26
|
-
export const LEVEL_STYLES: Record<LogLevel | 'success', LevelStyleConfig> = {
|
|
27
|
-
debug: {
|
|
28
|
-
emoji: '🔍',
|
|
29
|
-
label: 'DEBUG',
|
|
30
|
-
background: 'linear-gradient(90deg, #6c757d, #495057)',
|
|
31
|
-
color: '#ffffff',
|
|
32
|
-
border: '1px solid #6c757d',
|
|
33
|
-
shadow: '0 2px 4px rgba(108, 117, 125, 0.3)'
|
|
34
|
-
},
|
|
35
|
-
info: {
|
|
36
|
-
emoji: 'ℹ️',
|
|
37
|
-
label: 'INFO',
|
|
38
|
-
background: 'linear-gradient(90deg, #007bff, #0056b3)',
|
|
39
|
-
color: '#ffffff',
|
|
40
|
-
border: '1px solid #007bff',
|
|
41
|
-
shadow: '0 2px 4px rgba(0, 123, 255, 0.3)'
|
|
42
|
-
},
|
|
43
|
-
warn: {
|
|
44
|
-
emoji: '⚠️',
|
|
45
|
-
label: 'WARN',
|
|
46
|
-
background: 'linear-gradient(90deg, #ffc107, #e0a800)',
|
|
47
|
-
color: '#000000',
|
|
48
|
-
border: '1px solid #ffc107',
|
|
49
|
-
shadow: '0 2px 4px rgba(255, 193, 7, 0.3)'
|
|
50
|
-
},
|
|
51
|
-
error: {
|
|
52
|
-
emoji: '❌',
|
|
53
|
-
label: 'ERROR',
|
|
54
|
-
background: 'linear-gradient(90deg, #dc3545, #c82333)',
|
|
55
|
-
color: '#ffffff',
|
|
56
|
-
border: '1px solid #dc3545',
|
|
57
|
-
shadow: '0 2px 4px rgba(220, 53, 69, 0.3)'
|
|
58
|
-
},
|
|
59
|
-
critical: {
|
|
60
|
-
emoji: '🚨',
|
|
61
|
-
label: 'CRITICAL',
|
|
62
|
-
background: 'linear-gradient(90deg, #8B0000, #FF0000)',
|
|
63
|
-
color: '#ffffff',
|
|
64
|
-
border: '2px solid #FF0000',
|
|
65
|
-
shadow: '0 4px 8px rgba(255, 0, 0, 0.4)'
|
|
66
|
-
},
|
|
67
|
-
success: {
|
|
68
|
-
emoji: '✅',
|
|
69
|
-
label: 'SUCCESS',
|
|
70
|
-
background: 'linear-gradient(90deg, #28a745, #1e7e34)',
|
|
71
|
-
color: '#ffffff',
|
|
72
|
-
border: '1px solid #28a745',
|
|
73
|
-
shadow: '0 2px 4px rgba(40, 167, 69, 0.3)'
|
|
74
|
-
}
|
|
75
|
-
} as const;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Maximum allowed buffer sizes for performance
|
|
79
|
-
*/
|
|
80
|
-
export const BUFFER_LIMITS = {
|
|
81
|
-
MIN_SIZE: 50,
|
|
82
|
-
DEFAULT_SIZE: 1000,
|
|
83
|
-
MAX_SIZE: 10000,
|
|
84
|
-
} as const;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Export format definitions with extensions
|
|
88
|
-
*/
|
|
89
|
-
export const EXPORT_FORMATS = {
|
|
90
|
-
json: { extension: '.json', mimeType: 'application/json' },
|
|
91
|
-
csv: { extension: '.csv', mimeType: 'text/csv' },
|
|
92
|
-
markdown: { extension: '.md', mimeType: 'text/markdown' },
|
|
93
|
-
plain: { extension: '.txt', mimeType: 'text/plain' },
|
|
94
|
-
html: { extension: '.html', mimeType: 'text/html' },
|
|
95
|
-
} as const;
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* CLI command definitions
|
|
99
|
-
*/
|
|
100
|
-
export const CLI_COMMANDS = {
|
|
101
|
-
config: 'config',
|
|
102
|
-
help: 'help',
|
|
103
|
-
themes: 'themes',
|
|
104
|
-
banners: 'banners',
|
|
105
|
-
banner: 'banner',
|
|
106
|
-
status: 'status',
|
|
107
|
-
reset: 'reset',
|
|
108
|
-
demo: 'demo',
|
|
109
|
-
export: 'export',
|
|
110
|
-
copy: 'copy',
|
|
111
|
-
'buffer-size': 'buffer-size',
|
|
112
|
-
'clear-buffer': 'clear-buffer',
|
|
113
|
-
'buffer-info': 'buffer-info',
|
|
114
|
-
} as const;
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Time parsing constants for relative time filters
|
|
118
|
-
*/
|
|
119
|
-
export const TIME_UNITS = {
|
|
120
|
-
ms: 1,
|
|
121
|
-
s: 1000,
|
|
122
|
-
m: 60 * 1000,
|
|
123
|
-
h: 60 * 60 * 1000,
|
|
124
|
-
d: 24 * 60 * 60 * 1000,
|
|
125
|
-
} as const;
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Default styling values
|
|
129
|
-
*/
|
|
130
|
-
export const STYLE_DEFAULTS = {
|
|
131
|
-
FONT_FAMILY: 'Monaco, Consolas, monospace',
|
|
132
|
-
FONT_SIZE: '12px',
|
|
133
|
-
BORDER_RADIUS: '4px',
|
|
134
|
-
PADDING: '4px 8px',
|
|
135
|
-
} as const;
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Level priority mapping for filtering
|
|
139
|
-
*/
|
|
140
|
-
export const LEVEL_PRIORITIES: Record<LogLevel, number> = {
|
|
141
|
-
debug: 0,
|
|
142
|
-
info: 1,
|
|
143
|
-
warn: 2,
|
|
144
|
-
error: 3,
|
|
145
|
-
critical: 4,
|
|
146
|
-
} as const;
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Adaptive color configurations for DevTools theme compatibility
|
|
150
|
-
*/
|
|
151
|
-
export const ADAPTIVE_COLORS = {
|
|
152
|
-
timestamp: {
|
|
153
|
-
light: '#666666',
|
|
154
|
-
dark: '#a0a0a0',
|
|
155
|
-
},
|
|
156
|
-
messageText: {
|
|
157
|
-
light: '#2d3748',
|
|
158
|
-
dark: '#f7fafc',
|
|
159
|
-
},
|
|
160
|
-
prefix: {
|
|
161
|
-
light: '#2d3748',
|
|
162
|
-
dark: '#e2e8f0',
|
|
163
|
-
},
|
|
164
|
-
prefixBackground: {
|
|
165
|
-
light: '#2d3748',
|
|
166
|
-
dark: '#4a5568',
|
|
167
|
-
},
|
|
168
|
-
location: {
|
|
169
|
-
light: '#718096',
|
|
170
|
-
dark: '#a0aec0',
|
|
171
|
-
},
|
|
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
|
-
}
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* CLI log level to internal verbosity mapping
|
|
305
|
-
* @since 5.0.0
|
|
306
|
-
*/
|
|
307
|
-
export const CLI_LEVEL_MAP: Record<CLILogLevel, { verbosity: Verbosity; showPrimitives: boolean }> = {
|
|
308
|
-
silent: { verbosity: 'silent', showPrimitives: false },
|
|
309
|
-
quiet: { verbosity: 'error', showPrimitives: false },
|
|
310
|
-
normal: { verbosity: 'info', showPrimitives: true },
|
|
311
|
-
verbose: { verbosity: 'debug', showPrimitives: true },
|
|
312
|
-
debug: { verbosity: 'debug', showPrimitives: true },
|
|
313
|
-
} as const;
|
package/src/core.ts
DELETED
|
@@ -1,397 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Core Logger Module - Minimal logging without advanced features
|
|
3
|
-
* @version 0.0.1
|
|
4
|
-
*
|
|
5
|
-
* This module provides the essential logging functionality without visual enhancements,
|
|
6
|
-
* SVG support, or advanced styling. Perfect for lightweight applications or server-side usage.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
// Core types
|
|
10
|
-
import type {
|
|
11
|
-
LogLevel,
|
|
12
|
-
Verbosity,
|
|
13
|
-
LoggerConfig,
|
|
14
|
-
ILogHandler,
|
|
15
|
-
LogMetadata,
|
|
16
|
-
TimerEntry
|
|
17
|
-
} from './types/index.js';
|
|
18
|
-
|
|
19
|
-
// Core utilities
|
|
20
|
-
import {
|
|
21
|
-
parseStackTrace,
|
|
22
|
-
formatTimestamp
|
|
23
|
-
} from './utils/index.js';
|
|
24
|
-
|
|
25
|
-
// Universal formatting and environment detection
|
|
26
|
-
import {
|
|
27
|
-
createPlainOutput,
|
|
28
|
-
createOutput,
|
|
29
|
-
getConsoleMethod,
|
|
30
|
-
createLogEntry,
|
|
31
|
-
formatTablePlain,
|
|
32
|
-
safeSerialize,
|
|
33
|
-
detectOptimalFormat,
|
|
34
|
-
type OutputFormat
|
|
35
|
-
} from './utils/formatting.js';
|
|
36
|
-
|
|
37
|
-
import {
|
|
38
|
-
isBrowser,
|
|
39
|
-
isNode,
|
|
40
|
-
getRuntimeEnvironment,
|
|
41
|
-
supportsColors,
|
|
42
|
-
supportsCSSColors
|
|
43
|
-
} from './utils/environment.js';
|
|
44
|
-
|
|
45
|
-
import { createStyledOutput } from './utils/output.js';
|
|
46
|
-
|
|
47
|
-
// Constants
|
|
48
|
-
import { DEFAULT_CONFIG, LEVEL_STYLES } from './constants.js';
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Minimal Logger class with core functionality only
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```typescript
|
|
55
|
-
* import { CoreLogger } from '@mks2508/better-logger/core';
|
|
56
|
-
*
|
|
57
|
-
* const logger = new CoreLogger();
|
|
58
|
-
* logger.info('Hello world');
|
|
59
|
-
* logger.error('Something went wrong', error);
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
export class CoreLogger {
|
|
63
|
-
private config: LoggerConfig;
|
|
64
|
-
private scopedPrefix?: string;
|
|
65
|
-
private handlers: ILogHandler[] = [];
|
|
66
|
-
private timers: Map<string, TimerEntry> = new Map();
|
|
67
|
-
private groupDepth: number = 0;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Creates a new CoreLogger instance
|
|
71
|
-
* @param config - Optional configuration
|
|
72
|
-
*/
|
|
73
|
-
constructor(config: Partial<LoggerConfig> = {}) {
|
|
74
|
-
this.config = {
|
|
75
|
-
...DEFAULT_CONFIG,
|
|
76
|
-
...config,
|
|
77
|
-
// Auto-configure based on environment
|
|
78
|
-
enableColors: config.enableColors ?? (isBrowser ? true : false),
|
|
79
|
-
enableTimestamps: config.enableTimestamps ?? true,
|
|
80
|
-
enableStackTrace: config.enableStackTrace ?? false,
|
|
81
|
-
autoDetectTheme: config.autoDetectTheme ?? true,
|
|
82
|
-
outputFormat: config.outputFormat ?? 'auto'
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// ===== CONFIGURATION METHODS =====
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Get current configuration
|
|
90
|
-
*/
|
|
91
|
-
getConfig(): LoggerConfig {
|
|
92
|
-
return { ...this.config };
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Sets the global prefix for all log messages
|
|
97
|
-
*/
|
|
98
|
-
setGlobalPrefix(prefix: string): void {
|
|
99
|
-
this.config.globalPrefix = prefix;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Sets the verbosity level for filtering log output
|
|
104
|
-
*/
|
|
105
|
-
setVerbosity(level: Verbosity): void {
|
|
106
|
-
this.config.verbosity = level;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Creates a scoped logger with a specific prefix
|
|
111
|
-
*/
|
|
112
|
-
scope(prefix: string): CoreLogger {
|
|
113
|
-
const scopedLogger = new CoreLogger(this.config);
|
|
114
|
-
scopedLogger.scopedPrefix = prefix;
|
|
115
|
-
scopedLogger.handlers = [...this.handlers];
|
|
116
|
-
return scopedLogger;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Adds a custom log handler for extensibility
|
|
121
|
-
*/
|
|
122
|
-
addHandler(handler: ILogHandler): void {
|
|
123
|
-
this.handlers.push(handler);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// ===== CORE LOGGING METHODS =====
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Checks if a log level should be output based on current verbosity
|
|
130
|
-
*/
|
|
131
|
-
private shouldLog(level: LogLevel): boolean {
|
|
132
|
-
if (this.config.verbosity === 'silent') return false;
|
|
133
|
-
const levels = { debug: 0, info: 1, warn: 2, error: 3, critical: 4 };
|
|
134
|
-
return levels[level] >= levels[this.config.verbosity];
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Gets the effective prefix (global + scoped)
|
|
139
|
-
*/
|
|
140
|
-
private getEffectivePrefix(): string | undefined {
|
|
141
|
-
const parts = [this.config.globalPrefix, this.scopedPrefix].filter(Boolean);
|
|
142
|
-
return parts.length > 0 ? parts.join(':') : undefined;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Core logging method with universal formatting
|
|
147
|
-
*/
|
|
148
|
-
private log(level: LogLevel, ...args: any[]): void {
|
|
149
|
-
if (!this.shouldLog(level)) return;
|
|
150
|
-
|
|
151
|
-
const prefix = this.getEffectivePrefix();
|
|
152
|
-
const message = String(args[0] || '');
|
|
153
|
-
const stackInfo = this.config.enableStackTrace ? parseStackTrace() : null;
|
|
154
|
-
const consoleMethod = getConsoleMethod(level);
|
|
155
|
-
|
|
156
|
-
// Choose formatting based on environment and configuration
|
|
157
|
-
if (isBrowser && this.config.enableColors && supportsCSSColors()) {
|
|
158
|
-
// Browser with CSS styling
|
|
159
|
-
try {
|
|
160
|
-
const [format, ...styles] = createStyledOutput(
|
|
161
|
-
level,
|
|
162
|
-
LEVEL_STYLES,
|
|
163
|
-
prefix,
|
|
164
|
-
message,
|
|
165
|
-
stackInfo,
|
|
166
|
-
this.config.autoDetectTheme
|
|
167
|
-
);
|
|
168
|
-
console[consoleMethod](format, ...styles, ...args.slice(1));
|
|
169
|
-
} catch (error) {
|
|
170
|
-
// Fallback to universal formatting if CSS fails
|
|
171
|
-
const output = createOutput(level, message, prefix, stackInfo, this.config.outputFormat);
|
|
172
|
-
console[consoleMethod](output, ...args.slice(1));
|
|
173
|
-
}
|
|
174
|
-
} else {
|
|
175
|
-
// Node.js or browser without colors - use universal formatting
|
|
176
|
-
const groupIndent = ' '.repeat(this.groupDepth);
|
|
177
|
-
const output = groupIndent + createOutput(level, message, prefix, stackInfo, this.config.outputFormat);
|
|
178
|
-
console[consoleMethod](output, ...args.slice(1));
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// Call custom handlers with structured metadata
|
|
182
|
-
const logEntry = createLogEntry(level, message, args, prefix, stackInfo);
|
|
183
|
-
const metadata: LogMetadata = {
|
|
184
|
-
timestamp: logEntry.timestamp,
|
|
185
|
-
level,
|
|
186
|
-
prefix,
|
|
187
|
-
stackInfo: logEntry.location,
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
this.handlers.forEach(handler => {
|
|
191
|
-
try {
|
|
192
|
-
handler.handle(level, message, args, metadata);
|
|
193
|
-
} catch (error) {
|
|
194
|
-
console.error('Log handler failed:', error);
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Logs debug information (lowest priority)
|
|
201
|
-
*/
|
|
202
|
-
debug(...args: any[]): void {
|
|
203
|
-
this.log('debug', ...args);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Logs informational messages
|
|
208
|
-
*/
|
|
209
|
-
info(...args: any[]): void {
|
|
210
|
-
this.log('info', ...args);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Logs warning messages
|
|
215
|
-
*/
|
|
216
|
-
warn(...args: any[]): void {
|
|
217
|
-
this.log('warn', ...args);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Logs error messages
|
|
222
|
-
*/
|
|
223
|
-
error(...args: any[]): void {
|
|
224
|
-
this.log('error', ...args);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Logs critical errors (highest priority)
|
|
229
|
-
*/
|
|
230
|
-
critical(...args: any[]): void {
|
|
231
|
-
this.log('critical', ...args);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Logs trace information (detailed debugging)
|
|
236
|
-
*/
|
|
237
|
-
trace(...args: any[]): void {
|
|
238
|
-
this.log('debug', ...args);
|
|
239
|
-
if (this.shouldLog('debug')) {
|
|
240
|
-
console.trace(...args);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
// ===== BASIC ADVANCED FEATURES =====
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Displays data in a table format
|
|
248
|
-
*/
|
|
249
|
-
table(data: any, columns?: string[]): void {
|
|
250
|
-
if (!this.shouldLog('info')) return;
|
|
251
|
-
|
|
252
|
-
const prefix = this.getEffectivePrefix();
|
|
253
|
-
const tableHeader = `[TABLE]${prefix ? ` [${prefix}]` : ''}:`;
|
|
254
|
-
|
|
255
|
-
if (isBrowser && typeof console.table === 'function') {
|
|
256
|
-
// Browser has native table support
|
|
257
|
-
console.log(tableHeader);
|
|
258
|
-
if (columns) {
|
|
259
|
-
console.table(data, columns);
|
|
260
|
-
} else {
|
|
261
|
-
console.table(data);
|
|
262
|
-
}
|
|
263
|
-
} else {
|
|
264
|
-
// Node.js or fallback - use plain text formatting
|
|
265
|
-
console.log(tableHeader);
|
|
266
|
-
const tableText = formatTablePlain(data, columns);
|
|
267
|
-
console.log(tableText);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* Starts a collapsible group in the console
|
|
273
|
-
*/
|
|
274
|
-
group(label: string, collapsed: boolean = false): void {
|
|
275
|
-
const prefix = this.getEffectivePrefix();
|
|
276
|
-
const fullLabel = `${prefix ? `[${prefix}] ` : ''}${label}`;
|
|
277
|
-
|
|
278
|
-
if (isBrowser && console.group && console.groupCollapsed) {
|
|
279
|
-
// Browser supports native grouping
|
|
280
|
-
if (collapsed) {
|
|
281
|
-
console.groupCollapsed(fullLabel);
|
|
282
|
-
} else {
|
|
283
|
-
console.group(fullLabel);
|
|
284
|
-
}
|
|
285
|
-
} else {
|
|
286
|
-
// Node.js fallback - just log the group label
|
|
287
|
-
const groupStart = '┌─ ' + fullLabel;
|
|
288
|
-
console.log(groupStart);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
this.groupDepth++;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* Ends the current console group
|
|
296
|
-
*/
|
|
297
|
-
groupEnd(): void {
|
|
298
|
-
if (this.groupDepth > 0) {
|
|
299
|
-
if (isBrowser && console.groupEnd) {
|
|
300
|
-
console.groupEnd();
|
|
301
|
-
} else {
|
|
302
|
-
// Node.js fallback - log group end
|
|
303
|
-
const groupEnd = '└─ (end group)';
|
|
304
|
-
console.log(groupEnd);
|
|
305
|
-
}
|
|
306
|
-
this.groupDepth--;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* Starts a timer with the given label
|
|
312
|
-
*/
|
|
313
|
-
time(label: string): void {
|
|
314
|
-
const startTime = this.getPerformanceNow();
|
|
315
|
-
const timer: TimerEntry = {
|
|
316
|
-
label,
|
|
317
|
-
startTime,
|
|
318
|
-
};
|
|
319
|
-
this.timers.set(label, timer);
|
|
320
|
-
|
|
321
|
-
const prefix = this.getEffectivePrefix();
|
|
322
|
-
const message = `Timer started: ${label}`;
|
|
323
|
-
const output = createPlainOutput('info', message, prefix);
|
|
324
|
-
console.log(output);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* Ends a timer and logs the elapsed time
|
|
329
|
-
*/
|
|
330
|
-
timeEnd(label: string): void {
|
|
331
|
-
const timer = this.timers.get(label);
|
|
332
|
-
if (!timer) {
|
|
333
|
-
this.warn(`Timer '${label}' does not exist`);
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
const elapsed = this.getPerformanceNow() - timer.startTime;
|
|
338
|
-
this.timers.delete(label);
|
|
339
|
-
|
|
340
|
-
const prefix = this.getEffectivePrefix();
|
|
341
|
-
const message = `Timer ended: ${label} - ${elapsed.toFixed(2)}ms`;
|
|
342
|
-
const output = createPlainOutput('info', message, prefix);
|
|
343
|
-
console.log(output);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* Gets performance.now() or fallback for older environments
|
|
348
|
-
*/
|
|
349
|
-
private getPerformanceNow(): number {
|
|
350
|
-
if (typeof performance !== 'undefined' && performance.now) {
|
|
351
|
-
return performance.now();
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
if (isNode && process.hrtime) {
|
|
355
|
-
// Node.js high-resolution time
|
|
356
|
-
const [seconds, nanoseconds] = process.hrtime();
|
|
357
|
-
return seconds * 1000 + nanoseconds / 1000000;
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
// Fallback to Date.now()
|
|
361
|
-
return Date.now();
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
// Create and export singleton instance for convenience
|
|
366
|
-
const coreLogger = new CoreLogger();
|
|
367
|
-
|
|
368
|
-
/**
|
|
369
|
-
* Export individual methods for convenience (with proper binding)
|
|
370
|
-
*/
|
|
371
|
-
export const debug = (...args: any[]) => coreLogger.debug(...args);
|
|
372
|
-
export const info = (...args: any[]) => coreLogger.info(...args);
|
|
373
|
-
export const warn = (...args: any[]) => coreLogger.warn(...args);
|
|
374
|
-
export const error = (...args: any[]) => coreLogger.error(...args);
|
|
375
|
-
export const critical = (...args: any[]) => coreLogger.critical(...args);
|
|
376
|
-
export const trace = (...args: any[]) => coreLogger.trace(...args);
|
|
377
|
-
export const table = (data: any, columns?: string[]) => coreLogger.table(data, columns);
|
|
378
|
-
export const group = (label: string, collapsed?: boolean) => coreLogger.group(label, collapsed);
|
|
379
|
-
export const groupEnd = () => coreLogger.groupEnd();
|
|
380
|
-
export const time = (label: string) => coreLogger.time(label);
|
|
381
|
-
export const timeEnd = (label: string) => coreLogger.timeEnd(label);
|
|
382
|
-
export const setGlobalPrefix = (prefix: string) => coreLogger.setGlobalPrefix(prefix);
|
|
383
|
-
export const scope = (prefix: string) => coreLogger.scope(prefix);
|
|
384
|
-
export const setVerbosity = (level: Verbosity) => coreLogger.setVerbosity(level);
|
|
385
|
-
export const addHandler = (handler: ILogHandler) => coreLogger.addHandler(handler);
|
|
386
|
-
|
|
387
|
-
// Export the singleton as default
|
|
388
|
-
export default coreLogger;
|
|
389
|
-
|
|
390
|
-
// Re-export core types
|
|
391
|
-
export type {
|
|
392
|
-
LogLevel,
|
|
393
|
-
Verbosity,
|
|
394
|
-
LoggerConfig,
|
|
395
|
-
ILogHandler,
|
|
396
|
-
LogMetadata
|
|
397
|
-
} from './types/index.js';
|