@mks2508/better-logger 5.0.1 → 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/Logger.d.ts +976 -0
- package/dist/Logger.d.ts.map +1 -0
- package/dist/ScopedLogger.d.ts +74 -0
- package/dist/ScopedLogger.d.ts.map +1 -0
- package/dist/chunks/Logger-CKqzXDh3.js +2 -0
- package/dist/chunks/Logger-CKqzXDh3.js.map +1 -0
- package/dist/chunks/Logger-D_vuKP4l.js +4511 -0
- package/dist/chunks/Logger-D_vuKP4l.js.map +1 -0
- package/dist/chunks/RemoteLogHandler-CjWpWZGl.js +33 -0
- package/dist/chunks/RemoteLogHandler-CjWpWZGl.js.map +1 -0
- package/dist/chunks/RemoteLogHandler-ymkQ97xl.js +2 -0
- package/dist/chunks/RemoteLogHandler-ymkQ97xl.js.map +1 -0
- 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-Cx7qotPY.js +390 -0
- package/dist/chunks/cli-module-Cx7qotPY.js.map +1 -0
- package/dist/chunks/color-converter-CCSQRztd.js +2 -0
- package/dist/chunks/color-converter-CCSQRztd.js.map +1 -0
- package/dist/chunks/color-converter-_Xdmsy7E.js +462 -0
- package/dist/chunks/color-converter-_Xdmsy7E.js.map +1 -0
- package/dist/chunks/environment-C1xxvc8l.js +1127 -0
- package/dist/chunks/environment-C1xxvc8l.js.map +1 -0
- package/dist/chunks/environment-Cprkw3g9.js +4 -0
- package/dist/chunks/environment-Cprkw3g9.js.map +1 -0
- package/dist/chunks/formatting-DMJxYq9o.js +380 -0
- package/dist/chunks/formatting-DMJxYq9o.js.map +1 -0
- package/dist/chunks/formatting-DpKxCsXq.js +2 -0
- package/dist/chunks/formatting-DpKxCsXq.js.map +1 -0
- package/dist/cli/CommandProcessor.d.ts +100 -0
- package/dist/cli/CommandProcessor.d.ts.map +1 -0
- package/dist/cli/commands/ConfigCommand.d.ts +14 -0
- package/dist/cli/commands/ConfigCommand.d.ts.map +1 -0
- package/dist/cli/commands/ExportCommand.d.ts +48 -0
- package/dist/cli/commands/ExportCommand.d.ts.map +1 -0
- package/dist/cli/commands/HistoryCommand.d.ts +47 -0
- package/dist/cli/commands/HistoryCommand.d.ts.map +1 -0
- package/dist/cli/commands/StatusCommand.d.ts +30 -0
- package/dist/cli/commands/StatusCommand.d.ts.map +1 -0
- package/dist/cli/commands/ThemeCommand.d.ts +30 -0
- package/dist/cli/commands/ThemeCommand.d.ts.map +1 -0
- package/dist/cli/help.d.ts +12 -0
- package/dist/cli/help.d.ts.map +1 -0
- package/dist/cli/index.d.ts +15 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/{src/cli-module.ts → dist/cli-module.d.ts} +2 -8
- package/dist/cli-module.d.ts.map +1 -0
- package/dist/cli-primitives/box.d.ts +11 -0
- package/dist/cli-primitives/box.d.ts.map +1 -0
- package/dist/cli-primitives/cli-table.d.ts +11 -0
- package/dist/cli-primitives/cli-table.d.ts.map +1 -0
- package/dist/cli-primitives/divider.d.ts +11 -0
- package/dist/cli-primitives/divider.d.ts.map +1 -0
- package/dist/cli-primitives/header.d.ts +12 -0
- package/dist/cli-primitives/header.d.ts.map +1 -0
- package/{src/cli-primitives/index.ts → dist/cli-primitives/index.d.ts} +1 -1
- package/dist/cli-primitives/index.d.ts.map +1 -0
- package/dist/cli-primitives/server-fallback.d.ts +25 -0
- package/dist/cli-primitives/server-fallback.d.ts.map +1 -0
- package/dist/cli-primitives/spinner.d.ts +47 -0
- package/dist/cli-primitives/spinner.d.ts.map +1 -0
- package/dist/cli-primitives/step.d.ts +11 -0
- package/dist/cli-primitives/step.d.ts.map +1 -0
- package/dist/cli.cjs +2 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.js +12 -0
- package/dist/cli.js.map +1 -0
- package/dist/constants.d.ts +235 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/core.cjs +2 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.ts +127 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +291 -0
- package/dist/core.js.map +1 -0
- package/dist/example.d.ts +18 -0
- package/dist/example.d.ts.map +1 -0
- package/dist/exports-module.d.ts +196 -0
- package/dist/exports-module.d.ts.map +1 -0
- package/dist/exports.cjs +2 -0
- package/dist/exports.cjs.map +1 -0
- package/dist/exports.js +238 -0
- package/dist/exports.js.map +1 -0
- package/dist/handlers/AnalyticsLogHandler.d.ts +8 -0
- package/dist/handlers/AnalyticsLogHandler.d.ts.map +1 -0
- package/dist/handlers/ExportLogHandler.d.ts +100 -0
- package/dist/handlers/ExportLogHandler.d.ts.map +1 -0
- package/dist/handlers/FileLogHandler.d.ts +33 -0
- package/dist/handlers/FileLogHandler.d.ts.map +1 -0
- package/dist/handlers/RemoteLogHandler.d.ts +11 -0
- package/dist/handlers/RemoteLogHandler.d.ts.map +1 -0
- package/{src/handlers/index.ts → dist/handlers/index.d.ts} +2 -2
- package/dist/handlers/index.d.ts.map +1 -0
- package/dist/hooks/HookManager.d.ts +21 -0
- package/dist/hooks/HookManager.d.ts.map +1 -0
- package/{src/hooks/index.ts → dist/hooks/index.d.ts} +1 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +161 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +627 -0
- package/dist/index.js.map +1 -0
- package/dist/main.d.ts +2 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/serializers/SerializerRegistry.d.ts +16 -0
- package/dist/serializers/SerializerRegistry.d.ts.map +1 -0
- package/{src/serializers/index.ts → dist/serializers/index.d.ts} +1 -0
- package/dist/serializers/index.d.ts.map +1 -0
- package/dist/styling/LogStyleBuilder.d.ts +146 -0
- package/dist/styling/LogStyleBuilder.d.ts.map +1 -0
- package/dist/styling/SemanticStyles.d.ts +178 -0
- package/dist/styling/SemanticStyles.d.ts.map +1 -0
- package/dist/styling/SmartPresets.d.ts +22 -0
- package/dist/styling/SmartPresets.d.ts.map +1 -0
- package/dist/styling/StyleBuilder.d.ts +140 -0
- package/dist/styling/StyleBuilder.d.ts.map +1 -0
- package/dist/styling/StyleCache.d.ts +42 -0
- package/dist/styling/StyleCache.d.ts.map +1 -0
- package/dist/styling/banners.d.ts +42 -0
- package/dist/styling/banners.d.ts.map +1 -0
- package/dist/styling/index.d.ts +10 -0
- package/dist/styling/index.d.ts.map +1 -0
- package/dist/styling/themes.d.ts +7 -0
- package/dist/styling/themes.d.ts.map +1 -0
- package/dist/styling-module.d.ts +178 -0
- package/dist/styling-module.d.ts.map +1 -0
- package/dist/styling.cjs +2 -0
- package/dist/styling.cjs.map +1 -0
- package/dist/styling.js +146 -0
- package/dist/styling.js.map +1 -0
- package/dist/terminal/color-converter.d.ts +73 -0
- package/dist/terminal/color-converter.d.ts.map +1 -0
- package/dist/terminal/formatter.d.ts +20 -0
- package/dist/terminal/formatter.d.ts.map +1 -0
- package/dist/terminal/terminal-renderer.d.ts +77 -0
- package/dist/terminal/terminal-renderer.d.ts.map +1 -0
- package/dist/transports/ConsoleTransport.d.ts +9 -0
- package/dist/transports/ConsoleTransport.d.ts.map +1 -0
- package/dist/transports/FileTransport.d.ts +15 -0
- package/dist/transports/FileTransport.d.ts.map +1 -0
- package/dist/transports/HttpTransport.d.ts +16 -0
- package/dist/transports/HttpTransport.d.ts.map +1 -0
- package/dist/transports/TransportManager.d.ts +14 -0
- package/dist/transports/TransportManager.d.ts.map +1 -0
- package/{src/transports/index.ts → dist/transports/index.d.ts} +1 -0
- package/dist/transports/index.d.ts.map +1 -0
- package/{src/types/core.ts → dist/types/core.d.ts} +25 -62
- package/dist/types/core.d.ts.map +1 -0
- package/{src/types/handlers.ts → dist/types/handlers.d.ts} +5 -15
- package/dist/types/handlers.d.ts.map +1 -0
- package/{src/types/hooks.ts → dist/types/hooks.d.ts} +3 -12
- package/dist/types/hooks.d.ts.map +1 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.d.ts.map +1 -0
- package/{src/types/serializers.ts → dist/types/serializers.d.ts} +1 -6
- package/dist/types/serializers.d.ts.map +1 -0
- package/{src/types/transports.ts → dist/types/transports.d.ts} +2 -7
- package/dist/types/transports.d.ts.map +1 -0
- 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 +45 -0
- package/dist/utils/environment-detector.d.ts.map +1 -0
- package/dist/utils/environment.d.ts +47 -0
- package/dist/utils/environment.d.ts.map +1 -0
- package/dist/utils/formatting.d.ts +58 -0
- package/dist/utils/formatting.d.ts.map +1 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/opentui-detection.d.ts +34 -0
- package/dist/utils/opentui-detection.d.ts.map +1 -0
- package/dist/utils/output.d.ts +46 -0
- package/dist/utils/output.d.ts.map +1 -0
- package/dist/utils/stackTrace.d.ts +6 -0
- package/dist/utils/stackTrace.d.ts.map +1 -0
- package/dist/utils/timestamps.d.ts +20 -0
- package/dist/utils/timestamps.d.ts.map +1 -0
- package/{src/writers/BufferWriter.ts → dist/writers/BufferWriter.d.ts} +16 -77
- package/dist/writers/BufferWriter.d.ts.map +1 -0
- package/{src/writers/index.ts → dist/writers/index.d.ts} +1 -1
- package/dist/writers/index.d.ts.map +1 -0
- 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 -1120
- package/CHANGELOG.md +0 -209
- package/CLAUDE.md +0 -217
- package/demo.html +0 -847
- 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/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-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/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/hooks/HookManager.ts +0 -177
- package/src/index.ts +0 -395
- package/src/main.ts +0 -196
- package/src/serializers/SerializerRegistry.ts +0 -173
- 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 -242
- 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/types/index.ts +0 -83
- 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/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/{public → dist}/vite.svg +0 -0
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview File-based log handler for Advanced Logger
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { ILogHandler, LogLevel, LogMetadata } from '../types/index.js';
|
|
6
|
-
import { isNode, isBrowser } from '../utils/environment.js';
|
|
7
|
-
import { safeSerialize } from '../utils/formatting.js';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Universal file-based log handler for persistent logging
|
|
11
|
-
* Works in both Node.js (real files) and browser (localStorage)
|
|
12
|
-
*/
|
|
13
|
-
export class FileLogHandler implements ILogHandler {
|
|
14
|
-
private filename: string;
|
|
15
|
-
private maxSize?: number;
|
|
16
|
-
private fs?: any; // Node.js fs module
|
|
17
|
-
|
|
18
|
-
constructor(filename: string = 'app.log', maxSize?: number) {
|
|
19
|
-
this.filename = filename;
|
|
20
|
-
this.maxSize = maxSize;
|
|
21
|
-
|
|
22
|
-
// Load Node.js fs module if in Node environment
|
|
23
|
-
if (isNode) {
|
|
24
|
-
try {
|
|
25
|
-
this.fs = require('fs');
|
|
26
|
-
} catch (error) {
|
|
27
|
-
console.warn('FileLogHandler: Unable to load fs module:', error);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
handle(level: LogLevel, message: string, args: any[], metadata: LogMetadata): void {
|
|
33
|
-
const logEntry = {
|
|
34
|
-
timestamp: metadata.timestamp,
|
|
35
|
-
level: level.toUpperCase(),
|
|
36
|
-
prefix: metadata.prefix,
|
|
37
|
-
message,
|
|
38
|
-
args: args.slice(1).map(arg => safeSerialize(arg)),
|
|
39
|
-
location: metadata.stackInfo,
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const logLine = this.formatLogLine(logEntry);
|
|
43
|
-
|
|
44
|
-
if (isNode && this.fs) {
|
|
45
|
-
this.writeToFileNode(logLine);
|
|
46
|
-
} else if (isBrowser) {
|
|
47
|
-
this.writeToFileLocal(logLine);
|
|
48
|
-
} else {
|
|
49
|
-
// Fallback - just console output
|
|
50
|
-
console.log(`[FILE-LOG] ${logLine}`);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Format log entry as a single line for file storage
|
|
56
|
-
*/
|
|
57
|
-
private formatLogLine(entry: any): string {
|
|
58
|
-
const parts = [
|
|
59
|
-
entry.timestamp,
|
|
60
|
-
`[${entry.level}]`,
|
|
61
|
-
entry.prefix ? `[${entry.prefix}]` : '',
|
|
62
|
-
entry.message
|
|
63
|
-
].filter(Boolean);
|
|
64
|
-
|
|
65
|
-
let line = parts.join(' ');
|
|
66
|
-
|
|
67
|
-
if (entry.args && entry.args.length > 0) {
|
|
68
|
-
line += ' ' + entry.args.map((arg: any) =>
|
|
69
|
-
typeof arg === 'object' ? JSON.stringify(arg) : String(arg)
|
|
70
|
-
).join(' ');
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (entry.location) {
|
|
74
|
-
line += ` (${entry.location.file}:${entry.location.line}:${entry.location.column})`;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return line;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Write to actual file in Node.js environment
|
|
82
|
-
*/
|
|
83
|
-
private writeToFileNode(logLine: string): void {
|
|
84
|
-
if (!this.fs) return;
|
|
85
|
-
|
|
86
|
-
try {
|
|
87
|
-
// Check file size if maxSize is set
|
|
88
|
-
if (this.maxSize) {
|
|
89
|
-
try {
|
|
90
|
-
const stats = this.fs.statSync(this.filename);
|
|
91
|
-
if (stats.size > this.maxSize) {
|
|
92
|
-
// Simple rotation: backup current file and start fresh
|
|
93
|
-
const backupName = `${this.filename}.bak`;
|
|
94
|
-
this.fs.renameSync(this.filename, backupName);
|
|
95
|
-
}
|
|
96
|
-
} catch (error) {
|
|
97
|
-
// File doesn't exist yet, that's fine
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Append to file
|
|
102
|
-
this.fs.appendFileSync(this.filename, logLine + '\n', 'utf8');
|
|
103
|
-
} catch (error) {
|
|
104
|
-
console.error('FileLogHandler: Failed to write to file:', error);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Write to localStorage in browser environment
|
|
110
|
-
*/
|
|
111
|
-
private writeToFileLocal(logLine: string): void {
|
|
112
|
-
try {
|
|
113
|
-
const storageKey = `logger_${this.filename}`;
|
|
114
|
-
const existingLogs = localStorage.getItem(storageKey) || '';
|
|
115
|
-
|
|
116
|
-
let newLogs = existingLogs;
|
|
117
|
-
if (existingLogs.length > 0) {
|
|
118
|
-
newLogs += '\n';
|
|
119
|
-
}
|
|
120
|
-
newLogs += logLine;
|
|
121
|
-
|
|
122
|
-
// Simple size management - keep last 1000 lines max
|
|
123
|
-
if (this.maxSize || newLogs.split('\n').length > 1000) {
|
|
124
|
-
const lines = newLogs.split('\n');
|
|
125
|
-
const maxLines = this.maxSize ? Math.floor(this.maxSize / 100) : 1000;
|
|
126
|
-
if (lines.length > maxLines) {
|
|
127
|
-
newLogs = lines.slice(-maxLines).join('\n');
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
localStorage.setItem(storageKey, newLogs);
|
|
132
|
-
} catch (error) {
|
|
133
|
-
console.error('FileLogHandler: Failed to write to localStorage:', error);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Get stored logs (useful for debugging)
|
|
139
|
-
*/
|
|
140
|
-
getLogs(): string | null {
|
|
141
|
-
if (isNode && this.fs) {
|
|
142
|
-
try {
|
|
143
|
-
return this.fs.readFileSync(this.filename, 'utf8');
|
|
144
|
-
} catch (error) {
|
|
145
|
-
return null;
|
|
146
|
-
}
|
|
147
|
-
} else if (isBrowser) {
|
|
148
|
-
const storageKey = `logger_${this.filename}`;
|
|
149
|
-
return localStorage.getItem(storageKey);
|
|
150
|
-
}
|
|
151
|
-
return null;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Clear stored logs
|
|
156
|
-
*/
|
|
157
|
-
clearLogs(): void {
|
|
158
|
-
if (isNode && this.fs) {
|
|
159
|
-
try {
|
|
160
|
-
this.fs.writeFileSync(this.filename, '', 'utf8');
|
|
161
|
-
} catch (error) {
|
|
162
|
-
console.error('FileLogHandler: Failed to clear file:', error);
|
|
163
|
-
}
|
|
164
|
-
} else if (isBrowser) {
|
|
165
|
-
const storageKey = `logger_${this.filename}`;
|
|
166
|
-
localStorage.removeItem(storageKey);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Remote log handler for Advanced Logger
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type { ILogHandler, LogLevel, LogMetadata } from '../types/index.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Remote log handler for sending logs to external services
|
|
9
|
-
*/
|
|
10
|
-
export class RemoteLogHandler implements ILogHandler {
|
|
11
|
-
private endpoint: string;
|
|
12
|
-
private apiKey?: string;
|
|
13
|
-
|
|
14
|
-
constructor(endpoint: string, apiKey?: string) {
|
|
15
|
-
this.endpoint = endpoint;
|
|
16
|
-
this.apiKey = apiKey;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async handle(level: LogLevel, message: string, args: any[], metadata: LogMetadata): Promise<void> {
|
|
20
|
-
try {
|
|
21
|
-
const payload = {
|
|
22
|
-
timestamp: metadata.timestamp,
|
|
23
|
-
level,
|
|
24
|
-
message,
|
|
25
|
-
prefix: metadata.prefix,
|
|
26
|
-
location: metadata.stackInfo,
|
|
27
|
-
additional: args.slice(1),
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
await fetch(this.endpoint, {
|
|
31
|
-
method: 'POST',
|
|
32
|
-
headers: {
|
|
33
|
-
'Content-Type': 'application/json',
|
|
34
|
-
...(this.apiKey && { 'Authorization': `Bearer ${this.apiKey}` }),
|
|
35
|
-
},
|
|
36
|
-
body: JSON.stringify(payload),
|
|
37
|
-
});
|
|
38
|
-
} catch (error) {
|
|
39
|
-
// Silently fail to avoid infinite logging loops
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
package/src/hooks/HookManager.ts
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
HookLogEntry,
|
|
3
|
-
HookEvent,
|
|
4
|
-
HookCallback,
|
|
5
|
-
MiddlewareFn,
|
|
6
|
-
HookRegistration,
|
|
7
|
-
MiddlewareRegistration,
|
|
8
|
-
IHookManager
|
|
9
|
-
} from '../types/index.js';
|
|
10
|
-
|
|
11
|
-
function generateId(): string {
|
|
12
|
-
return `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class HookManager implements IHookManager {
|
|
16
|
-
private hooks: Map<HookEvent, HookRegistration[]> = new Map();
|
|
17
|
-
private middlewares: MiddlewareRegistration[] = [];
|
|
18
|
-
|
|
19
|
-
constructor() {
|
|
20
|
-
this.hooks.set('beforeLog', []);
|
|
21
|
-
this.hooks.set('afterLog', []);
|
|
22
|
-
this.hooks.set('onError', []);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
on(event: HookEvent, callback: HookCallback, priority: number = 50): () => void {
|
|
26
|
-
const registration: HookRegistration = {
|
|
27
|
-
id: generateId(),
|
|
28
|
-
event,
|
|
29
|
-
callback,
|
|
30
|
-
priority,
|
|
31
|
-
once: false
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const hooks = this.hooks.get(event)!;
|
|
35
|
-
hooks.push(registration);
|
|
36
|
-
hooks.sort((a, b) => b.priority - a.priority);
|
|
37
|
-
|
|
38
|
-
return () => this.removeHook(event, registration.id);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
once(event: HookEvent, callback: HookCallback, priority: number = 50): () => void {
|
|
42
|
-
const registration: HookRegistration = {
|
|
43
|
-
id: generateId(),
|
|
44
|
-
event,
|
|
45
|
-
callback,
|
|
46
|
-
priority,
|
|
47
|
-
once: true
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const hooks = this.hooks.get(event)!;
|
|
51
|
-
hooks.push(registration);
|
|
52
|
-
hooks.sort((a, b) => b.priority - a.priority);
|
|
53
|
-
|
|
54
|
-
return () => this.removeHook(event, registration.id);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
off(event: HookEvent, callback: HookCallback): boolean {
|
|
58
|
-
const hooks = this.hooks.get(event);
|
|
59
|
-
if (!hooks) return false;
|
|
60
|
-
|
|
61
|
-
const index = hooks.findIndex(h => h.callback === callback);
|
|
62
|
-
if (index >= 0) {
|
|
63
|
-
hooks.splice(index, 1);
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
private removeHook(event: HookEvent, id: string): void {
|
|
70
|
-
const hooks = this.hooks.get(event);
|
|
71
|
-
if (hooks) {
|
|
72
|
-
const index = hooks.findIndex(h => h.id === id);
|
|
73
|
-
if (index >= 0) {
|
|
74
|
-
hooks.splice(index, 1);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
use(middleware: MiddlewareFn, priority: number = 50): () => void {
|
|
80
|
-
const registration: MiddlewareRegistration = {
|
|
81
|
-
id: generateId(),
|
|
82
|
-
fn: middleware,
|
|
83
|
-
priority
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
this.middlewares.push(registration);
|
|
87
|
-
this.middlewares.sort((a, b) => b.priority - a.priority);
|
|
88
|
-
|
|
89
|
-
return () => {
|
|
90
|
-
const index = this.middlewares.findIndex(m => m.id === registration.id);
|
|
91
|
-
if (index >= 0) {
|
|
92
|
-
this.middlewares.splice(index, 1);
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
async emit(event: HookEvent, entry: HookLogEntry): Promise<HookLogEntry> {
|
|
98
|
-
const hooks = this.hooks.get(event) || [];
|
|
99
|
-
let currentEntry = { ...entry };
|
|
100
|
-
const toRemove: string[] = [];
|
|
101
|
-
|
|
102
|
-
for (const hook of hooks) {
|
|
103
|
-
try {
|
|
104
|
-
const result = await hook.callback(currentEntry);
|
|
105
|
-
if (result) {
|
|
106
|
-
currentEntry = { ...currentEntry, ...result };
|
|
107
|
-
}
|
|
108
|
-
if (hook.once) {
|
|
109
|
-
toRemove.push(hook.id);
|
|
110
|
-
}
|
|
111
|
-
} catch (error) {
|
|
112
|
-
if (event !== 'onError') {
|
|
113
|
-
await this.emit('onError', {
|
|
114
|
-
...currentEntry,
|
|
115
|
-
error,
|
|
116
|
-
hookEvent: event
|
|
117
|
-
} as HookLogEntry);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
toRemove.forEach(id => this.removeHook(event, id));
|
|
123
|
-
return currentEntry;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
async process(entry: HookLogEntry): Promise<HookLogEntry> {
|
|
127
|
-
let currentEntry = { ...entry };
|
|
128
|
-
|
|
129
|
-
currentEntry = await this.emit('beforeLog', currentEntry);
|
|
130
|
-
|
|
131
|
-
if (this.middlewares.length > 0) {
|
|
132
|
-
let index = 0;
|
|
133
|
-
|
|
134
|
-
const executeNext = async (): Promise<void> => {
|
|
135
|
-
if (index < this.middlewares.length) {
|
|
136
|
-
const middleware = this.middlewares[index++];
|
|
137
|
-
if (middleware) {
|
|
138
|
-
await middleware.fn(currentEntry, executeNext);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
await executeNext();
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return currentEntry;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
async afterProcess(entry: HookLogEntry): Promise<void> {
|
|
150
|
-
await this.emit('afterLog', entry);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
clear(): void {
|
|
154
|
-
this.hooks.forEach(hooks => hooks.length = 0);
|
|
155
|
-
this.middlewares.length = 0;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
getStats(): { hooks: Record<HookEvent, number>; middlewares: number } {
|
|
159
|
-
return {
|
|
160
|
-
hooks: {
|
|
161
|
-
beforeLog: this.hooks.get('beforeLog')?.length || 0,
|
|
162
|
-
afterLog: this.hooks.get('afterLog')?.length || 0,
|
|
163
|
-
onError: this.hooks.get('onError')?.length || 0
|
|
164
|
-
},
|
|
165
|
-
middlewares: this.middlewares.length
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
let _defaultHookManager: HookManager | null = null;
|
|
171
|
-
|
|
172
|
-
export function getDefaultHookManager(): HookManager {
|
|
173
|
-
if (!_defaultHookManager) {
|
|
174
|
-
_defaultHookManager = new HookManager();
|
|
175
|
-
}
|
|
176
|
-
return _defaultHookManager;
|
|
177
|
-
}
|