voltlog-io 1.0.6 → 1.0.8
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/{client.d.mts → browser/client.d.mts} +1 -64
- package/dist/{client.d.ts → browser/client.d.ts} +1 -64
- package/dist/{client.js → browser/client.js} +139 -221
- package/dist/{client.mjs → browser/client.mjs} +0 -66
- package/dist/index.d.mts +1 -27
- package/dist/index.d.ts +1 -27
- package/dist/index.js +18 -50
- package/dist/index.mjs +16 -54
- package/package.json +7 -6
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
|
@@ -1,64 +1,4 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/client.ts
|
|
21
|
-
var client_exports = {};
|
|
22
|
-
__export(client_exports, {
|
|
23
|
-
LogLevel: () => LogLevel,
|
|
24
|
-
LogLevelNameMap: () => LogLevelNameMap,
|
|
25
|
-
LogLevelValueMap: () => LogLevelValueMap,
|
|
26
|
-
aiEnrichmentMiddleware: () => aiEnrichmentMiddleware,
|
|
27
|
-
alertMiddleware: () => alertMiddleware,
|
|
28
|
-
batchTransport: () => batchTransport,
|
|
29
|
-
browserJsonStreamTransport: () => browserJsonStreamTransport,
|
|
30
|
-
consoleTransport: () => consoleTransport,
|
|
31
|
-
createHttpLogger: () => createHttpLogger,
|
|
32
|
-
createLogger: () => createLogger,
|
|
33
|
-
createMiddleware: () => createMiddleware,
|
|
34
|
-
createOpenAiErrorAnalyzer: () => createOpenAiErrorAnalyzer,
|
|
35
|
-
createTransport: () => createTransport,
|
|
36
|
-
datadogTransport: () => datadogTransport,
|
|
37
|
-
deduplicationMiddleware: () => deduplicationMiddleware,
|
|
38
|
-
discordTransport: () => discordTransport,
|
|
39
|
-
heapUsageMiddleware: () => heapUsageMiddleware,
|
|
40
|
-
ipMiddleware: () => ipMiddleware,
|
|
41
|
-
levelOverrideMiddleware: () => levelOverrideMiddleware,
|
|
42
|
-
lokiTransport: () => lokiTransport,
|
|
43
|
-
nodeHttpMappers: () => nodeHttpMappers,
|
|
44
|
-
ocppMiddleware: () => ocppMiddleware,
|
|
45
|
-
otelTraceMiddleware: () => otelTraceMiddleware,
|
|
46
|
-
otelTransport: () => otelTransport,
|
|
47
|
-
prettyTransport: () => prettyTransport,
|
|
48
|
-
redactionMiddleware: () => redactionMiddleware,
|
|
49
|
-
resolveLevel: () => resolveLevel,
|
|
50
|
-
ringBufferTransport: () => ringBufferTransport,
|
|
51
|
-
samplingMiddleware: () => samplingMiddleware,
|
|
52
|
-
sentryTransport: () => sentryTransport,
|
|
53
|
-
shouldIncludeStack: () => shouldIncludeStack,
|
|
54
|
-
shouldLog: () => shouldLog,
|
|
55
|
-
slackTransport: () => slackTransport,
|
|
56
|
-
userAgentMiddleware: () => userAgentMiddleware,
|
|
57
|
-
webhookTransport: () => webhookTransport
|
|
58
|
-
});
|
|
59
|
-
module.exports = __toCommonJS(client_exports);
|
|
60
|
-
|
|
61
|
-
// src/core/types.ts
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/core/types.ts
|
|
62
2
|
var LogLevel = {
|
|
63
3
|
TRACE: 10,
|
|
64
4
|
DEBUG: 20,
|
|
@@ -114,32 +54,32 @@ function fanOutToTransports(entry, transports, loggerLevel) {
|
|
|
114
54
|
result.catch(() => {
|
|
115
55
|
});
|
|
116
56
|
}
|
|
117
|
-
} catch {
|
|
57
|
+
} catch (e2) {
|
|
118
58
|
}
|
|
119
59
|
}
|
|
120
60
|
}
|
|
121
61
|
|
|
122
62
|
// src/core/logger.ts
|
|
123
|
-
var randomUUID = typeof globalThis.crypto
|
|
63
|
+
var randomUUID = typeof _optionalChain([globalThis, 'access', _2 => _2.crypto, 'optionalAccess', _3 => _3.randomUUID]) === "function" ? () => globalThis.crypto.randomUUID() : () => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
124
64
|
const r = Math.random() * 16 | 0;
|
|
125
65
|
return (c === "x" ? r : r & 3 | 8).toString(16);
|
|
126
66
|
});
|
|
127
67
|
var LoggerImpl = class {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
136
76
|
constructor(options = {}) {
|
|
137
|
-
this._level = resolveLevel(options.level
|
|
138
|
-
this._transports = [...options.transports
|
|
139
|
-
this._middlewareList = [...options.middleware
|
|
77
|
+
this._level = resolveLevel(_nullishCoalesce(options.level, () => ( "INFO")));
|
|
78
|
+
this._transports = [..._nullishCoalesce(options.transports, () => ( []))];
|
|
79
|
+
this._middlewareList = [..._nullishCoalesce(options.middleware, () => ( []))];
|
|
140
80
|
this._context = options.context ? { ...options.context } : {};
|
|
141
|
-
this._includeStack = options.includeStack
|
|
142
|
-
this._timestampFn = options.timestamp
|
|
81
|
+
this._includeStack = _nullishCoalesce(options.includeStack, () => ( "ERROR"));
|
|
82
|
+
this._timestampFn = _nullishCoalesce(options.timestamp, () => ( Date.now));
|
|
143
83
|
this._idFn = options.idGenerator !== void 0 ? options.idGenerator : randomUUID;
|
|
144
84
|
this._pipeline = this._buildPipeline();
|
|
145
85
|
}
|
|
@@ -199,7 +139,7 @@ var LoggerImpl = class {
|
|
|
199
139
|
this._level = resolveLevel(level);
|
|
200
140
|
}
|
|
201
141
|
getLevel() {
|
|
202
|
-
return LogLevelValueMap[this._level]
|
|
142
|
+
return _nullishCoalesce(LogLevelValueMap[this._level], () => ( "INFO"));
|
|
203
143
|
}
|
|
204
144
|
isLevelEnabled(level) {
|
|
205
145
|
return resolveLevel(level) >= this._level;
|
|
@@ -207,7 +147,7 @@ var LoggerImpl = class {
|
|
|
207
147
|
// ─── Timer ─────────────────────────────────────────────────
|
|
208
148
|
startTimer(level) {
|
|
209
149
|
const start = performance.now();
|
|
210
|
-
const logLevel = level
|
|
150
|
+
const logLevel = _nullishCoalesce(level, () => ( "INFO"));
|
|
211
151
|
return {
|
|
212
152
|
done: (message, meta) => {
|
|
213
153
|
const durationMs = Math.round(performance.now() - start);
|
|
@@ -220,11 +160,11 @@ var LoggerImpl = class {
|
|
|
220
160
|
}
|
|
221
161
|
// ─── Lifecycle ──────────────────────────────────────────────
|
|
222
162
|
async flush() {
|
|
223
|
-
await Promise.all(this._transports.map((t) => t.flush
|
|
163
|
+
await Promise.all(this._transports.map((t) => _optionalChain([t, 'access', _4 => _4.flush, 'optionalCall', _5 => _5()])).filter(Boolean));
|
|
224
164
|
}
|
|
225
165
|
async close() {
|
|
226
166
|
await this.flush();
|
|
227
|
-
await Promise.all(this._transports.map((t) => t.close
|
|
167
|
+
await Promise.all(this._transports.map((t) => _optionalChain([t, 'access', _6 => _6.close, 'optionalCall', _7 => _7()])).filter(Boolean));
|
|
228
168
|
}
|
|
229
169
|
// ─── Internal ───────────────────────────────────────────────
|
|
230
170
|
/** @internal */
|
|
@@ -240,7 +180,7 @@ var LoggerImpl = class {
|
|
|
240
180
|
levelName,
|
|
241
181
|
message,
|
|
242
182
|
timestamp: this._timestampFn(),
|
|
243
|
-
meta: meta
|
|
183
|
+
meta: _nullishCoalesce(meta, () => ( {})),
|
|
244
184
|
context: Object.keys(context).length > 0 ? context : void 0
|
|
245
185
|
};
|
|
246
186
|
if (error) {
|
|
@@ -373,10 +313,10 @@ function createLogger(options) {
|
|
|
373
313
|
|
|
374
314
|
// src/middleware/ai-enrichment.ts
|
|
375
315
|
function aiEnrichmentMiddleware(options) {
|
|
376
|
-
const minLevel = resolveLevel(options.level
|
|
377
|
-
const timeoutMs = options.timeout
|
|
378
|
-
const swallow = options.swallowErrors
|
|
379
|
-
const fieldName = options.targetField
|
|
316
|
+
const minLevel = resolveLevel(_nullishCoalesce(options.level, () => ( "ERROR")));
|
|
317
|
+
const timeoutMs = _nullishCoalesce(options.timeout, () => ( 2e3));
|
|
318
|
+
const swallow = _nullishCoalesce(options.swallowErrors, () => ( true));
|
|
319
|
+
const fieldName = _nullishCoalesce(options.targetField, () => ( "ai_analysis"));
|
|
380
320
|
return async (entry, next) => {
|
|
381
321
|
if (entry.level < minLevel) {
|
|
382
322
|
next(entry);
|
|
@@ -429,8 +369,8 @@ Context: ${JSON.stringify(entry.meta)}`
|
|
|
429
369
|
);
|
|
430
370
|
if (!response.ok) return null;
|
|
431
371
|
const data = await response.json();
|
|
432
|
-
return data.choices
|
|
433
|
-
} catch {
|
|
372
|
+
return _nullishCoalesce(_optionalChain([data, 'access', _8 => _8.choices, 'optionalAccess', _9 => _9[0], 'optionalAccess', _10 => _10.message, 'optionalAccess', _11 => _11.content]), () => ( null));
|
|
373
|
+
} catch (e3) {
|
|
434
374
|
return null;
|
|
435
375
|
}
|
|
436
376
|
};
|
|
@@ -447,9 +387,9 @@ function alertMiddleware(rules) {
|
|
|
447
387
|
for (const rule of rules) {
|
|
448
388
|
if (!rule.when(entry)) continue;
|
|
449
389
|
const state = states.get(rule.name);
|
|
450
|
-
const windowMs = rule.windowMs
|
|
451
|
-
const threshold = rule.threshold
|
|
452
|
-
const cooldownMs = rule.cooldownMs
|
|
390
|
+
const windowMs = _nullishCoalesce(rule.windowMs, () => ( Infinity));
|
|
391
|
+
const threshold = _nullishCoalesce(rule.threshold, () => ( 1));
|
|
392
|
+
const cooldownMs = _nullishCoalesce(rule.cooldownMs, () => ( 0));
|
|
453
393
|
if (Number.isFinite(windowMs)) {
|
|
454
394
|
state.entries = state.entries.filter(
|
|
455
395
|
(e) => now - e.timestamp < windowMs
|
|
@@ -466,7 +406,7 @@ function alertMiddleware(rules) {
|
|
|
466
406
|
result.catch(() => {
|
|
467
407
|
});
|
|
468
408
|
}
|
|
469
|
-
} catch {
|
|
409
|
+
} catch (e4) {
|
|
470
410
|
}
|
|
471
411
|
}
|
|
472
412
|
}
|
|
@@ -481,8 +421,8 @@ function createMiddleware(fn) {
|
|
|
481
421
|
|
|
482
422
|
// src/middleware/deduplication.ts
|
|
483
423
|
function deduplicationMiddleware(options = {}) {
|
|
484
|
-
const windowMs = options.windowMs
|
|
485
|
-
const keyFn = options.keyFn
|
|
424
|
+
const windowMs = _nullishCoalesce(options.windowMs, () => ( 1e3));
|
|
425
|
+
const keyFn = _nullishCoalesce(options.keyFn, () => ( ((e) => `${e.level}:${e.message}:${_nullishCoalesce(_optionalChain([e, 'access', _12 => _12.error, 'optionalAccess', _13 => _13.message]), () => ( ""))}`)));
|
|
486
426
|
const buffer = /* @__PURE__ */ new Map();
|
|
487
427
|
return (entry, next) => {
|
|
488
428
|
const key = keyFn(entry);
|
|
@@ -514,7 +454,7 @@ function deduplicationMiddleware(options = {}) {
|
|
|
514
454
|
|
|
515
455
|
// src/middleware/heap-usage.ts
|
|
516
456
|
function heapUsageMiddleware(options = {}) {
|
|
517
|
-
const fieldName = options.fieldName
|
|
457
|
+
const fieldName = _nullishCoalesce(options.fieldName, () => ( "memory"));
|
|
518
458
|
return (entry, next) => {
|
|
519
459
|
if (typeof process !== "undefined" && process.memoryUsage) {
|
|
520
460
|
const memory = process.memoryUsage();
|
|
@@ -532,26 +472,6 @@ function heapUsageMiddleware(options = {}) {
|
|
|
532
472
|
}
|
|
533
473
|
|
|
534
474
|
// src/middleware/http.ts
|
|
535
|
-
var nodeHttpMappers = {
|
|
536
|
-
req: {
|
|
537
|
-
getMethod: (req) => req.method || "UNKNOWN",
|
|
538
|
-
getUrl: (req) => req.originalUrl || req.url || "/",
|
|
539
|
-
getIp: (req) => req.ip || req.socket?.remoteAddress || req.headers?.["x-forwarded-for"] || void 0,
|
|
540
|
-
getUserAgent: (req) => req.headers?.["user-agent"] || void 0,
|
|
541
|
-
getHeader: (req, name) => req.headers?.[name] || void 0
|
|
542
|
-
},
|
|
543
|
-
res: {
|
|
544
|
-
getStatusCode: (res) => res.statusCode || 200,
|
|
545
|
-
onFinish: (res, callback) => {
|
|
546
|
-
if (typeof res.on === "function") {
|
|
547
|
-
res.on("finish", callback);
|
|
548
|
-
res.on("close", callback);
|
|
549
|
-
} else {
|
|
550
|
-
callback();
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
};
|
|
555
475
|
function createHttpLogger(logger, options) {
|
|
556
476
|
const {
|
|
557
477
|
reqMapper,
|
|
@@ -561,7 +481,7 @@ function createHttpLogger(logger, options) {
|
|
|
561
481
|
extractContext
|
|
562
482
|
} = options;
|
|
563
483
|
return (req, res) => {
|
|
564
|
-
if (skip
|
|
484
|
+
if (_optionalChain([skip, 'optionalCall', _14 => _14(req)])) {
|
|
565
485
|
return;
|
|
566
486
|
}
|
|
567
487
|
const startTime = performance.now();
|
|
@@ -598,14 +518,14 @@ function createHttpLogger(logger, options) {
|
|
|
598
518
|
|
|
599
519
|
// src/middleware/ip.ts
|
|
600
520
|
function ipMiddleware(options = {}) {
|
|
601
|
-
const targetField = options.fieldName
|
|
602
|
-
const keysToCheck = options.headerKeys
|
|
521
|
+
const targetField = _nullishCoalesce(options.fieldName, () => ( "ip"));
|
|
522
|
+
const keysToCheck = _nullishCoalesce(options.headerKeys, () => ( [
|
|
603
523
|
"x-forwarded-for",
|
|
604
524
|
"x-real-ip",
|
|
605
525
|
"req.ip",
|
|
606
526
|
"ip",
|
|
607
527
|
"x-client-ip"
|
|
608
|
-
];
|
|
528
|
+
]));
|
|
609
529
|
return (entry, next) => {
|
|
610
530
|
const meta = entry.meta;
|
|
611
531
|
const headers = meta.headers || {};
|
|
@@ -642,12 +562,12 @@ function ipMiddleware(options = {}) {
|
|
|
642
562
|
|
|
643
563
|
// src/middleware/level-override.ts
|
|
644
564
|
function levelOverrideMiddleware(options = {}) {
|
|
645
|
-
const key = options.key
|
|
646
|
-
const cleanup = options.cleanup
|
|
565
|
+
const key = _nullishCoalesce(options.key, () => ( "x-log-level"));
|
|
566
|
+
const cleanup = _nullishCoalesce(options.cleanup, () => ( true));
|
|
647
567
|
return (entry, next) => {
|
|
648
568
|
const meta = entry.meta;
|
|
649
569
|
const context = entry.context;
|
|
650
|
-
const levelName = meta[key] || context
|
|
570
|
+
const levelName = meta[key] || _optionalChain([context, 'optionalAccess', _15 => _15[key]]) || _optionalChain([meta, 'access', _16 => _16.headers, 'optionalAccess', _17 => _17[key]]);
|
|
651
571
|
if (levelName && typeof levelName === "string") {
|
|
652
572
|
const upperName = levelName.toUpperCase();
|
|
653
573
|
if (LogLevel[upperName]) {
|
|
@@ -667,14 +587,14 @@ function levelOverrideMiddleware(options = {}) {
|
|
|
667
587
|
|
|
668
588
|
// src/middleware/ocpp.ts
|
|
669
589
|
function ocppMiddleware(options = {}) {
|
|
670
|
-
const autoPayloadSize = options.autoPayloadSize
|
|
671
|
-
const propagateCorrelationId = options.propagateCorrelationId
|
|
590
|
+
const autoPayloadSize = _nullishCoalesce(options.autoPayloadSize, () => ( true));
|
|
591
|
+
const propagateCorrelationId = _nullishCoalesce(options.propagateCorrelationId, () => ( true));
|
|
672
592
|
return (entry, next) => {
|
|
673
593
|
const enriched = { ...entry, meta: { ...entry.meta } };
|
|
674
594
|
if (autoPayloadSize && enriched.meta.payloadSize === void 0 && enriched.meta.action) {
|
|
675
595
|
try {
|
|
676
596
|
enriched.meta.payloadSize = JSON.stringify(enriched.meta).length;
|
|
677
|
-
} catch {
|
|
597
|
+
} catch (e5) {
|
|
678
598
|
}
|
|
679
599
|
}
|
|
680
600
|
if (propagateCorrelationId && enriched.meta.correlationId && !enriched.correlationId) {
|
|
@@ -684,49 +604,12 @@ function ocppMiddleware(options = {}) {
|
|
|
684
604
|
};
|
|
685
605
|
}
|
|
686
606
|
|
|
687
|
-
// src/middleware/otel-trace.ts
|
|
688
|
-
function otelTraceMiddleware(options = {}) {
|
|
689
|
-
let traceApi = options.traceApi ?? null;
|
|
690
|
-
let resolved = !!traceApi;
|
|
691
|
-
if (!resolved) {
|
|
692
|
-
try {
|
|
693
|
-
const { createRequire } = require("module");
|
|
694
|
-
const dynamicRequire = createRequire(__filename);
|
|
695
|
-
const api = dynamicRequire("@opentelemetry/api");
|
|
696
|
-
traceApi = api;
|
|
697
|
-
resolved = true;
|
|
698
|
-
} catch {
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
return (entry, next) => {
|
|
702
|
-
if (resolved && traceApi?.trace) {
|
|
703
|
-
try {
|
|
704
|
-
const activeSpan = traceApi.trace.getActiveSpan?.();
|
|
705
|
-
if (activeSpan) {
|
|
706
|
-
const spanContext = activeSpan.spanContext?.();
|
|
707
|
-
if (spanContext) {
|
|
708
|
-
const meta = entry.meta;
|
|
709
|
-
meta.traceId = spanContext.traceId;
|
|
710
|
-
meta.spanId = spanContext.spanId;
|
|
711
|
-
meta.traceFlags = spanContext.traceFlags;
|
|
712
|
-
if (!entry.correlationId) {
|
|
713
|
-
entry.correlationId = spanContext.traceId;
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
} catch {
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
next(entry);
|
|
721
|
-
};
|
|
722
|
-
}
|
|
723
|
-
|
|
724
607
|
// src/middleware/redaction.ts
|
|
725
608
|
var DEFAULT_REDACT_VALUE = "[REDACTED]";
|
|
726
609
|
function redactionMiddleware(options) {
|
|
727
610
|
const paths = new Set(options.paths.map((p) => p.toLowerCase()));
|
|
728
|
-
const replacement = options.replacement
|
|
729
|
-
const deep = options.deep
|
|
611
|
+
const replacement = _nullishCoalesce(options.replacement, () => ( DEFAULT_REDACT_VALUE));
|
|
612
|
+
const deep = _nullishCoalesce(options.deep, () => ( true));
|
|
730
613
|
function redactObject(obj) {
|
|
731
614
|
const result = {};
|
|
732
615
|
for (const [key, value] of Object.entries(obj)) {
|
|
@@ -756,11 +639,11 @@ function redactionMiddleware(options) {
|
|
|
756
639
|
|
|
757
640
|
// src/middleware/sampling.ts
|
|
758
641
|
function samplingMiddleware(options = {}) {
|
|
759
|
-
const keyFn = options.keyFn
|
|
760
|
-
const maxPerWindow = options.maxPerWindow
|
|
761
|
-
const windowMs = options.windowMs
|
|
762
|
-
const sampleRate = options.sampleRate
|
|
763
|
-
const priorityLevel = options.priorityLevel
|
|
642
|
+
const keyFn = _nullishCoalesce(options.keyFn, () => ( ((entry) => entry.message)));
|
|
643
|
+
const maxPerWindow = _nullishCoalesce(options.maxPerWindow, () => ( 100));
|
|
644
|
+
const windowMs = _nullishCoalesce(options.windowMs, () => ( 6e4));
|
|
645
|
+
const sampleRate = _nullishCoalesce(options.sampleRate, () => ( 1));
|
|
646
|
+
const priorityLevel = _nullishCoalesce(options.priorityLevel, () => ( 40));
|
|
764
647
|
const buckets = /* @__PURE__ */ new Map();
|
|
765
648
|
return (entry, next) => {
|
|
766
649
|
if (entry.level >= priorityLevel) {
|
|
@@ -794,11 +677,11 @@ function samplingMiddleware(options = {}) {
|
|
|
794
677
|
// src/middleware/user-agent.ts
|
|
795
678
|
function userAgentMiddleware(options = {}) {
|
|
796
679
|
const sourceField = options.sourceField;
|
|
797
|
-
const targetField = options.targetField
|
|
680
|
+
const targetField = _nullishCoalesce(options.targetField, () => ( "client"));
|
|
798
681
|
return (entry, next) => {
|
|
799
682
|
const meta = entry.meta;
|
|
800
683
|
const context = entry.context;
|
|
801
|
-
const ua = (sourceField ? meta[sourceField] : void 0) || meta.userAgent || meta["user-agent"] || context
|
|
684
|
+
const ua = (sourceField ? meta[sourceField] : void 0) || meta.userAgent || meta["user-agent"] || _optionalChain([context, 'optionalAccess', _18 => _18.userAgent]) || _optionalChain([context, 'optionalAccess', _19 => _19["user-agent"]]);
|
|
802
685
|
if (ua) {
|
|
803
686
|
const info = parseUserAgent(ua);
|
|
804
687
|
entry.meta = {
|
|
@@ -831,8 +714,8 @@ function parseUserAgent(ua) {
|
|
|
831
714
|
|
|
832
715
|
// src/transports/batch.ts
|
|
833
716
|
function batchTransport(inner, options = {}) {
|
|
834
|
-
const batchSize = options.batchSize
|
|
835
|
-
const flushIntervalMs = options.flushIntervalMs
|
|
717
|
+
const batchSize = _nullishCoalesce(options.batchSize, () => ( 100));
|
|
718
|
+
const flushIntervalMs = _nullishCoalesce(options.flushIntervalMs, () => ( 5e3));
|
|
836
719
|
let buffer = [];
|
|
837
720
|
let flushTimer = null;
|
|
838
721
|
function scheduleFlush() {
|
|
@@ -853,7 +736,7 @@ function batchTransport(inner, options = {}) {
|
|
|
853
736
|
result.catch(() => {
|
|
854
737
|
});
|
|
855
738
|
}
|
|
856
|
-
} catch {
|
|
739
|
+
} catch (e6) {
|
|
857
740
|
}
|
|
858
741
|
}
|
|
859
742
|
}
|
|
@@ -874,11 +757,11 @@ function batchTransport(inner, options = {}) {
|
|
|
874
757
|
flushTimer = null;
|
|
875
758
|
}
|
|
876
759
|
doFlush();
|
|
877
|
-
await inner.flush
|
|
760
|
+
await _optionalChain([inner, 'access', _20 => _20.flush, 'optionalCall', _21 => _21()]);
|
|
878
761
|
},
|
|
879
762
|
async close() {
|
|
880
|
-
await this.flush
|
|
881
|
-
await inner.close
|
|
763
|
+
await _optionalChain([this, 'access', _22 => _22.flush, 'optionalCall', _23 => _23()]);
|
|
764
|
+
await _optionalChain([inner, 'access', _24 => _24.close, 'optionalCall', _25 => _25()]);
|
|
882
765
|
}
|
|
883
766
|
};
|
|
884
767
|
}
|
|
@@ -887,8 +770,8 @@ function batchTransport(inner, options = {}) {
|
|
|
887
770
|
function browserJsonStreamTransport(options) {
|
|
888
771
|
const stream = options.stream;
|
|
889
772
|
const writer = stream.getWriter();
|
|
890
|
-
const serialize = options.serializer
|
|
891
|
-
`);
|
|
773
|
+
const serialize = _nullishCoalesce(options.serializer, () => ( ((entry) => `${JSON.stringify(entry)}
|
|
774
|
+
`)));
|
|
892
775
|
return {
|
|
893
776
|
name: "browser-stream",
|
|
894
777
|
level: options.level,
|
|
@@ -912,8 +795,8 @@ function browserJsonStreamTransport(options) {
|
|
|
912
795
|
|
|
913
796
|
// src/transports/console.ts
|
|
914
797
|
function consoleTransport(options = {}) {
|
|
915
|
-
const useConsoleLevels = options.useConsoleLevels
|
|
916
|
-
const formatter = options.formatter
|
|
798
|
+
const useConsoleLevels = _nullishCoalesce(options.useConsoleLevels, () => ( true));
|
|
799
|
+
const formatter = _nullishCoalesce(options.formatter, () => ( ((entry) => JSON.stringify(entry))));
|
|
917
800
|
return {
|
|
918
801
|
name: "console",
|
|
919
802
|
level: options.level,
|
|
@@ -1033,7 +916,7 @@ ${JSON.stringify(entry.meta, null, 2).slice(
|
|
|
1033
916
|
)}
|
|
1034
917
|
\`\`\``
|
|
1035
918
|
},
|
|
1036
|
-
entry.error
|
|
919
|
+
_optionalChain([entry, 'access', _26 => _26.error, 'optionalAccess', _27 => _27.stack]) ? {
|
|
1037
920
|
name: "Stack",
|
|
1038
921
|
value: `\`\`\`js
|
|
1039
922
|
${entry.error.stack.slice(0, 1e3)}
|
|
@@ -1054,12 +937,12 @@ function getLevelColor(level) {
|
|
|
1054
937
|
// src/transports/loki.ts
|
|
1055
938
|
function lokiTransport(options) {
|
|
1056
939
|
const { host, level } = options;
|
|
1057
|
-
const staticLabels = options.labels
|
|
1058
|
-
const batchSize = options.batchSize
|
|
1059
|
-
const interval = options.interval
|
|
940
|
+
const staticLabels = _nullishCoalesce(options.labels, () => ( { app: "voltlog" }));
|
|
941
|
+
const batchSize = _nullishCoalesce(options.batchSize, () => ( 10));
|
|
942
|
+
const interval = _nullishCoalesce(options.interval, () => ( 5e3));
|
|
1060
943
|
const includeMetadata = options.includeMetadata !== false;
|
|
1061
|
-
const retryEnabled = options.retry
|
|
1062
|
-
const maxRetries = options.maxRetries
|
|
944
|
+
const retryEnabled = _nullishCoalesce(options.retry, () => ( false));
|
|
945
|
+
const maxRetries = _nullishCoalesce(options.maxRetries, () => ( 3));
|
|
1063
946
|
const url = `${host.replace(/\/$/, "")}/loki/api/v1/push`;
|
|
1064
947
|
const headers = {
|
|
1065
948
|
"Content-Type": "application/json"
|
|
@@ -1182,7 +1065,7 @@ function lokiTransport(options) {
|
|
|
1182
1065
|
await doFlush();
|
|
1183
1066
|
},
|
|
1184
1067
|
async close() {
|
|
1185
|
-
await this.flush
|
|
1068
|
+
await _optionalChain([this, 'access', _28 => _28.flush, 'optionalCall', _29 => _29()]);
|
|
1186
1069
|
}
|
|
1187
1070
|
};
|
|
1188
1071
|
}
|
|
@@ -1198,8 +1081,8 @@ var OTEL_SEVERITY_MAP = {
|
|
|
1198
1081
|
};
|
|
1199
1082
|
function otelTransport(options) {
|
|
1200
1083
|
const { endpoint, serviceName, level, resource = {} } = options;
|
|
1201
|
-
const batchSize = options.batchSize
|
|
1202
|
-
const interval = options.interval
|
|
1084
|
+
const batchSize = _nullishCoalesce(options.batchSize, () => ( 20));
|
|
1085
|
+
const interval = _nullishCoalesce(options.interval, () => ( 5e3));
|
|
1203
1086
|
const url = `${endpoint.replace(/\/$/, "")}/v1/logs`;
|
|
1204
1087
|
const headers = {
|
|
1205
1088
|
"Content-Type": "application/json",
|
|
@@ -1215,7 +1098,7 @@ function otelTransport(options) {
|
|
|
1215
1098
|
let buffer = [];
|
|
1216
1099
|
let timer = null;
|
|
1217
1100
|
function toOtlpLogRecord(entry) {
|
|
1218
|
-
const severity = OTEL_SEVERITY_MAP[entry.levelName]
|
|
1101
|
+
const severity = _nullishCoalesce(OTEL_SEVERITY_MAP[entry.levelName], () => ( OTEL_SEVERITY_MAP.INFO));
|
|
1219
1102
|
const attributes = [];
|
|
1220
1103
|
if (entry.meta && typeof entry.meta === "object") {
|
|
1221
1104
|
for (const [key, val] of Object.entries(entry.meta)) {
|
|
@@ -1260,19 +1143,19 @@ function otelTransport(options) {
|
|
|
1260
1143
|
const record = {
|
|
1261
1144
|
timeUnixNano: String(entry.timestamp * 1e6),
|
|
1262
1145
|
// ms → ns
|
|
1263
|
-
severityNumber: severity
|
|
1264
|
-
severityText: severity
|
|
1146
|
+
severityNumber: _optionalChain([severity, 'optionalAccess', _30 => _30.number]),
|
|
1147
|
+
severityText: _optionalChain([severity, 'optionalAccess', _31 => _31.text]),
|
|
1265
1148
|
body: { stringValue: entry.message },
|
|
1266
1149
|
attributes
|
|
1267
1150
|
};
|
|
1268
1151
|
const meta = entry.meta;
|
|
1269
|
-
if (meta
|
|
1152
|
+
if (_optionalChain([meta, 'optionalAccess', _32 => _32.traceId])) {
|
|
1270
1153
|
record.traceId = meta.traceId;
|
|
1271
1154
|
}
|
|
1272
|
-
if (meta
|
|
1155
|
+
if (_optionalChain([meta, 'optionalAccess', _33 => _33.spanId])) {
|
|
1273
1156
|
record.spanId = meta.spanId;
|
|
1274
1157
|
}
|
|
1275
|
-
if (meta
|
|
1158
|
+
if (_optionalChain([meta, 'optionalAccess', _34 => _34.traceFlags]) !== void 0) {
|
|
1276
1159
|
record.flags = meta.traceFlags;
|
|
1277
1160
|
}
|
|
1278
1161
|
return record;
|
|
@@ -1343,7 +1226,7 @@ function otelTransport(options) {
|
|
|
1343
1226
|
await sendBatch(batch);
|
|
1344
1227
|
},
|
|
1345
1228
|
async close() {
|
|
1346
|
-
await this.flush
|
|
1229
|
+
await _optionalChain([this, 'access', _35 => _35.flush, 'optionalCall', _36 => _36()]);
|
|
1347
1230
|
}
|
|
1348
1231
|
};
|
|
1349
1232
|
}
|
|
@@ -1384,29 +1267,29 @@ var DIRECTION_ARROWS = {
|
|
|
1384
1267
|
OUT: "\u2190"
|
|
1385
1268
|
};
|
|
1386
1269
|
function prettyTransport(options = {}) {
|
|
1387
|
-
const showTimestamps = options.timestamps
|
|
1388
|
-
const useColors = options.colors
|
|
1389
|
-
const hideMeta = options.hideMeta
|
|
1390
|
-
const prettyMeta = options.prettyMeta
|
|
1270
|
+
const showTimestamps = _nullishCoalesce(options.timestamps, () => ( true));
|
|
1271
|
+
const useColors = _nullishCoalesce(options.colors, () => ( true));
|
|
1272
|
+
const hideMeta = _nullishCoalesce(options.hideMeta, () => ( false));
|
|
1273
|
+
const prettyMeta = _nullishCoalesce(options.prettyMeta, () => ( false));
|
|
1391
1274
|
function colorize(text, color) {
|
|
1392
1275
|
return useColors ? `${color}${text}${RESET}` : text;
|
|
1393
1276
|
}
|
|
1394
1277
|
function formatExchange(entry) {
|
|
1395
1278
|
const meta = entry.meta;
|
|
1396
1279
|
if (!meta || !meta.action || !meta.messageType) return null;
|
|
1397
|
-
const icon = EXCHANGE_ICONS[meta.messageType]
|
|
1398
|
-
const arrow = DIRECTION_ARROWS[meta.direction
|
|
1399
|
-
const cpId = meta.chargePointId
|
|
1280
|
+
const icon = _nullishCoalesce(EXCHANGE_ICONS[meta.messageType], () => ( "\u2022"));
|
|
1281
|
+
const arrow = _nullishCoalesce(DIRECTION_ARROWS[_nullishCoalesce(meta.direction, () => ( "IN"))], () => ( "\u2192"));
|
|
1282
|
+
const cpId = _nullishCoalesce(meta.chargePointId, () => ( "unknown"));
|
|
1400
1283
|
const action = meta.action;
|
|
1401
1284
|
const msgType = meta.messageType;
|
|
1402
|
-
const dir = meta.direction
|
|
1285
|
+
const dir = _nullishCoalesce(meta.direction, () => ( ""));
|
|
1403
1286
|
let line = `${icon} ${colorize(cpId, BOLD)} ${arrow} ${colorize(
|
|
1404
1287
|
action,
|
|
1405
1288
|
BOLD
|
|
1406
1289
|
)} [${dir}] ${colorize(msgType, DIM)}`;
|
|
1407
1290
|
if (meta.status || meta.latencyMs !== void 0) {
|
|
1408
1291
|
const statusIcon = meta.messageType === "CALLERROR" ? "\u274C" : "\u2714";
|
|
1409
|
-
const status = meta.status
|
|
1292
|
+
const status = _nullishCoalesce(meta.status, () => ( ""));
|
|
1410
1293
|
const latency = meta.latencyMs !== void 0 ? `(${meta.latencyMs}ms)` : "";
|
|
1411
1294
|
line += `
|
|
1412
1295
|
${statusIcon} ${status} ${colorize(latency, DIM)}`;
|
|
@@ -1414,8 +1297,8 @@ ${statusIcon} ${status} ${colorize(latency, DIM)}`;
|
|
|
1414
1297
|
return line;
|
|
1415
1298
|
}
|
|
1416
1299
|
function formatStandard(entry) {
|
|
1417
|
-
const icon = ICONS[entry.levelName]
|
|
1418
|
-
const levelColor = COLORS[entry.levelName]
|
|
1300
|
+
const icon = _nullishCoalesce(ICONS[entry.levelName], () => ( "\u2022"));
|
|
1301
|
+
const levelColor = _nullishCoalesce(COLORS[entry.levelName], () => ( ""));
|
|
1419
1302
|
const level = colorize(entry.levelName.padEnd(5), levelColor);
|
|
1420
1303
|
const ts = showTimestamps ? `${colorize(new Date(entry.timestamp).toISOString(), DIM)} ` : "";
|
|
1421
1304
|
let line = `${icon} ${ts}${level} ${entry.message}`;
|
|
@@ -1445,8 +1328,8 @@ ${statusIcon} ${status} ${colorize(latency, DIM)}`;
|
|
|
1445
1328
|
if (entry.error) {
|
|
1446
1329
|
line += `
|
|
1447
1330
|
${colorize(
|
|
1448
|
-
`${entry.error.name
|
|
1449
|
-
COLORS.ERROR
|
|
1331
|
+
`${_nullishCoalesce(entry.error.name, () => ( "Error"))}: ${entry.error.message}`,
|
|
1332
|
+
_nullishCoalesce(COLORS.ERROR, () => ( ""))
|
|
1450
1333
|
)}`;
|
|
1451
1334
|
if (entry.error.stack) {
|
|
1452
1335
|
line += `
|
|
@@ -1478,7 +1361,7 @@ ${colorize(entry.error.stack, DIM)}`;
|
|
|
1478
1361
|
|
|
1479
1362
|
// src/transports/ring-buffer.ts
|
|
1480
1363
|
function ringBufferTransport(options = {}) {
|
|
1481
|
-
const maxSize = options.maxSize
|
|
1364
|
+
const maxSize = _nullishCoalesce(options.maxSize, () => ( 1e3));
|
|
1482
1365
|
const buffer = [];
|
|
1483
1366
|
let head = 0;
|
|
1484
1367
|
let count = 0;
|
|
@@ -1501,15 +1384,15 @@ function ringBufferTransport(options = {}) {
|
|
|
1501
1384
|
} else {
|
|
1502
1385
|
entries = [...buffer.slice(head), ...buffer.slice(0, head)];
|
|
1503
1386
|
}
|
|
1504
|
-
if (query
|
|
1387
|
+
if (_optionalChain([query, 'optionalAccess', _37 => _37.level])) {
|
|
1505
1388
|
const minLevel = resolveLevel(query.level);
|
|
1506
1389
|
entries = entries.filter((e) => e.level >= minLevel);
|
|
1507
1390
|
}
|
|
1508
|
-
if (query
|
|
1391
|
+
if (_optionalChain([query, 'optionalAccess', _38 => _38.since])) {
|
|
1509
1392
|
const since = query.since;
|
|
1510
1393
|
entries = entries.filter((e) => e.timestamp >= since);
|
|
1511
1394
|
}
|
|
1512
|
-
if (query
|
|
1395
|
+
if (_optionalChain([query, 'optionalAccess', _39 => _39.limit])) {
|
|
1513
1396
|
entries = entries.slice(-query.limit);
|
|
1514
1397
|
}
|
|
1515
1398
|
return entries;
|
|
@@ -1528,8 +1411,8 @@ function ringBufferTransport(options = {}) {
|
|
|
1528
1411
|
// src/transports/sentry.ts
|
|
1529
1412
|
function sentryTransport(options) {
|
|
1530
1413
|
const { sentry } = options;
|
|
1531
|
-
const errorLevelValue = resolveLevel(options.errorLevel
|
|
1532
|
-
const breadcrumbLevelValue = resolveLevel(options.breadcrumbLevel
|
|
1414
|
+
const errorLevelValue = resolveLevel(_nullishCoalesce(options.errorLevel, () => ( "ERROR")));
|
|
1415
|
+
const breadcrumbLevelValue = resolveLevel(_nullishCoalesce(options.breadcrumbLevel, () => ( "INFO")));
|
|
1533
1416
|
return {
|
|
1534
1417
|
name: "sentry",
|
|
1535
1418
|
write(entry) {
|
|
@@ -1571,7 +1454,7 @@ function slackTransport(options) {
|
|
|
1571
1454
|
const { webhookUrl, username, iconEmoji, level } = options;
|
|
1572
1455
|
return {
|
|
1573
1456
|
name: "slack",
|
|
1574
|
-
level: level
|
|
1457
|
+
level: _nullishCoalesce(level, () => ( "ERROR")),
|
|
1575
1458
|
// Default to ERROR to prevent spamming
|
|
1576
1459
|
async write(entry) {
|
|
1577
1460
|
try {
|
|
@@ -1631,7 +1514,7 @@ function formatSlackMessage(entry, username, icon_emoji) {
|
|
|
1631
1514
|
}
|
|
1632
1515
|
});
|
|
1633
1516
|
}
|
|
1634
|
-
if (entry.error
|
|
1517
|
+
if (_optionalChain([entry, 'access', _40 => _40.error, 'optionalAccess', _41 => _41.stack])) {
|
|
1635
1518
|
blocks.push({
|
|
1636
1519
|
type: "section",
|
|
1637
1520
|
text: {
|
|
@@ -1681,11 +1564,11 @@ function webhookTransport(options) {
|
|
|
1681
1564
|
retry = false,
|
|
1682
1565
|
maxRetries = 3
|
|
1683
1566
|
} = options;
|
|
1684
|
-
const serialize = options.serializer
|
|
1567
|
+
const serialize = _nullishCoalesce(options.serializer, () => ( ((entries) => JSON.stringify({
|
|
1685
1568
|
entries,
|
|
1686
1569
|
count: entries.length,
|
|
1687
1570
|
timestamp: Date.now()
|
|
1688
|
-
}));
|
|
1571
|
+
}))));
|
|
1689
1572
|
let buffer = [];
|
|
1690
1573
|
let flushTimer = null;
|
|
1691
1574
|
async function sendBatch(entries, attempt = 0) {
|
|
@@ -1703,7 +1586,7 @@ function webhookTransport(options) {
|
|
|
1703
1586
|
await new Promise((r) => setTimeout(r, delay));
|
|
1704
1587
|
return sendBatch(entries, attempt + 1);
|
|
1705
1588
|
}
|
|
1706
|
-
} catch {
|
|
1589
|
+
} catch (e7) {
|
|
1707
1590
|
if (retry && attempt < maxRetries) {
|
|
1708
1591
|
const delay = Math.min(1e3 * 2 ** attempt, 3e4);
|
|
1709
1592
|
await new Promise((r) => setTimeout(r, delay));
|
|
@@ -1748,7 +1631,42 @@ function webhookTransport(options) {
|
|
|
1748
1631
|
}
|
|
1749
1632
|
},
|
|
1750
1633
|
async close() {
|
|
1751
|
-
await this.flush
|
|
1634
|
+
await _optionalChain([this, 'access', _42 => _42.flush, 'optionalCall', _43 => _43()]);
|
|
1752
1635
|
}
|
|
1753
1636
|
};
|
|
1754
1637
|
}
|
|
1638
|
+
|
|
1639
|
+
|
|
1640
|
+
|
|
1641
|
+
|
|
1642
|
+
|
|
1643
|
+
|
|
1644
|
+
|
|
1645
|
+
|
|
1646
|
+
|
|
1647
|
+
|
|
1648
|
+
|
|
1649
|
+
|
|
1650
|
+
|
|
1651
|
+
|
|
1652
|
+
|
|
1653
|
+
|
|
1654
|
+
|
|
1655
|
+
|
|
1656
|
+
|
|
1657
|
+
|
|
1658
|
+
|
|
1659
|
+
|
|
1660
|
+
|
|
1661
|
+
|
|
1662
|
+
|
|
1663
|
+
|
|
1664
|
+
|
|
1665
|
+
|
|
1666
|
+
|
|
1667
|
+
|
|
1668
|
+
|
|
1669
|
+
|
|
1670
|
+
|
|
1671
|
+
|
|
1672
|
+
exports.LogLevel = LogLevel; exports.LogLevelNameMap = LogLevelNameMap; exports.LogLevelValueMap = LogLevelValueMap; exports.aiEnrichmentMiddleware = aiEnrichmentMiddleware; exports.alertMiddleware = alertMiddleware; exports.batchTransport = batchTransport; exports.browserJsonStreamTransport = browserJsonStreamTransport; exports.consoleTransport = consoleTransport; exports.createHttpLogger = createHttpLogger; exports.createLogger = createLogger; exports.createMiddleware = createMiddleware; exports.createOpenAiErrorAnalyzer = createOpenAiErrorAnalyzer; exports.createTransport = createTransport; exports.datadogTransport = datadogTransport; exports.deduplicationMiddleware = deduplicationMiddleware; exports.discordTransport = discordTransport; exports.heapUsageMiddleware = heapUsageMiddleware; exports.ipMiddleware = ipMiddleware; exports.levelOverrideMiddleware = levelOverrideMiddleware; exports.lokiTransport = lokiTransport; exports.ocppMiddleware = ocppMiddleware; exports.otelTransport = otelTransport; exports.prettyTransport = prettyTransport; exports.redactionMiddleware = redactionMiddleware; exports.resolveLevel = resolveLevel; exports.ringBufferTransport = ringBufferTransport; exports.samplingMiddleware = samplingMiddleware; exports.sentryTransport = sentryTransport; exports.shouldIncludeStack = shouldIncludeStack; exports.shouldLog = shouldLog; exports.slackTransport = slackTransport; exports.userAgentMiddleware = userAgentMiddleware; exports.webhookTransport = webhookTransport;
|