@mks2508/better-logger 2.1.0 → 3.1.0
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/.claude/settings.local.json +8 -1
- package/CHANGELOG.json +168 -1
- package/CHANGELOG.md +127 -0
- package/CLAUDE.md +14 -1
- package/README.md +111 -20
- package/dist/Logger.d.ts +217 -70
- package/dist/Logger.d.ts.map +1 -1
- package/dist/ScopedLogger.d.ts +23 -276
- package/dist/ScopedLogger.d.ts.map +1 -1
- package/dist/chunks/Logger-BV0v1AyC.js +2 -0
- package/dist/chunks/Logger-BV0v1AyC.js.map +1 -0
- package/dist/chunks/{Logger-B7L-ujY4.js → Logger-C086w3EM.js} +868 -102
- package/dist/chunks/Logger-C086w3EM.js.map +1 -0
- package/dist/chunks/environment-C_8J-zQ_.js +4 -0
- package/dist/chunks/environment-C_8J-zQ_.js.map +1 -0
- package/dist/chunks/{environment-TI2ByCPT.js → environment-DXHouGD4.js} +468 -100
- package/dist/chunks/environment-DXHouGD4.js.map +1 -0
- package/dist/chunks/{formatting-CuNUqGks.js → formatting-BNnVUPcw.js} +2 -2
- package/dist/chunks/{formatting-CuNUqGks.js.map → formatting-BNnVUPcw.js.map} +1 -1
- package/dist/chunks/{formatting-Blwy-f0W.js → formatting-Cg5YhB9Y.js} +2 -2
- package/dist/chunks/{formatting-Blwy-f0W.js.map → formatting-Cg5YhB9Y.js.map} +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.js +2 -2
- package/dist/exports-module.d.ts +1 -1
- package/dist/exports-module.d.ts.map +1 -1
- package/dist/exports.cjs +1 -1
- package/dist/exports.js +2 -2
- package/dist/hooks/HookManager.d.ts +21 -0
- package/dist/hooks/HookManager.d.ts.map +1 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +30 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +433 -20
- package/dist/index.js.map +1 -1
- package/dist/serializers/SerializerRegistry.d.ts +16 -0
- package/dist/serializers/SerializerRegistry.d.ts.map +1 -0
- package/dist/serializers/index.d.ts +2 -0
- package/dist/serializers/index.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-module.d.ts +1 -1
- package/dist/styling-module.d.ts.map +1 -1
- package/dist/styling.cjs +1 -1
- package/dist/styling.js +3 -3
- 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 +20 -6
- package/dist/terminal/terminal-renderer.d.ts.map +1 -1
- 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/dist/transports/index.d.ts +5 -0
- package/dist/transports/index.d.ts.map +1 -0
- package/dist/types/core.d.ts +55 -0
- package/dist/types/core.d.ts.map +1 -1
- package/dist/types/hooks.d.ts +36 -0
- package/dist/types/hooks.d.ts.map +1 -0
- package/dist/types/index.d.ts +5 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/serializers.d.ts +25 -0
- package/dist/types/serializers.d.ts.map +1 -0
- package/dist/types/transports.d.ts +47 -0
- package/dist/types/transports.d.ts.map +1 -0
- package/dist/utils/environment-detector.d.ts +10 -0
- package/dist/utils/environment-detector.d.ts.map +1 -1
- package/docs/API.md +227 -0
- package/package.json +1 -1
- package/packages/core/package.json +1 -1
- package/packages/styling/package.json +2 -2
- package/src/Logger.ts +403 -114
- package/src/ScopedLogger.ts +78 -318
- package/src/hooks/HookManager.ts +177 -0
- package/src/hooks/index.ts +1 -0
- package/src/index.ts +133 -3
- package/src/serializers/SerializerRegistry.ts +173 -0
- package/src/serializers/index.ts +1 -0
- package/src/styling/StyleCache.ts +131 -0
- package/src/terminal/color-converter.ts +315 -0
- package/src/terminal/formatter.ts +236 -0
- package/src/terminal/terminal-renderer.ts +74 -79
- package/src/transports/ConsoleTransport.ts +28 -0
- package/src/transports/FileTransport.ts +53 -0
- package/src/transports/HttpTransport.ts +56 -0
- package/src/transports/TransportManager.ts +130 -0
- package/src/transports/index.ts +4 -0
- package/src/types/core.ts +68 -0
- package/src/types/hooks.ts +45 -0
- package/src/types/index.ts +44 -1
- package/src/types/serializers.ts +30 -0
- package/src/types/transports.ts +52 -0
- package/src/utils/environment-detector.ts +23 -1
- package/dist/chunks/Logger-B7L-ujY4.js.map +0 -1
- package/dist/chunks/Logger-DzU_c5sX.js +0 -2
- package/dist/chunks/Logger-DzU_c5sX.js.map +0 -1
- package/dist/chunks/ScopedLogger-BY3-E8Ov.js +0 -2
- package/dist/chunks/ScopedLogger-BY3-E8Ov.js.map +0 -1
- package/dist/chunks/ScopedLogger-D-RbiFZn.js +0 -361
- package/dist/chunks/ScopedLogger-D-RbiFZn.js.map +0 -1
- package/dist/chunks/environment-Ba5kShbx.js +0 -4
- package/dist/chunks/environment-Ba5kShbx.js.map +0 -1
- package/dist/chunks/environment-TI2ByCPT.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,10 +1,116 @@
|
|
|
1
|
-
import { L as Logger } from "./chunks/Logger-
|
|
2
|
-
import { B, a, T } from "./chunks/Logger-
|
|
3
|
-
import { i as isNode, a as isBrowser, S as StylePresets,
|
|
4
|
-
import { B as B2, D, E, d, f,
|
|
5
|
-
import { s as safeSerialize } from "./chunks/formatting-
|
|
6
|
-
import { B as B3, h, i, g as
|
|
1
|
+
import { L as Logger } from "./chunks/Logger-C086w3EM.js";
|
|
2
|
+
import { A, B, C, d, H, c, S, a, T, b } from "./chunks/Logger-C086w3EM.js";
|
|
3
|
+
import { i as isNode, a as isBrowser, g as getTerminalWidth, b as getANSIForeground, A as ANSI, S as StylePresets, c as StyleBuilder } from "./chunks/environment-DXHouGD4.js";
|
|
4
|
+
import { B as B2, D, E, T as T2, k, o, d as d2, f, n, m, l, u, q, w, e, v, j, h, s, p, r, t } from "./chunks/environment-DXHouGD4.js";
|
|
5
|
+
import { s as safeSerialize } from "./chunks/formatting-BNnVUPcw.js";
|
|
6
|
+
import { B as B3, h as h2, i, g, j as j2, f as f2, k as k2, a as a2, b as b2, e as e2, c as c2, d as d3, l as l2, m as m2, n as n2 } from "./chunks/formatting-BNnVUPcw.js";
|
|
7
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
|
+
}
|
|
8
114
|
class FileLogHandler {
|
|
9
115
|
filename;
|
|
10
116
|
maxSize;
|
|
@@ -148,6 +254,240 @@ class AnalyticsLogHandler {
|
|
|
148
254
|
}
|
|
149
255
|
}
|
|
150
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
|
+
function stripAnsi(str) {
|
|
341
|
+
return str.replace(/\x1b\[[0-9;]*m/g, "");
|
|
342
|
+
}
|
|
343
|
+
function getVisibleLength(str) {
|
|
344
|
+
return stripAnsi(str).length;
|
|
345
|
+
}
|
|
346
|
+
function padToWidth(str, width, align = "left") {
|
|
347
|
+
const visibleLen = getVisibleLength(str);
|
|
348
|
+
if (visibleLen >= width) return str;
|
|
349
|
+
const padding = width - visibleLen;
|
|
350
|
+
switch (align) {
|
|
351
|
+
case "right":
|
|
352
|
+
return " ".repeat(padding) + str;
|
|
353
|
+
case "center":
|
|
354
|
+
const leftPad = Math.floor(padding / 2);
|
|
355
|
+
const rightPad = padding - leftPad;
|
|
356
|
+
return " ".repeat(leftPad) + str + " ".repeat(rightPad);
|
|
357
|
+
case "left":
|
|
358
|
+
default:
|
|
359
|
+
return str + " ".repeat(padding);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
function formatWithRightAlign(leftContent, rightContent, maxWidth) {
|
|
363
|
+
const width = maxWidth ?? getTerminalWidth();
|
|
364
|
+
const leftLen = getVisibleLength(leftContent);
|
|
365
|
+
const rightLen = getVisibleLength(rightContent);
|
|
366
|
+
const gap = width - leftLen - rightLen;
|
|
367
|
+
if (gap <= 1) {
|
|
368
|
+
return `${leftContent} ${rightContent}`;
|
|
369
|
+
}
|
|
370
|
+
return `${leftContent}${" ".repeat(gap)}${rightContent}`;
|
|
371
|
+
}
|
|
372
|
+
function formatColumns(columns, maxWidth, colorCapability = "full") {
|
|
373
|
+
const width = maxWidth ?? getTerminalWidth();
|
|
374
|
+
columns.length;
|
|
375
|
+
const columnsWithWidths = columns.map((col, idx) => {
|
|
376
|
+
if (col.width) return { ...col, calculatedWidth: col.width };
|
|
377
|
+
const remainingWidth = width - columns.filter((c3, i2) => i2 !== idx && c3.width).reduce((sum, c3) => sum + (c3.width ?? 0), 0);
|
|
378
|
+
const autoColumns = columns.filter((c3) => !c3.width).length;
|
|
379
|
+
const calculatedWidth = Math.floor(remainingWidth / autoColumns);
|
|
380
|
+
return { ...col, calculatedWidth };
|
|
381
|
+
});
|
|
382
|
+
return columnsWithWidths.map((col) => {
|
|
383
|
+
let content = col.content;
|
|
384
|
+
if (col.color && colorCapability !== "none") {
|
|
385
|
+
const colorCode = getANSIForeground(col.color, colorCapability);
|
|
386
|
+
content = `${colorCode}${content}${ANSI.reset}`;
|
|
387
|
+
}
|
|
388
|
+
return padToWidth(content, col.calculatedWidth, col.align);
|
|
389
|
+
}).join("");
|
|
390
|
+
}
|
|
391
|
+
function formatKeyValue(obj, colorCapability = "full", options = {}) {
|
|
392
|
+
const {
|
|
393
|
+
separator = " ",
|
|
394
|
+
keyColor = "#888888",
|
|
395
|
+
valueColor = "#00ffff"
|
|
396
|
+
} = options;
|
|
397
|
+
const entries = Object.entries(obj);
|
|
398
|
+
if (entries.length === 0) return "";
|
|
399
|
+
const keyColorCode = colorCapability !== "none" ? getANSIForeground(keyColor, colorCapability) : "";
|
|
400
|
+
const valueColorCode = colorCapability !== "none" ? getANSIForeground(valueColor, colorCapability) : "";
|
|
401
|
+
const reset = colorCapability !== "none" ? ANSI.reset : "";
|
|
402
|
+
return entries.map(([key, value]) => {
|
|
403
|
+
const valueStr = typeof value === "object" ? JSON.stringify(value) : String(value);
|
|
404
|
+
return `${keyColorCode}${key}:${reset} ${valueColorCode}${valueStr}${reset}`;
|
|
405
|
+
}).join(separator);
|
|
406
|
+
}
|
|
407
|
+
function isKeyValueObject(obj) {
|
|
408
|
+
if (typeof obj !== "object" || obj === null) return false;
|
|
409
|
+
if (Array.isArray(obj)) return false;
|
|
410
|
+
const proto = Object.getPrototypeOf(obj);
|
|
411
|
+
if (proto !== Object.prototype && proto !== null) return false;
|
|
412
|
+
const values = Object.values(obj);
|
|
413
|
+
return values.every(
|
|
414
|
+
(v2) => typeof v2 === "string" || typeof v2 === "number" || typeof v2 === "boolean" || v2 === null
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
function formatBadge(badge2, style = "brackets", colorCapability = "full", color) {
|
|
418
|
+
const colorCode = color && colorCapability !== "none" ? getANSIForeground(color, colorCapability) : "";
|
|
419
|
+
const reset = colorCapability !== "none" ? ANSI.reset : "";
|
|
420
|
+
const bgBlack = colorCapability !== "none" ? ANSI.bg.black : "";
|
|
421
|
+
const text = badge2.toUpperCase();
|
|
422
|
+
switch (style) {
|
|
423
|
+
case "rounded":
|
|
424
|
+
return `${bgBlack}${colorCode}⟨${text}⟩${reset}`;
|
|
425
|
+
case "plain":
|
|
426
|
+
return `${colorCode}${text}${reset}`;
|
|
427
|
+
case "unicode":
|
|
428
|
+
return `${bgBlack}${colorCode}╭${text}╮${reset}`;
|
|
429
|
+
case "pill":
|
|
430
|
+
return `${bgBlack}${colorCode}⦗${text}⦘${reset}`;
|
|
431
|
+
case "brackets":
|
|
432
|
+
default:
|
|
433
|
+
return `${bgBlack}${colorCode}[${text}]${reset}`;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
function formatTimestamp(date = /* @__PURE__ */ new Date(), format = "time") {
|
|
437
|
+
switch (format) {
|
|
438
|
+
case "iso":
|
|
439
|
+
return date.toISOString();
|
|
440
|
+
case "date":
|
|
441
|
+
return date.toISOString().split("T")[0] ?? "";
|
|
442
|
+
case "time":
|
|
443
|
+
return date.toTimeString().slice(0, 8);
|
|
444
|
+
case "timeMs":
|
|
445
|
+
return date.toTimeString().slice(0, 8) + "." + String(date.getMilliseconds()).padStart(3, "0");
|
|
446
|
+
case "relative":
|
|
447
|
+
return formatRelativeTime(date);
|
|
448
|
+
case "elapsed":
|
|
449
|
+
return formatElapsedTime(date);
|
|
450
|
+
case "custom":
|
|
451
|
+
default:
|
|
452
|
+
return date.toLocaleTimeString();
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
let startTime = null;
|
|
456
|
+
function formatRelativeTime(date) {
|
|
457
|
+
if (startTime === null) {
|
|
458
|
+
startTime = Date.now();
|
|
459
|
+
}
|
|
460
|
+
const diff = date.getTime() - startTime;
|
|
461
|
+
if (diff < 1e3) {
|
|
462
|
+
return `+${diff}ms`;
|
|
463
|
+
} else if (diff < 6e4) {
|
|
464
|
+
return `+${(diff / 1e3).toFixed(1)}s`;
|
|
465
|
+
} else {
|
|
466
|
+
const mins = Math.floor(diff / 6e4);
|
|
467
|
+
const secs = Math.floor(diff % 6e4 / 1e3);
|
|
468
|
+
return `+${mins}m${secs}s`;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
function formatElapsedTime(date) {
|
|
472
|
+
if (startTime === null) {
|
|
473
|
+
startTime = Date.now();
|
|
474
|
+
}
|
|
475
|
+
const diff = date.getTime() - startTime;
|
|
476
|
+
const hours = Math.floor(diff / 36e5);
|
|
477
|
+
const mins = Math.floor(diff % 36e5 / 6e4);
|
|
478
|
+
const secs = Math.floor(diff % 6e4 / 1e3);
|
|
479
|
+
return `${String(hours).padStart(2, "0")}:${String(mins).padStart(2, "0")}:${String(secs).padStart(2, "0")}`;
|
|
480
|
+
}
|
|
481
|
+
function resetStartTime() {
|
|
482
|
+
startTime = Date.now();
|
|
483
|
+
}
|
|
484
|
+
function applyLogOptions(message, options, colorCapability = "full") {
|
|
485
|
+
let result = message;
|
|
486
|
+
if (options.rightAlign) {
|
|
487
|
+
result = formatWithRightAlign(message, options.rightAlign);
|
|
488
|
+
}
|
|
489
|
+
return result;
|
|
490
|
+
}
|
|
151
491
|
let _logger = null;
|
|
152
492
|
function getLogger() {
|
|
153
493
|
if (!_logger) {
|
|
@@ -169,7 +509,12 @@ const groupEnd = () => getLogger().groupEnd();
|
|
|
169
509
|
const time = (label) => getLogger().time(label);
|
|
170
510
|
const timeEnd = (label) => getLogger().timeEnd(label);
|
|
171
511
|
const setGlobalPrefix = (prefix) => getLogger().setGlobalPrefix(prefix);
|
|
172
|
-
const scope = (
|
|
512
|
+
const scope = (name) => getLogger().scope(name);
|
|
513
|
+
const component = (name) => getLogger().component(name);
|
|
514
|
+
const api = (name) => getLogger().api(name);
|
|
515
|
+
const badges = (badgeList) => getLogger().badges(badgeList);
|
|
516
|
+
const badge = (badgeName) => getLogger().badge(badgeName);
|
|
517
|
+
const clearBadges = () => getLogger().clearBadges();
|
|
173
518
|
const setVerbosity = (level) => getLogger().setVerbosity(level);
|
|
174
519
|
const addHandler = (handler) => getLogger().addHandler(handler);
|
|
175
520
|
const setTheme = (theme) => getLogger().setTheme(theme);
|
|
@@ -178,6 +523,16 @@ const showBanner = (bannerType) => getLogger().showBanner(bannerType);
|
|
|
178
523
|
const logWithSVG = (message, svgContent, options) => getLogger().logWithSVG(message, svgContent, options);
|
|
179
524
|
const logAnimated = (message, duration) => getLogger().logAnimated(message, duration);
|
|
180
525
|
const cli = (command) => getLogger().cli(command);
|
|
526
|
+
const addSerializer = (type, serializer, priority) => getLogger().addSerializer(type, serializer, priority);
|
|
527
|
+
const removeSerializer = (type) => getLogger().removeSerializer(type);
|
|
528
|
+
const on = (event, callback, priority) => getLogger().on(event, callback, priority);
|
|
529
|
+
const once = (event, callback, priority) => getLogger().once(event, callback, priority);
|
|
530
|
+
const off = (event, callback) => getLogger().off(event, callback);
|
|
531
|
+
const use = (middleware, priority) => getLogger().use(middleware, priority);
|
|
532
|
+
const addTransport = (target) => getLogger().addTransport(target);
|
|
533
|
+
const removeTransport = (id) => getLogger().removeTransport(id);
|
|
534
|
+
const flushTransports = () => getLogger().flushTransports();
|
|
535
|
+
const closeTransports = () => getLogger().closeTransports();
|
|
181
536
|
const createStyle = () => new StyleBuilder();
|
|
182
537
|
const stylePresets = {
|
|
183
538
|
success: StylePresets.success().build(),
|
|
@@ -187,61 +542,119 @@ const stylePresets = {
|
|
|
187
542
|
accent: StylePresets.accent().build()
|
|
188
543
|
};
|
|
189
544
|
export {
|
|
545
|
+
ANSI,
|
|
546
|
+
A as APILogger,
|
|
190
547
|
AnalyticsLogHandler,
|
|
191
548
|
B as BANNER_VARIANTS,
|
|
192
549
|
B3 as BUILD_FORMATTERS,
|
|
193
550
|
B2 as BUILD_PRESETS,
|
|
551
|
+
C as ComponentLogger,
|
|
552
|
+
ConsoleTransport,
|
|
553
|
+
d as ContextLogger,
|
|
194
554
|
D as DEFAULT_CONFIG,
|
|
195
555
|
E as ENVIRONMENT_DETECTION,
|
|
196
556
|
FileLogHandler,
|
|
557
|
+
FileTransport,
|
|
558
|
+
H as HookManager,
|
|
559
|
+
HttpTransport,
|
|
197
560
|
Logger,
|
|
198
561
|
R as RemoteLogHandler,
|
|
562
|
+
c as ScopedLogger,
|
|
563
|
+
S as SerializerRegistry,
|
|
199
564
|
StyleBuilder,
|
|
565
|
+
StyleCache,
|
|
200
566
|
StylePresets,
|
|
201
567
|
a as THEME_BANNERS,
|
|
202
568
|
T as THEME_PRESETS,
|
|
569
|
+
T2 as TerminalRenderer,
|
|
570
|
+
b as TransportManager,
|
|
203
571
|
addHandler,
|
|
204
|
-
|
|
572
|
+
addSerializer,
|
|
573
|
+
addTransport,
|
|
574
|
+
h2 as ansiBackground,
|
|
205
575
|
i as ansiBold,
|
|
206
|
-
|
|
207
|
-
|
|
576
|
+
g as ansiColor,
|
|
577
|
+
j2 as ansiDim,
|
|
208
578
|
f2 as ansiStyle,
|
|
209
|
-
|
|
579
|
+
k2 as ansiUnderline,
|
|
580
|
+
api,
|
|
581
|
+
applyLogOptions,
|
|
582
|
+
badge,
|
|
583
|
+
badges,
|
|
584
|
+
clearBadges,
|
|
210
585
|
cli,
|
|
586
|
+
closeTransports,
|
|
587
|
+
k as colorToHex,
|
|
588
|
+
component,
|
|
211
589
|
a2 as createANSIOutput,
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
590
|
+
b2 as createBuildOutput,
|
|
591
|
+
e2 as createCIOutput,
|
|
592
|
+
c2 as createOutput,
|
|
215
593
|
createStyle,
|
|
216
594
|
critical,
|
|
595
|
+
o as cssColorToANSI,
|
|
217
596
|
debug,
|
|
218
597
|
index as default,
|
|
219
|
-
|
|
220
|
-
|
|
598
|
+
d2 as detectEnvironmentPreset,
|
|
599
|
+
d3 as detectOptimalFormat,
|
|
221
600
|
error,
|
|
222
|
-
|
|
223
|
-
|
|
601
|
+
flushTransports,
|
|
602
|
+
formatBadge,
|
|
603
|
+
formatColumns,
|
|
604
|
+
formatElapsedTime,
|
|
605
|
+
formatKeyValue,
|
|
606
|
+
l2 as formatLogLevelANSI,
|
|
607
|
+
formatRelativeTime,
|
|
608
|
+
m2 as formatSuccessANSI,
|
|
224
609
|
f as formatTimestamp,
|
|
225
|
-
|
|
610
|
+
formatTimestamp as formatTimestampExt,
|
|
611
|
+
formatWithRightAlign,
|
|
612
|
+
n as getANSI256Background,
|
|
613
|
+
m as getANSI256Foreground,
|
|
614
|
+
l as getANSIBackground,
|
|
615
|
+
getANSIForeground,
|
|
616
|
+
u as getColorCapability,
|
|
617
|
+
q as getEnvironment,
|
|
618
|
+
w as getEnvironmentInfo,
|
|
619
|
+
e as getOptimalConfig,
|
|
620
|
+
getStyleCache,
|
|
621
|
+
v as getTerminalHeight,
|
|
622
|
+
getTerminalWidth,
|
|
623
|
+
getVisibleLength,
|
|
226
624
|
group,
|
|
227
625
|
groupEnd,
|
|
626
|
+
j as hexTo256,
|
|
627
|
+
h as hexToRgb,
|
|
228
628
|
info,
|
|
629
|
+
isKeyValueObject,
|
|
630
|
+
s as isRunningInTerminal,
|
|
229
631
|
logAnimated,
|
|
230
632
|
logWithSVG,
|
|
633
|
+
off,
|
|
634
|
+
on,
|
|
635
|
+
once,
|
|
636
|
+
padToWidth,
|
|
231
637
|
p as parseStackTrace,
|
|
232
|
-
|
|
638
|
+
removeSerializer,
|
|
639
|
+
removeTransport,
|
|
640
|
+
resetStartTime,
|
|
641
|
+
r as rgbToHex,
|
|
642
|
+
n2 as sanitizeEmojis,
|
|
233
643
|
scope,
|
|
234
644
|
setBannerType,
|
|
235
645
|
setGlobalPrefix,
|
|
236
646
|
setTheme,
|
|
237
647
|
setVerbosity,
|
|
238
648
|
showBanner,
|
|
649
|
+
stripAnsi,
|
|
239
650
|
stylePresets,
|
|
240
651
|
success,
|
|
652
|
+
t as supportsANSI,
|
|
241
653
|
table,
|
|
242
654
|
time,
|
|
243
655
|
timeEnd,
|
|
244
656
|
trace,
|
|
657
|
+
use,
|
|
245
658
|
warn
|
|
246
659
|
};
|
|
247
660
|
//# sourceMappingURL=index.js.map
|