@mks2508/better-logger 4.0.0 → 5.0.1
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/CHANGELOG.json +67 -1
- package/package.json +28 -3
- package/packages/core/package.json +1 -1
- package/packages/exports/package.json +2 -2
- package/packages/styling/package.json +2 -2
- package/playground/demo-all.ts +95 -0
- package/playground/demo-box.ts +85 -0
- package/playground/demo-levels.ts +56 -0
- package/playground/demo-real-world.ts +98 -0
- package/playground/demo-spinner.ts +77 -0
- package/playground/demo-steps.ts +72 -0
- package/playground/demo-table.ts +83 -0
- package/src/Logger.ts +213 -8
- package/src/ScopedLogger.ts +43 -1
- package/src/cli-module.ts +21 -0
- package/src/cli-primitives/box.ts +86 -0
- package/src/cli-primitives/cli-table.ts +62 -0
- package/src/cli-primitives/divider.ts +17 -0
- package/src/cli-primitives/header.ts +18 -0
- package/src/cli-primitives/index.ts +13 -0
- package/src/cli-primitives/server-fallback.ts +54 -0
- package/src/cli-primitives/spinner.ts +133 -0
- package/src/cli-primitives/step.ts +22 -0
- package/src/constants.ts +14 -2
- package/src/index.ts +18 -1
- package/src/terminal/formatter.ts +16 -10
- package/src/types/core.ts +53 -0
- package/src/types/index.ts +4 -0
- package/vite.config.ts +33 -0
- package/bun.lock +0 -333
- package/dist/Logger.d.ts +0 -863
- package/dist/Logger.d.ts.map +0 -1
- package/dist/ScopedLogger.d.ts +0 -57
- package/dist/ScopedLogger.d.ts.map +0 -1
- package/dist/chunks/Logger-D-gmmgR2.js +0 -4458
- package/dist/chunks/Logger-D-gmmgR2.js.map +0 -1
- package/dist/chunks/Logger-D7cfaz15.js +0 -2
- package/dist/chunks/Logger-D7cfaz15.js.map +0 -1
- package/dist/chunks/RemoteLogHandler-CjWpWZGl.js +0 -33
- package/dist/chunks/RemoteLogHandler-CjWpWZGl.js.map +0 -1
- package/dist/chunks/RemoteLogHandler-ymkQ97xl.js +0 -2
- package/dist/chunks/RemoteLogHandler-ymkQ97xl.js.map +0 -1
- package/dist/chunks/environment-COWvu6Wz.js +0 -1577
- package/dist/chunks/environment-COWvu6Wz.js.map +0 -1
- package/dist/chunks/environment-C_8J-zQ_.js +0 -4
- package/dist/chunks/environment-C_8J-zQ_.js.map +0 -1
- package/dist/chunks/formatting-CYjT9yhO.js +0 -380
- package/dist/chunks/formatting-CYjT9yhO.js.map +0 -1
- package/dist/chunks/formatting-Cg5YhB9Y.js +0 -2
- package/dist/chunks/formatting-Cg5YhB9Y.js.map +0 -1
- package/dist/cli/CommandProcessor.d.ts +0 -100
- package/dist/cli/CommandProcessor.d.ts.map +0 -1
- package/dist/cli/commands/ConfigCommand.d.ts +0 -14
- package/dist/cli/commands/ConfigCommand.d.ts.map +0 -1
- package/dist/cli/commands/ExportCommand.d.ts +0 -48
- package/dist/cli/commands/ExportCommand.d.ts.map +0 -1
- package/dist/cli/commands/HistoryCommand.d.ts +0 -47
- package/dist/cli/commands/HistoryCommand.d.ts.map +0 -1
- package/dist/cli/commands/StatusCommand.d.ts +0 -30
- package/dist/cli/commands/StatusCommand.d.ts.map +0 -1
- package/dist/cli/commands/ThemeCommand.d.ts +0 -30
- package/dist/cli/commands/ThemeCommand.d.ts.map +0 -1
- package/dist/cli/help.d.ts +0 -12
- package/dist/cli/help.d.ts.map +0 -1
- package/dist/cli/index.d.ts +0 -15
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/constants.d.ts +0 -227
- package/dist/constants.d.ts.map +0 -1
- package/dist/core.cjs +0 -2
- package/dist/core.cjs.map +0 -1
- package/dist/core.d.ts +0 -127
- package/dist/core.d.ts.map +0 -1
- package/dist/core.js +0 -291
- package/dist/core.js.map +0 -1
- package/dist/example.d.ts +0 -18
- package/dist/example.d.ts.map +0 -1
- package/dist/exports-module.d.ts +0 -196
- package/dist/exports-module.d.ts.map +0 -1
- package/dist/exports.cjs +0 -2
- package/dist/exports.cjs.map +0 -1
- package/dist/exports.js +0 -238
- package/dist/exports.js.map +0 -1
- package/dist/handlers/AnalyticsLogHandler.d.ts +0 -8
- package/dist/handlers/AnalyticsLogHandler.d.ts.map +0 -1
- package/dist/handlers/ExportLogHandler.d.ts +0 -100
- package/dist/handlers/ExportLogHandler.d.ts.map +0 -1
- package/dist/handlers/FileLogHandler.d.ts +0 -33
- package/dist/handlers/FileLogHandler.d.ts.map +0 -1
- package/dist/handlers/RemoteLogHandler.d.ts +0 -11
- package/dist/handlers/RemoteLogHandler.d.ts.map +0 -1
- package/dist/handlers/index.d.ts +0 -8
- package/dist/handlers/index.d.ts.map +0 -1
- package/dist/hooks/HookManager.d.ts +0 -21
- package/dist/hooks/HookManager.d.ts.map +0 -1
- package/dist/hooks/index.d.ts +0 -2
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/index.cjs +0 -2
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts +0 -153
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -609
- package/dist/index.js.map +0 -1
- package/dist/main.d.ts +0 -2
- package/dist/main.d.ts.map +0 -1
- package/dist/serializers/SerializerRegistry.d.ts +0 -16
- package/dist/serializers/SerializerRegistry.d.ts.map +0 -1
- package/dist/serializers/index.d.ts +0 -2
- package/dist/serializers/index.d.ts.map +0 -1
- package/dist/styling/LogStyleBuilder.d.ts +0 -146
- package/dist/styling/LogStyleBuilder.d.ts.map +0 -1
- package/dist/styling/SemanticStyles.d.ts +0 -178
- package/dist/styling/SemanticStyles.d.ts.map +0 -1
- package/dist/styling/SmartPresets.d.ts +0 -22
- package/dist/styling/SmartPresets.d.ts.map +0 -1
- package/dist/styling/StyleBuilder.d.ts +0 -140
- package/dist/styling/StyleBuilder.d.ts.map +0 -1
- package/dist/styling/StyleCache.d.ts +0 -42
- package/dist/styling/StyleCache.d.ts.map +0 -1
- package/dist/styling/banners.d.ts +0 -42
- package/dist/styling/banners.d.ts.map +0 -1
- package/dist/styling/index.d.ts +0 -10
- package/dist/styling/index.d.ts.map +0 -1
- package/dist/styling/themes.d.ts +0 -7
- package/dist/styling/themes.d.ts.map +0 -1
- package/dist/styling-module.d.ts +0 -178
- package/dist/styling-module.d.ts.map +0 -1
- package/dist/styling.cjs +0 -2
- package/dist/styling.cjs.map +0 -1
- package/dist/styling.js +0 -146
- package/dist/styling.js.map +0 -1
- package/dist/terminal/color-converter.d.ts +0 -73
- package/dist/terminal/color-converter.d.ts.map +0 -1
- package/dist/terminal/formatter.d.ts +0 -20
- package/dist/terminal/formatter.d.ts.map +0 -1
- package/dist/terminal/terminal-renderer.d.ts +0 -77
- package/dist/terminal/terminal-renderer.d.ts.map +0 -1
- package/dist/transports/ConsoleTransport.d.ts +0 -9
- package/dist/transports/ConsoleTransport.d.ts.map +0 -1
- package/dist/transports/FileTransport.d.ts +0 -15
- package/dist/transports/FileTransport.d.ts.map +0 -1
- package/dist/transports/HttpTransport.d.ts +0 -16
- package/dist/transports/HttpTransport.d.ts.map +0 -1
- package/dist/transports/TransportManager.d.ts +0 -14
- package/dist/transports/TransportManager.d.ts.map +0 -1
- package/dist/transports/index.d.ts +0 -5
- package/dist/transports/index.d.ts.map +0 -1
- package/dist/types/core.d.ts +0 -333
- package/dist/types/core.d.ts.map +0 -1
- package/dist/types/handlers.d.ts +0 -85
- package/dist/types/handlers.d.ts.map +0 -1
- package/dist/types/hooks.d.ts +0 -36
- package/dist/types/hooks.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -11
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/serializers.d.ts +0 -25
- package/dist/types/serializers.d.ts.map +0 -1
- package/dist/types/transports.d.ts +0 -47
- package/dist/types/transports.d.ts.map +0 -1
- package/dist/utils/adapter.d.ts +0 -48
- package/dist/utils/adapter.d.ts.map +0 -1
- package/dist/utils/ansi-colors.d.ts +0 -156
- package/dist/utils/ansi-colors.d.ts.map +0 -1
- package/dist/utils/environment-detector.d.ts +0 -45
- package/dist/utils/environment-detector.d.ts.map +0 -1
- package/dist/utils/environment.d.ts +0 -47
- package/dist/utils/environment.d.ts.map +0 -1
- package/dist/utils/formatting.d.ts +0 -58
- package/dist/utils/formatting.d.ts.map +0 -1
- package/dist/utils/index.d.ts +0 -8
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/opentui-detection.d.ts +0 -34
- package/dist/utils/opentui-detection.d.ts.map +0 -1
- package/dist/utils/output.d.ts +0 -46
- package/dist/utils/output.d.ts.map +0 -1
- package/dist/utils/stackTrace.d.ts +0 -6
- package/dist/utils/stackTrace.d.ts.map +0 -1
- package/dist/utils/timestamps.d.ts +0 -20
- package/dist/utils/timestamps.d.ts.map +0 -1
- package/dist/vite.svg +0 -1
- package/dist/writers/BufferWriter.d.ts +0 -96
- package/dist/writers/BufferWriter.d.ts.map +0 -1
- package/dist/writers/index.d.ts +0 -6
- package/dist/writers/index.d.ts.map +0 -1
package/dist/index.js
DELETED
|
@@ -1,609 +0,0 @@
|
|
|
1
|
-
import { L as Logger } from "./chunks/Logger-D-gmmgR2.js";
|
|
2
|
-
import { A, B, C, d, H, c, S, a, T, b, n, h, e, k, g, j, i, f, m, l, p, r, s } from "./chunks/Logger-D-gmmgR2.js";
|
|
3
|
-
import { i as isNode, a as isBrowser, S as StylePresets, b as StyleBuilder } from "./chunks/environment-COWvu6Wz.js";
|
|
4
|
-
import { A as A2, B as B2, D, E, T as T2, e as e2, n as n2, d as d2, f as f2, m as m2, l as l2, k as k2, j as j2, t, o, w, g as g2, v, u, c as c2, h as h2, q, p as p2, r as r2, s as s2 } from "./chunks/environment-COWvu6Wz.js";
|
|
5
|
-
import { s as safeSerialize } from "./chunks/formatting-CYjT9yhO.js";
|
|
6
|
-
import { B as B3, h as h3, i as i2, g as g3, j as j3, f as f3, k as k3, a as a2, b as b2, e as e3, c as c3, d as d3, l as l3, m as m3, n as n3 } from "./chunks/formatting-CYjT9yhO.js";
|
|
7
|
-
import { R } from "./chunks/RemoteLogHandler-CjWpWZGl.js";
|
|
8
|
-
class ConsoleTransport {
|
|
9
|
-
constructor(options) {
|
|
10
|
-
this.options = options;
|
|
11
|
-
}
|
|
12
|
-
name = "console";
|
|
13
|
-
write(record) {
|
|
14
|
-
const method = this.getConsoleMethod(record.level);
|
|
15
|
-
const prefix = record.prefix ? `[${record.prefix}] ` : "";
|
|
16
|
-
const location = record.location ? ` (${record.location.file}:${record.location.line})` : "";
|
|
17
|
-
console[method](`[${record.level.toUpperCase()}]${prefix} ${record.msg}${location}`);
|
|
18
|
-
}
|
|
19
|
-
getConsoleMethod(level) {
|
|
20
|
-
switch (level) {
|
|
21
|
-
case "debug":
|
|
22
|
-
return "log";
|
|
23
|
-
case "info":
|
|
24
|
-
return "info";
|
|
25
|
-
case "warn":
|
|
26
|
-
return "warn";
|
|
27
|
-
case "error":
|
|
28
|
-
case "critical":
|
|
29
|
-
return "error";
|
|
30
|
-
default:
|
|
31
|
-
return "log";
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
class FileTransport {
|
|
36
|
-
name = "file";
|
|
37
|
-
buffer = [];
|
|
38
|
-
flushTimer;
|
|
39
|
-
options;
|
|
40
|
-
constructor(options) {
|
|
41
|
-
this.options = options || {};
|
|
42
|
-
if (this.options.flushInterval) {
|
|
43
|
-
this.flushTimer = setInterval(() => this.flush(), this.options.flushInterval);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
write(record) {
|
|
47
|
-
const line = JSON.stringify(record) + "\n";
|
|
48
|
-
this.buffer.push(line);
|
|
49
|
-
if (this.buffer.length >= (this.options.batchSize || 100)) {
|
|
50
|
-
this.flush();
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
async flush() {
|
|
54
|
-
if (this.buffer.length === 0) return;
|
|
55
|
-
const lines = this.buffer.join("");
|
|
56
|
-
this.buffer = [];
|
|
57
|
-
if (typeof globalThis.process !== "undefined" && typeof require === "function") {
|
|
58
|
-
try {
|
|
59
|
-
const fs = require("fs");
|
|
60
|
-
const dest = this.options.destination || "app.log";
|
|
61
|
-
fs.appendFileSync(dest, lines);
|
|
62
|
-
} catch {
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
close() {
|
|
67
|
-
if (this.flushTimer) {
|
|
68
|
-
clearInterval(this.flushTimer);
|
|
69
|
-
}
|
|
70
|
-
this.flush();
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
class HttpTransport {
|
|
74
|
-
name = "http";
|
|
75
|
-
buffer = [];
|
|
76
|
-
flushTimer;
|
|
77
|
-
options;
|
|
78
|
-
constructor(options) {
|
|
79
|
-
this.options = options || {};
|
|
80
|
-
if (this.options.flushInterval) {
|
|
81
|
-
this.flushTimer = setInterval(() => this.flush(), this.options.flushInterval);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
write(record) {
|
|
85
|
-
this.buffer.push(record);
|
|
86
|
-
if (this.buffer.length >= (this.options.batchSize || 50)) {
|
|
87
|
-
this.flush();
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
async flush() {
|
|
91
|
-
if (this.buffer.length === 0 || !this.options.url) return;
|
|
92
|
-
const records = [...this.buffer];
|
|
93
|
-
this.buffer = [];
|
|
94
|
-
try {
|
|
95
|
-
await fetch(this.options.url, {
|
|
96
|
-
method: "POST",
|
|
97
|
-
headers: {
|
|
98
|
-
"Content-Type": "application/json",
|
|
99
|
-
...this.options.headers
|
|
100
|
-
},
|
|
101
|
-
body: JSON.stringify({ logs: records })
|
|
102
|
-
});
|
|
103
|
-
} catch {
|
|
104
|
-
this.buffer.unshift(...records);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
close() {
|
|
108
|
-
if (this.flushTimer) {
|
|
109
|
-
clearInterval(this.flushTimer);
|
|
110
|
-
}
|
|
111
|
-
this.flush();
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
class FileLogHandler {
|
|
115
|
-
filename;
|
|
116
|
-
maxSize;
|
|
117
|
-
fs;
|
|
118
|
-
// Node.js fs module
|
|
119
|
-
constructor(filename = "app.log", maxSize) {
|
|
120
|
-
this.filename = filename;
|
|
121
|
-
this.maxSize = maxSize;
|
|
122
|
-
if (isNode) {
|
|
123
|
-
try {
|
|
124
|
-
this.fs = require("fs");
|
|
125
|
-
} catch (error2) {
|
|
126
|
-
console.warn("FileLogHandler: Unable to load fs module:", error2);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
handle(level, message, args, metadata) {
|
|
131
|
-
const logEntry = {
|
|
132
|
-
timestamp: metadata.timestamp,
|
|
133
|
-
level: level.toUpperCase(),
|
|
134
|
-
prefix: metadata.prefix,
|
|
135
|
-
message,
|
|
136
|
-
args: args.slice(1).map((arg) => safeSerialize(arg)),
|
|
137
|
-
location: metadata.stackInfo
|
|
138
|
-
};
|
|
139
|
-
const logLine = this.formatLogLine(logEntry);
|
|
140
|
-
if (isNode && this.fs) {
|
|
141
|
-
this.writeToFileNode(logLine);
|
|
142
|
-
} else if (isBrowser) {
|
|
143
|
-
this.writeToFileLocal(logLine);
|
|
144
|
-
} else {
|
|
145
|
-
console.log(`[FILE-LOG] ${logLine}`);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Format log entry as a single line for file storage
|
|
150
|
-
*/
|
|
151
|
-
formatLogLine(entry) {
|
|
152
|
-
const parts = [
|
|
153
|
-
entry.timestamp,
|
|
154
|
-
`[${entry.level}]`,
|
|
155
|
-
entry.prefix ? `[${entry.prefix}]` : "",
|
|
156
|
-
entry.message
|
|
157
|
-
].filter(Boolean);
|
|
158
|
-
let line = parts.join(" ");
|
|
159
|
-
if (entry.args && entry.args.length > 0) {
|
|
160
|
-
line += " " + entry.args.map(
|
|
161
|
-
(arg) => typeof arg === "object" ? JSON.stringify(arg) : String(arg)
|
|
162
|
-
).join(" ");
|
|
163
|
-
}
|
|
164
|
-
if (entry.location) {
|
|
165
|
-
line += ` (${entry.location.file}:${entry.location.line}:${entry.location.column})`;
|
|
166
|
-
}
|
|
167
|
-
return line;
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Write to actual file in Node.js environment
|
|
171
|
-
*/
|
|
172
|
-
writeToFileNode(logLine) {
|
|
173
|
-
if (!this.fs) return;
|
|
174
|
-
try {
|
|
175
|
-
if (this.maxSize) {
|
|
176
|
-
try {
|
|
177
|
-
const stats = this.fs.statSync(this.filename);
|
|
178
|
-
if (stats.size > this.maxSize) {
|
|
179
|
-
const backupName = `${this.filename}.bak`;
|
|
180
|
-
this.fs.renameSync(this.filename, backupName);
|
|
181
|
-
}
|
|
182
|
-
} catch (error2) {
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
this.fs.appendFileSync(this.filename, logLine + "\n", "utf8");
|
|
186
|
-
} catch (error2) {
|
|
187
|
-
console.error("FileLogHandler: Failed to write to file:", error2);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Write to localStorage in browser environment
|
|
192
|
-
*/
|
|
193
|
-
writeToFileLocal(logLine) {
|
|
194
|
-
try {
|
|
195
|
-
const storageKey = `logger_${this.filename}`;
|
|
196
|
-
const existingLogs = localStorage.getItem(storageKey) || "";
|
|
197
|
-
let newLogs = existingLogs;
|
|
198
|
-
if (existingLogs.length > 0) {
|
|
199
|
-
newLogs += "\n";
|
|
200
|
-
}
|
|
201
|
-
newLogs += logLine;
|
|
202
|
-
if (this.maxSize || newLogs.split("\n").length > 1e3) {
|
|
203
|
-
const lines = newLogs.split("\n");
|
|
204
|
-
const maxLines = this.maxSize ? Math.floor(this.maxSize / 100) : 1e3;
|
|
205
|
-
if (lines.length > maxLines) {
|
|
206
|
-
newLogs = lines.slice(-maxLines).join("\n");
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
localStorage.setItem(storageKey, newLogs);
|
|
210
|
-
} catch (error2) {
|
|
211
|
-
console.error("FileLogHandler: Failed to write to localStorage:", error2);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Get stored logs (useful for debugging)
|
|
216
|
-
*/
|
|
217
|
-
getLogs() {
|
|
218
|
-
if (isNode && this.fs) {
|
|
219
|
-
try {
|
|
220
|
-
return this.fs.readFileSync(this.filename, "utf8");
|
|
221
|
-
} catch (error2) {
|
|
222
|
-
return null;
|
|
223
|
-
}
|
|
224
|
-
} else if (isBrowser) {
|
|
225
|
-
const storageKey = `logger_${this.filename}`;
|
|
226
|
-
return localStorage.getItem(storageKey);
|
|
227
|
-
}
|
|
228
|
-
return null;
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Clear stored logs
|
|
232
|
-
*/
|
|
233
|
-
clearLogs() {
|
|
234
|
-
if (isNode && this.fs) {
|
|
235
|
-
try {
|
|
236
|
-
this.fs.writeFileSync(this.filename, "", "utf8");
|
|
237
|
-
} catch (error2) {
|
|
238
|
-
console.error("FileLogHandler: Failed to clear file:", error2);
|
|
239
|
-
}
|
|
240
|
-
} else if (isBrowser) {
|
|
241
|
-
const storageKey = `logger_${this.filename}`;
|
|
242
|
-
localStorage.removeItem(storageKey);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
class AnalyticsLogHandler {
|
|
247
|
-
handle(level, message, _args, metadata) {
|
|
248
|
-
if (level === "error" || level === "critical") {
|
|
249
|
-
console.debug("Analytics: Error tracked", {
|
|
250
|
-
level,
|
|
251
|
-
message,
|
|
252
|
-
timestamp: metadata.timestamp
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
const DEFAULT_CONFIG = {
|
|
258
|
-
maxEntries: 100,
|
|
259
|
-
ttl: 5 * 60 * 1e3,
|
|
260
|
-
enabled: true
|
|
261
|
-
};
|
|
262
|
-
class StyleCache {
|
|
263
|
-
cache = /* @__PURE__ */ new Map();
|
|
264
|
-
config;
|
|
265
|
-
hitCount = 0;
|
|
266
|
-
missCount = 0;
|
|
267
|
-
constructor(config = {}) {
|
|
268
|
-
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
269
|
-
}
|
|
270
|
-
generateKey(key) {
|
|
271
|
-
return `${key.level}:${key.theme}:${key.presetName || "default"}:${key.hasPrefix}:${key.hasLocation}`;
|
|
272
|
-
}
|
|
273
|
-
get(key) {
|
|
274
|
-
if (!this.config.enabled) return null;
|
|
275
|
-
const cacheKey = this.generateKey(key);
|
|
276
|
-
const entry = this.cache.get(cacheKey);
|
|
277
|
-
if (!entry) {
|
|
278
|
-
this.missCount++;
|
|
279
|
-
return null;
|
|
280
|
-
}
|
|
281
|
-
if (Date.now() - entry.createdAt > this.config.ttl) {
|
|
282
|
-
this.cache.delete(cacheKey);
|
|
283
|
-
this.missCount++;
|
|
284
|
-
return null;
|
|
285
|
-
}
|
|
286
|
-
entry.hits++;
|
|
287
|
-
this.cache.delete(cacheKey);
|
|
288
|
-
this.cache.set(cacheKey, entry);
|
|
289
|
-
this.hitCount++;
|
|
290
|
-
return entry;
|
|
291
|
-
}
|
|
292
|
-
set(key, format, styles) {
|
|
293
|
-
if (!this.config.enabled) return;
|
|
294
|
-
const cacheKey = this.generateKey(key);
|
|
295
|
-
if (this.cache.size >= this.config.maxEntries) {
|
|
296
|
-
const firstKey = this.cache.keys().next().value;
|
|
297
|
-
if (firstKey) {
|
|
298
|
-
this.cache.delete(firstKey);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
this.cache.set(cacheKey, {
|
|
302
|
-
format,
|
|
303
|
-
styles: [...styles],
|
|
304
|
-
createdAt: Date.now(),
|
|
305
|
-
hits: 0
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
clear() {
|
|
309
|
-
this.cache.clear();
|
|
310
|
-
this.hitCount = 0;
|
|
311
|
-
this.missCount = 0;
|
|
312
|
-
}
|
|
313
|
-
getStats() {
|
|
314
|
-
const total = this.hitCount + this.missCount;
|
|
315
|
-
return {
|
|
316
|
-
size: this.cache.size,
|
|
317
|
-
maxSize: this.config.maxEntries,
|
|
318
|
-
hitRate: total > 0 ? this.hitCount / total : 0,
|
|
319
|
-
hits: this.hitCount,
|
|
320
|
-
misses: this.missCount
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
setEnabled(enabled) {
|
|
324
|
-
this.config.enabled = enabled;
|
|
325
|
-
if (!enabled) {
|
|
326
|
-
this.clear();
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
isEnabled() {
|
|
330
|
-
return this.config.enabled;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
let _styleCache = null;
|
|
334
|
-
function getStyleCache() {
|
|
335
|
-
if (!_styleCache) {
|
|
336
|
-
_styleCache = new StyleCache();
|
|
337
|
-
}
|
|
338
|
-
return _styleCache;
|
|
339
|
-
}
|
|
340
|
-
class BufferWriter {
|
|
341
|
-
buffer = [];
|
|
342
|
-
maxSize;
|
|
343
|
-
/**
|
|
344
|
-
* Creates a new BufferWriter
|
|
345
|
-
* @param maxSize - Maximum number of entries to buffer (default: 1000)
|
|
346
|
-
*/
|
|
347
|
-
constructor(maxSize = 1e3) {
|
|
348
|
-
this.maxSize = maxSize;
|
|
349
|
-
}
|
|
350
|
-
/**
|
|
351
|
-
* Writes a log entry to the buffer
|
|
352
|
-
* @param message - Formatted log message
|
|
353
|
-
* @param level - Log level
|
|
354
|
-
* @param styles - CSS styles (for browser console)
|
|
355
|
-
*/
|
|
356
|
-
write(message, level, styles) {
|
|
357
|
-
if (this.buffer.length >= this.maxSize) {
|
|
358
|
-
this.buffer.shift();
|
|
359
|
-
}
|
|
360
|
-
this.buffer.push({
|
|
361
|
-
message,
|
|
362
|
-
level,
|
|
363
|
-
styles,
|
|
364
|
-
timestamp: Date.now()
|
|
365
|
-
});
|
|
366
|
-
}
|
|
367
|
-
/**
|
|
368
|
-
* Returns all buffered entries
|
|
369
|
-
* @returns Copy of the buffer array
|
|
370
|
-
*/
|
|
371
|
-
getBuffer() {
|
|
372
|
-
return [...this.buffer];
|
|
373
|
-
}
|
|
374
|
-
/**
|
|
375
|
-
* Returns buffered entries filtered by log level
|
|
376
|
-
* @param levels - Log levels to include
|
|
377
|
-
* @returns Filtered buffer entries
|
|
378
|
-
*/
|
|
379
|
-
getByLevel(...levels) {
|
|
380
|
-
return this.buffer.filter((entry) => levels.includes(entry.level));
|
|
381
|
-
}
|
|
382
|
-
/**
|
|
383
|
-
* Returns the number of buffered entries
|
|
384
|
-
*/
|
|
385
|
-
get size() {
|
|
386
|
-
return this.buffer.length;
|
|
387
|
-
}
|
|
388
|
-
/**
|
|
389
|
-
* Checks if buffer is empty
|
|
390
|
-
*/
|
|
391
|
-
get isEmpty() {
|
|
392
|
-
return this.buffer.length === 0;
|
|
393
|
-
}
|
|
394
|
-
/**
|
|
395
|
-
* Clears all buffered entries
|
|
396
|
-
*/
|
|
397
|
-
clear() {
|
|
398
|
-
this.buffer = [];
|
|
399
|
-
}
|
|
400
|
-
/**
|
|
401
|
-
* Outputs all buffered entries to console and clears the buffer
|
|
402
|
-
*/
|
|
403
|
-
flush() {
|
|
404
|
-
this.buffer.forEach((entry) => {
|
|
405
|
-
if (entry.styles.length > 0) {
|
|
406
|
-
console.log(entry.message, ...entry.styles);
|
|
407
|
-
} else {
|
|
408
|
-
console.log(entry.message);
|
|
409
|
-
}
|
|
410
|
-
});
|
|
411
|
-
this.clear();
|
|
412
|
-
}
|
|
413
|
-
/**
|
|
414
|
-
* Outputs buffered entries to console without clearing
|
|
415
|
-
*/
|
|
416
|
-
replay() {
|
|
417
|
-
this.buffer.forEach((entry) => {
|
|
418
|
-
if (entry.styles.length > 0) {
|
|
419
|
-
console.log(entry.message, ...entry.styles);
|
|
420
|
-
} else {
|
|
421
|
-
console.log(entry.message);
|
|
422
|
-
}
|
|
423
|
-
});
|
|
424
|
-
}
|
|
425
|
-
/**
|
|
426
|
-
* Returns all messages as an array of strings
|
|
427
|
-
*/
|
|
428
|
-
toArray() {
|
|
429
|
-
return this.buffer.map((entry) => entry.message);
|
|
430
|
-
}
|
|
431
|
-
/**
|
|
432
|
-
* Returns all messages joined as a single string
|
|
433
|
-
* @param separator - String to join messages with (default: newline)
|
|
434
|
-
*/
|
|
435
|
-
toString(separator = "\n") {
|
|
436
|
-
return this.toArray().join(separator);
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
let _logger = null;
|
|
440
|
-
function getLogger() {
|
|
441
|
-
if (!_logger) {
|
|
442
|
-
_logger = new Logger();
|
|
443
|
-
}
|
|
444
|
-
return _logger;
|
|
445
|
-
}
|
|
446
|
-
const index = getLogger();
|
|
447
|
-
const debug = (...args) => getLogger().debug(...args);
|
|
448
|
-
const info = (...args) => getLogger().info(...args);
|
|
449
|
-
const warn = (...args) => getLogger().warn(...args);
|
|
450
|
-
const error = (...args) => getLogger().error(...args);
|
|
451
|
-
const success = (...args) => getLogger().success(...args);
|
|
452
|
-
const critical = (...args) => getLogger().critical(...args);
|
|
453
|
-
const trace = (...args) => getLogger().trace(...args);
|
|
454
|
-
const table = (data, columns) => getLogger().table(data, columns);
|
|
455
|
-
const group = (label, collapsed) => getLogger().group(label, collapsed);
|
|
456
|
-
const groupEnd = () => getLogger().groupEnd();
|
|
457
|
-
const time = (label) => getLogger().time(label);
|
|
458
|
-
const timeEnd = (label) => getLogger().timeEnd(label);
|
|
459
|
-
const setGlobalPrefix = (prefix) => getLogger().setGlobalPrefix(prefix);
|
|
460
|
-
const scope = (name) => getLogger().scope(name);
|
|
461
|
-
const component = (name) => getLogger().component(name);
|
|
462
|
-
const api = (name) => getLogger().api(name);
|
|
463
|
-
const badges = (badgeList) => getLogger().badges(badgeList);
|
|
464
|
-
const badge = (badgeName) => getLogger().badge(badgeName);
|
|
465
|
-
const clearBadges = () => getLogger().clearBadges();
|
|
466
|
-
const setVerbosity = (level) => getLogger().setVerbosity(level);
|
|
467
|
-
const addHandler = (handler) => getLogger().addHandler(handler);
|
|
468
|
-
const setTheme = (theme) => getLogger().setTheme(theme);
|
|
469
|
-
const setBannerType = (bannerType) => getLogger().setBannerType(bannerType);
|
|
470
|
-
const showBanner = (bannerType) => getLogger().showBanner(bannerType);
|
|
471
|
-
const logWithSVG = (message, svgContent, options) => getLogger().logWithSVG(message, svgContent, options);
|
|
472
|
-
const logAnimated = (message, duration) => getLogger().logAnimated(message, duration);
|
|
473
|
-
const cli = (command) => getLogger().cli(command);
|
|
474
|
-
const addSerializer = (type, serializer, priority) => getLogger().addSerializer(type, serializer, priority);
|
|
475
|
-
const removeSerializer = (type) => getLogger().removeSerializer(type);
|
|
476
|
-
const on = (event, callback, priority) => getLogger().on(event, callback, priority);
|
|
477
|
-
const once = (event, callback, priority) => getLogger().once(event, callback, priority);
|
|
478
|
-
const off = (event, callback) => getLogger().off(event, callback);
|
|
479
|
-
const use = (middleware, priority) => getLogger().use(middleware, priority);
|
|
480
|
-
const addTransport = (target) => getLogger().addTransport(target);
|
|
481
|
-
const removeTransport = (id) => getLogger().removeTransport(id);
|
|
482
|
-
const flushTransports = () => getLogger().flushTransports();
|
|
483
|
-
const closeTransports = () => getLogger().closeTransports();
|
|
484
|
-
const createStyle = () => new StyleBuilder();
|
|
485
|
-
const stylePresets = {
|
|
486
|
-
success: StylePresets.success().build(),
|
|
487
|
-
error: StylePresets.error().build(),
|
|
488
|
-
warning: StylePresets.warning().build(),
|
|
489
|
-
info: StylePresets.info().build(),
|
|
490
|
-
accent: StylePresets.accent().build()
|
|
491
|
-
};
|
|
492
|
-
export {
|
|
493
|
-
A2 as ANSI,
|
|
494
|
-
A as APILogger,
|
|
495
|
-
AnalyticsLogHandler,
|
|
496
|
-
B as BANNER_VARIANTS,
|
|
497
|
-
B3 as BUILD_FORMATTERS,
|
|
498
|
-
B2 as BUILD_PRESETS,
|
|
499
|
-
BufferWriter,
|
|
500
|
-
C as ComponentLogger,
|
|
501
|
-
ConsoleTransport,
|
|
502
|
-
d as ContextLogger,
|
|
503
|
-
D as DEFAULT_CONFIG,
|
|
504
|
-
E as ENVIRONMENT_DETECTION,
|
|
505
|
-
FileLogHandler,
|
|
506
|
-
FileTransport,
|
|
507
|
-
H as HookManager,
|
|
508
|
-
HttpTransport,
|
|
509
|
-
Logger,
|
|
510
|
-
R as RemoteLogHandler,
|
|
511
|
-
c as ScopedLogger,
|
|
512
|
-
S as SerializerRegistry,
|
|
513
|
-
StyleBuilder,
|
|
514
|
-
StyleCache,
|
|
515
|
-
StylePresets,
|
|
516
|
-
a as THEME_BANNERS,
|
|
517
|
-
T as THEME_PRESETS,
|
|
518
|
-
T2 as TerminalRenderer,
|
|
519
|
-
b as TransportManager,
|
|
520
|
-
addHandler,
|
|
521
|
-
addSerializer,
|
|
522
|
-
addTransport,
|
|
523
|
-
h3 as ansiBackground,
|
|
524
|
-
i2 as ansiBold,
|
|
525
|
-
g3 as ansiColor,
|
|
526
|
-
j3 as ansiDim,
|
|
527
|
-
f3 as ansiStyle,
|
|
528
|
-
k3 as ansiUnderline,
|
|
529
|
-
api,
|
|
530
|
-
n as applyLogOptions,
|
|
531
|
-
badge,
|
|
532
|
-
badges,
|
|
533
|
-
clearBadges,
|
|
534
|
-
cli,
|
|
535
|
-
closeTransports,
|
|
536
|
-
e2 as colorToHex,
|
|
537
|
-
component,
|
|
538
|
-
a2 as createANSIOutput,
|
|
539
|
-
b2 as createBuildOutput,
|
|
540
|
-
e3 as createCIOutput,
|
|
541
|
-
c3 as createOutput,
|
|
542
|
-
createStyle,
|
|
543
|
-
critical,
|
|
544
|
-
n2 as cssColorToANSI,
|
|
545
|
-
debug,
|
|
546
|
-
index as default,
|
|
547
|
-
d2 as detectEnvironmentPreset,
|
|
548
|
-
d3 as detectOptimalFormat,
|
|
549
|
-
error,
|
|
550
|
-
flushTransports,
|
|
551
|
-
h as formatBadge,
|
|
552
|
-
e as formatColumns,
|
|
553
|
-
k as formatElapsedTime,
|
|
554
|
-
g as formatKeyValue,
|
|
555
|
-
l3 as formatLogLevelANSI,
|
|
556
|
-
j as formatRelativeTime,
|
|
557
|
-
m3 as formatSuccessANSI,
|
|
558
|
-
f2 as formatTimestamp,
|
|
559
|
-
i as formatTimestampExt,
|
|
560
|
-
f as formatWithRightAlign,
|
|
561
|
-
m2 as getANSI256Background,
|
|
562
|
-
l2 as getANSI256Foreground,
|
|
563
|
-
k2 as getANSIBackground,
|
|
564
|
-
j2 as getANSIForeground,
|
|
565
|
-
t as getColorCapability,
|
|
566
|
-
o as getEnvironment,
|
|
567
|
-
w as getEnvironmentInfo,
|
|
568
|
-
g2 as getOptimalConfig,
|
|
569
|
-
getStyleCache,
|
|
570
|
-
v as getTerminalHeight,
|
|
571
|
-
u as getTerminalWidth,
|
|
572
|
-
m as getVisibleLength,
|
|
573
|
-
group,
|
|
574
|
-
groupEnd,
|
|
575
|
-
c2 as hexTo256,
|
|
576
|
-
h2 as hexToRgb,
|
|
577
|
-
info,
|
|
578
|
-
l as isKeyValueObject,
|
|
579
|
-
q as isRunningInTerminal,
|
|
580
|
-
logAnimated,
|
|
581
|
-
logWithSVG,
|
|
582
|
-
off,
|
|
583
|
-
on,
|
|
584
|
-
once,
|
|
585
|
-
p as padToWidth,
|
|
586
|
-
p2 as parseStackTrace,
|
|
587
|
-
removeSerializer,
|
|
588
|
-
removeTransport,
|
|
589
|
-
r as resetStartTime,
|
|
590
|
-
r2 as rgbToHex,
|
|
591
|
-
n3 as sanitizeEmojis,
|
|
592
|
-
scope,
|
|
593
|
-
setBannerType,
|
|
594
|
-
setGlobalPrefix,
|
|
595
|
-
setTheme,
|
|
596
|
-
setVerbosity,
|
|
597
|
-
showBanner,
|
|
598
|
-
s as stripAnsi,
|
|
599
|
-
stylePresets,
|
|
600
|
-
success,
|
|
601
|
-
s2 as supportsANSI,
|
|
602
|
-
table,
|
|
603
|
-
time,
|
|
604
|
-
timeEnd,
|
|
605
|
-
trace,
|
|
606
|
-
use,
|
|
607
|
-
warn
|
|
608
|
-
};
|
|
609
|
-
//# sourceMappingURL=index.js.map
|