@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,342 +0,0 @@
1
- /**
2
- * Terminal Renderer - ANSI color rendering for terminal environments
3
- * Converts CSS-based styling to ANSI escape sequences for terminal output
4
- */
5
-
6
- import type { LogLevel } from '../types/index.js';
7
- import type { LogStyles } from '../types/index.js';
8
- import { getANSIForeground, getANSIBackground, ANSI, type ColorCapability } from './color-converter.js';
9
-
10
- export type ANSIStyle = {
11
- text: string;
12
- timestamp?: string;
13
- level?: string;
14
- prefix?: string;
15
- message?: string;
16
- location?: string;
17
- reset: string;
18
- };
19
-
20
- export class TerminalRenderer {
21
- private colorCapability: ColorCapability;
22
-
23
- constructor(colorCapability: ColorCapability = 'full') {
24
- this.colorCapability = colorCapability;
25
- }
26
-
27
- /**
28
- * Get ANSI color codes - now supports truecolor/256-color
29
- */
30
- private getColorCode(color: string, background: boolean = false): string {
31
- return background
32
- ? getANSIBackground(color, this.colorCapability)
33
- : getANSIForeground(color, this.colorCapability);
34
- }
35
-
36
- /**
37
- * Get ANSI style codes
38
- */
39
- private getStyleCode(styles: string[]): string {
40
- const styleCodes: Record<string, string> = {
41
- 'bold': '1',
42
- 'dim': '2',
43
- 'italic': '3',
44
- 'underline': '4',
45
- 'reset': '0'
46
- };
47
-
48
- const codes = styles.map(style => styleCodes[style] || '0').join(';');
49
- return codes ? `\x1b[${codes}m` : '';
50
- }
51
-
52
- /**
53
- * Convert log styles to ANSI formatting
54
- */
55
- renderTerminal(
56
- level: LogLevel,
57
- message: string,
58
- timestamp?: string,
59
- prefix?: string,
60
- location?: string,
61
- styles?: LogStyles
62
- ): ANSIStyle {
63
- const reset = '\x1b[0m';
64
- const result: ANSIStyle = { text: '', reset };
65
-
66
- // Apply preset styles if provided
67
- if (styles) {
68
- result.timestamp = this.styleTimestamp(timestamp, styles.timestamp);
69
- result.level = this.styleLevel(level, styles.level);
70
- result.prefix = this.stylePrefix(prefix, styles.prefix);
71
- result.message = this.styleMessage(message, styles.message);
72
- result.location = this.styleLocation(location, styles.location);
73
- } else {
74
- // Default styling based on level
75
- result.timestamp = this.styleTimestamp(timestamp);
76
- result.level = this.styleLevel(level);
77
- result.prefix = this.stylePrefix(prefix);
78
- result.message = this.styleMessage(message);
79
- result.location = this.styleLocation(location);
80
- }
81
-
82
- // Build complete text
83
- const parts: string[] = [];
84
- if (result.timestamp) parts.push(result.timestamp);
85
- if (result.level) parts.push(result.level);
86
- if (result.prefix) parts.push(result.prefix);
87
- if (result.message) parts.push(result.message);
88
- if (result.location) parts.push(result.location);
89
-
90
- result.text = parts.join(' ') + reset;
91
- return result;
92
- }
93
-
94
- /**
95
- * Style timestamp based on preset or defaults
96
- */
97
- private styleTimestamp(timestamp?: string, style?: LogStyles['timestamp']): string {
98
- if (!timestamp || !style?.show) return '';
99
-
100
- if (this.colorCapability === 'none') {
101
- return timestamp;
102
- }
103
-
104
- const dimStyle = this.getStyleCode(['dim']);
105
- return `${dimStyle}${timestamp}${'\x1b[0m'}`;
106
- }
107
-
108
- /**
109
- * Style level with appropriate colors and formatting
110
- */
111
- private styleLevel(level: LogLevel, style?: LogStyles['level']): string {
112
- if (!style?.show) return '';
113
-
114
- const levelText = this.getLevelText(level);
115
- const levelColors: Record<LogLevel, string> = {
116
- 'debug': 'magenta',
117
- 'info': 'blue',
118
- 'warn': 'yellow',
119
- 'error': 'red',
120
- 'critical': 'red'
121
- };
122
-
123
- if (this.colorCapability === 'none') {
124
- return `[${levelText}]`;
125
- }
126
-
127
- const color = levelColors[level] || 'white';
128
- const colorCode = this.getColorCode(color);
129
- const boldStyle = this.getStyleCode(['bold']);
130
-
131
- if (style?.style === 'compact') {
132
- return `${colorCode}[${levelText}]${'\x1b[0m'}`;
133
- } else {
134
- return `${colorCode}${boldStyle}[${levelText}]${'\x1b[0m'}`;
135
- }
136
- }
137
-
138
- /**
139
- * Style prefix based on preset - now as a badge
140
- */
141
- private stylePrefix(prefix?: string, style?: LogStyles['prefix']): string {
142
- if (!prefix || !style?.show) return '';
143
-
144
- if (this.colorCapability === 'none') {
145
- return `[${prefix}]`;
146
- }
147
-
148
- // Create badge styling similar to level badges
149
- const colorCode = this.getColorCode('cyan');
150
- const bgBlack = '\x1b[40m';
151
- return `${bgBlack}${colorCode}[${prefix.toUpperCase()}]${'\x1b[0m'}`;
152
- }
153
-
154
- /**
155
- * Style message based on preset
156
- */
157
- private styleMessage(message: string, style?: LogStyles['message']): string {
158
- if (!style?.show) return message;
159
-
160
- return message; // Messages usually don't need styling
161
- }
162
-
163
- /**
164
- * Style location (file:line) information
165
- */
166
- private styleLocation(location?: string, style?: LogStyles['location']): string {
167
- if (!location || !style?.show) return '';
168
-
169
- if (this.colorCapability === 'none') {
170
- return `(${location})`;
171
- }
172
-
173
- const dimStyle = this.getStyleCode(['dim']);
174
- if (style?.style === 'clickable') {
175
- const underlineStyle = this.getStyleCode(['dim', 'underline']);
176
- return `${underlineStyle}(${location})${'\x1b[0m'}`;
177
- }
178
-
179
- return `${dimStyle}(${location})${'\x1b[0m'}`;
180
- }
181
-
182
- /**
183
- * Get text representation of log level
184
- */
185
- public getLevelText(level: LogLevel): string {
186
- const levelMap: Record<LogLevel, string> = {
187
- 'debug': 'DEBUG',
188
- 'info': 'INFO',
189
- 'warn': 'WARN',
190
- 'error': 'ERROR',
191
- 'critical': 'CRITICAL'
192
- };
193
-
194
- return levelMap[level] || String(level).toUpperCase();
195
- }
196
-
197
- /**
198
- * Create cyberpunk-style ANSI rendering with truecolor support
199
- */
200
- renderCyberpunk(
201
- level: LogLevel,
202
- message: string,
203
- timestamp?: string,
204
- prefix?: string,
205
- location?: string
206
- ): ANSIStyle {
207
- const reset = ANSI.reset;
208
-
209
- const cyberpunkColors: Record<LogLevel, string> = {
210
- 'debug': '#ff00ff', // Neon magenta
211
- 'info': '#00ffff', // Neon cyan
212
- 'warn': '#ffff00', // Neon yellow
213
- 'error': '#ff0040', // Neon red-pink
214
- 'critical': '#ff0000' // Pure red
215
- };
216
-
217
- const parts: string[] = [];
218
-
219
- if (timestamp) {
220
- parts.push(`${ANSI.dim}${timestamp}${reset}`);
221
- }
222
-
223
- const levelColor = this.getColorCode(cyberpunkColors[level] || '#ffffff');
224
- const bgBlack = ANSI.bg.black;
225
- const bold = level === 'critical' ? ANSI.bold : '';
226
- parts.push(`${bgBlack}${levelColor}${bold} ${this.getLevelText(level)} ${reset}`);
227
-
228
- if (prefix) {
229
- const cyanColor = this.getColorCode('#00ffff');
230
- parts.push(`${bgBlack}${cyanColor}[${prefix.toUpperCase()}]${reset}`);
231
- }
232
-
233
- parts.push(message);
234
-
235
- if (location) {
236
- parts.push(`${ANSI.dim}(${location})${reset}`);
237
- }
238
-
239
- return {
240
- text: parts.join(' '),
241
- reset
242
- };
243
- }
244
-
245
- /**
246
- * Create minimal ANSI rendering with truecolor support
247
- */
248
- renderMinimal(
249
- level: LogLevel,
250
- message: string,
251
- timestamp?: string,
252
- prefix?: string
253
- ): ANSIStyle {
254
- const reset = ANSI.reset;
255
-
256
- const minimalColors: Record<LogLevel, string> = {
257
- 'debug': '#c678dd', // Soft purple
258
- 'info': '#61afef', // Soft blue
259
- 'warn': '#e5c07b', // Soft yellow
260
- 'error': '#e06c75', // Soft red
261
- 'critical': '#be5046' // Dark red
262
- };
263
-
264
- const parts: string[] = [];
265
-
266
- if (timestamp) {
267
- parts.push(`${ANSI.dim}${timestamp}${reset}`);
268
- }
269
-
270
- const levelColor = this.getColorCode(minimalColors[level] || '#abb2bf');
271
- const bold = level === 'critical' ? ANSI.bold : '';
272
- parts.push(`${levelColor}${bold}${this.getLevelText(level)}:${reset}`);
273
-
274
- if (prefix) {
275
- const cyanColor = this.getColorCode('#56b6c2');
276
- parts.push(`${cyanColor}[${prefix.toUpperCase()}]${reset}`);
277
- }
278
-
279
- parts.push(message);
280
-
281
- return {
282
- text: parts.join(' '),
283
- reset
284
- };
285
- }
286
-
287
- /**
288
- * Get chalk-like interface for log level with truecolor support
289
- */
290
- public getChalkForLevel(level: LogLevel): ChalkLikeInterface {
291
- const levelColors: Record<LogLevel, string> = {
292
- 'debug': '#c678dd',
293
- 'info': '#61afef',
294
- 'warn': '#e5c07b',
295
- 'error': '#e06c75',
296
- 'critical': '#be5046'
297
- };
298
-
299
- const reset = ANSI.reset;
300
-
301
- return {
302
- color: (text: string) => {
303
- const color = levelColors[level] || '#abb2bf';
304
- const colorCode = this.getColorCode(color);
305
- return `${colorCode}${text}${reset}`;
306
- },
307
- bold: (text: string) => `${ANSI.bold}${text}${reset}`,
308
- dim: (text: string) => `${ANSI.dim}${text}${reset}`,
309
- bgGray: (text: string) => `${ANSI.bg.gray}${text}${reset}`,
310
- bgBlue: (text: string) => `${this.getColorCode('#1e3a5f', true)}${text}${reset}`,
311
- reset: (text: string) => text,
312
- cyan: {
313
- bold: (text: string) => {
314
- const cyan = this.getColorCode('#00ffff');
315
- return `${cyan}${ANSI.bold}${text}${reset}`;
316
- },
317
- dim: (text: string) => {
318
- const cyan = this.getColorCode('#00ffff');
319
- return `${cyan}${ANSI.dim}${text}${reset}`;
320
- },
321
- bg: (text: string) => {
322
- const cyan = this.getColorCode('#00ffff');
323
- return `${ANSI.bg.black}${cyan}[${text.toUpperCase()}]${reset}`;
324
- }
325
- }
326
- };
327
- }
328
- }
329
-
330
- export interface ChalkLikeInterface {
331
- color: (text: string) => string;
332
- bold: (text: string) => string;
333
- dim: (text: string) => string;
334
- bgGray: (text: string) => string;
335
- bgBlue: (text: string) => string;
336
- reset: (text: string) => string;
337
- cyan: {
338
- bold: (text: string) => string;
339
- dim: (text: string) => string;
340
- bg: (text: string) => string;
341
- };
342
- }
@@ -1,28 +0,0 @@
1
- import type { TransportRecord, TransportOptions, ITransport, LogLevel } from '../types/index.js';
2
-
3
- export class ConsoleTransport implements ITransport {
4
- readonly name = 'console';
5
-
6
- constructor(private options?: TransportOptions) {}
7
-
8
- write(record: TransportRecord): void {
9
- const method = this.getConsoleMethod(record.level);
10
- const prefix = record.prefix ? `[${record.prefix}] ` : '';
11
- const location = record.location
12
- ? ` (${record.location.file}:${record.location.line})`
13
- : '';
14
-
15
- console[method](`[${record.level.toUpperCase()}]${prefix} ${record.msg}${location}`);
16
- }
17
-
18
- private getConsoleMethod(level: LogLevel): 'log' | 'info' | 'warn' | 'error' {
19
- switch (level) {
20
- case 'debug': return 'log';
21
- case 'info': return 'info';
22
- case 'warn': return 'warn';
23
- case 'error':
24
- case 'critical': return 'error';
25
- default: return 'log';
26
- }
27
- }
28
- }
@@ -1,53 +0,0 @@
1
- import type { TransportRecord, TransportOptions, ITransport } from '../types/index.js';
2
-
3
- export interface FileTransportOptions extends TransportOptions {
4
- destination?: string;
5
- }
6
-
7
- export class FileTransport implements ITransport {
8
- readonly name = 'file';
9
- private buffer: string[] = [];
10
- private flushTimer?: ReturnType<typeof setInterval>;
11
- private options: FileTransportOptions;
12
-
13
- constructor(options?: FileTransportOptions) {
14
- this.options = options || {};
15
-
16
- if (this.options.flushInterval) {
17
- this.flushTimer = setInterval(() => this.flush(), this.options.flushInterval);
18
- }
19
- }
20
-
21
- write(record: TransportRecord): void {
22
- const line = JSON.stringify(record) + '\n';
23
- this.buffer.push(line);
24
-
25
- if (this.buffer.length >= (this.options.batchSize || 100)) {
26
- this.flush();
27
- }
28
- }
29
-
30
- async flush(): Promise<void> {
31
- if (this.buffer.length === 0) return;
32
-
33
- const lines = this.buffer.join('');
34
- this.buffer = [];
35
-
36
- if (typeof globalThis.process !== 'undefined' && typeof require === 'function') {
37
- try {
38
- const fs = require('fs');
39
- const dest = this.options.destination || 'app.log';
40
- fs.appendFileSync(dest, lines);
41
- } catch {
42
- // Silent fail in browser or if fs not available
43
- }
44
- }
45
- }
46
-
47
- close(): void {
48
- if (this.flushTimer) {
49
- clearInterval(this.flushTimer);
50
- }
51
- this.flush();
52
- }
53
- }
@@ -1,56 +0,0 @@
1
- import type { TransportRecord, TransportOptions, ITransport } from '../types/index.js';
2
-
3
- export interface HttpTransportOptions extends TransportOptions {
4
- url?: string;
5
- headers?: Record<string, string>;
6
- }
7
-
8
- export class HttpTransport implements ITransport {
9
- readonly name = 'http';
10
- private buffer: TransportRecord[] = [];
11
- private flushTimer?: ReturnType<typeof setInterval>;
12
- private options: HttpTransportOptions;
13
-
14
- constructor(options?: HttpTransportOptions) {
15
- this.options = options || {};
16
-
17
- if (this.options.flushInterval) {
18
- this.flushTimer = setInterval(() => this.flush(), this.options.flushInterval);
19
- }
20
- }
21
-
22
- write(record: TransportRecord): void {
23
- this.buffer.push(record);
24
-
25
- if (this.buffer.length >= (this.options.batchSize || 50)) {
26
- this.flush();
27
- }
28
- }
29
-
30
- async flush(): Promise<void> {
31
- if (this.buffer.length === 0 || !this.options.url) return;
32
-
33
- const records = [...this.buffer];
34
- this.buffer = [];
35
-
36
- try {
37
- await fetch(this.options.url, {
38
- method: 'POST',
39
- headers: {
40
- 'Content-Type': 'application/json',
41
- ...this.options.headers
42
- },
43
- body: JSON.stringify({ logs: records })
44
- });
45
- } catch {
46
- this.buffer.unshift(...records);
47
- }
48
- }
49
-
50
- close(): void {
51
- if (this.flushTimer) {
52
- clearInterval(this.flushTimer);
53
- }
54
- this.flush();
55
- }
56
- }
@@ -1,130 +0,0 @@
1
- import type {
2
- TransportRecord,
3
- TransportTarget,
4
- TransportOptions,
5
- ITransport,
6
- ITransportManager,
7
- LogLevel
8
- } from '../types/index.js';
9
- import { LOG_LEVELS } from '../types/index.js';
10
-
11
- function generateTransportId(): string {
12
- return `transport-${Date.now()}-${Math.random().toString(36).substr(2, 6)}`;
13
- }
14
-
15
- interface TransportEntry {
16
- id: string;
17
- transport: ITransport;
18
- options: TransportOptions;
19
- level: LogLevel;
20
- levelValue: number;
21
- }
22
-
23
- export class TransportManager implements ITransportManager {
24
- private transports: Map<string, TransportEntry> = new Map();
25
- private defaultLevel: LogLevel = 'info';
26
-
27
- constructor(defaultLevel?: LogLevel) {
28
- if (defaultLevel) {
29
- this.defaultLevel = defaultLevel;
30
- }
31
- }
32
-
33
- add(target: TransportTarget): string {
34
- const id = generateTransportId();
35
- const level = target.level || this.defaultLevel;
36
-
37
- let transport: ITransport;
38
-
39
- if (typeof target.target === 'string') {
40
- throw new Error(`String transport targets not supported. Use inline transport object.`);
41
- } else {
42
- transport = target.target;
43
- }
44
-
45
- const entry: TransportEntry = {
46
- id,
47
- transport,
48
- options: target.options || {},
49
- level,
50
- levelValue: LOG_LEVELS[level]
51
- };
52
-
53
- this.transports.set(id, entry);
54
- return id;
55
- }
56
-
57
- remove(id: string): boolean {
58
- const entry = this.transports.get(id);
59
- if (entry) {
60
- entry.transport.close?.();
61
- return this.transports.delete(id);
62
- }
63
- return false;
64
- }
65
-
66
- async write(record: TransportRecord): Promise<void> {
67
- const promises: Promise<void>[] = [];
68
-
69
- for (const entry of this.transports.values()) {
70
- if (record.levelValue < entry.levelValue) {
71
- continue;
72
- }
73
-
74
- let transformedRecord = record;
75
- if (entry.options.transform) {
76
- const result = entry.options.transform(record);
77
- if (result === null) continue;
78
- transformedRecord = result;
79
- }
80
-
81
- const result = entry.transport.write(transformedRecord);
82
- if (result instanceof Promise) {
83
- promises.push(result);
84
- }
85
- }
86
-
87
- await Promise.all(promises);
88
- }
89
-
90
- async flush(): Promise<void> {
91
- const promises: Promise<void>[] = [];
92
-
93
- for (const entry of this.transports.values()) {
94
- if (entry.transport.flush) {
95
- const result = entry.transport.flush();
96
- if (result instanceof Promise) {
97
- promises.push(result);
98
- }
99
- }
100
- }
101
-
102
- await Promise.all(promises);
103
- }
104
-
105
- async close(): Promise<void> {
106
- await this.flush();
107
-
108
- const promises: Promise<void>[] = [];
109
-
110
- for (const entry of this.transports.values()) {
111
- if (entry.transport.close) {
112
- const result = entry.transport.close();
113
- if (result instanceof Promise) {
114
- promises.push(result);
115
- }
116
- }
117
- }
118
-
119
- await Promise.all(promises);
120
- this.transports.clear();
121
- }
122
-
123
- get count(): number {
124
- return this.transports.size;
125
- }
126
-
127
- list(): string[] {
128
- return Array.from(this.transports.keys());
129
- }
130
- }
@@ -1,4 +0,0 @@
1
- export { TransportManager } from './TransportManager.js';
2
- export { ConsoleTransport } from './ConsoleTransport.js';
3
- export { FileTransport, type FileTransportOptions } from './FileTransport.js';
4
- export { HttpTransport, type HttpTransportOptions } from './HttpTransport.js';