voltlog-io 1.0.6 → 1.0.7

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.
@@ -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 _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } 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?.randomUUID === "function" ? () => globalThis.crypto.randomUUID() : () => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
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
- _level;
129
- _transports;
130
- _middlewareList;
131
- _pipeline;
132
- _context;
133
- _includeStack;
134
- _timestampFn;
135
- _idFn;
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
136
76
  constructor(options = {}) {
137
- this._level = resolveLevel(options.level ?? "INFO");
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 ?? "ERROR";
142
- this._timestampFn = options.timestamp ?? Date.now;
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] ?? "INFO";
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 ?? "INFO";
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?.()).filter(Boolean));
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?.()).filter(Boolean));
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 ?? "ERROR");
377
- const timeoutMs = options.timeout ?? 2e3;
378
- const swallow = options.swallowErrors ?? true;
379
- const fieldName = options.targetField ?? "ai_analysis";
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?.[0]?.message?.content ?? null;
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 ?? Infinity;
451
- const threshold = rule.threshold ?? 1;
452
- const cooldownMs = rule.cooldownMs ?? 0;
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 ?? 1e3;
485
- const keyFn = options.keyFn ?? ((e) => `${e.level}:${e.message}:${e.error?.message ?? ""}`);
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 ?? "memory";
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?.(req)) {
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 ?? "ip";
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 ?? "x-log-level";
646
- const cleanup = options.cleanup ?? true;
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?.[key] || meta.headers?.[key];
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 ?? true;
671
- const propagateCorrelationId = options.propagateCorrelationId ?? true;
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) {
@@ -686,24 +606,27 @@ function ocppMiddleware(options = {}) {
686
606
 
687
607
  // src/middleware/otel-trace.ts
688
608
  function otelTraceMiddleware(options = {}) {
689
- let traceApi = options.traceApi ?? null;
609
+ let traceApi = _nullishCoalesce(options.traceApi, () => ( null));
690
610
  let resolved = !!traceApi;
691
- if (!resolved) {
692
- try {
693
- const { createRequire } = require("module");
694
- const dynamicRequire = createRequire(__filename);
695
- const api = dynamicRequire("@opentelemetry/api");
611
+ let resolvePromise = null;
612
+ function ensureResolved() {
613
+ if (resolved || resolvePromise) return _nullishCoalesce(resolvePromise, () => ( Promise.resolve()));
614
+ resolvePromise = Promise.resolve().then(() => _interopRequireWildcard(require("@opentelemetry/api"))).then((api) => {
696
615
  traceApi = api;
697
616
  resolved = true;
698
- } catch {
699
- }
617
+ }).catch(() => {
618
+ resolved = true;
619
+ });
620
+ return resolvePromise;
700
621
  }
701
622
  return (entry, next) => {
702
- if (resolved && traceApi?.trace) {
623
+ ensureResolved().catch(() => {
624
+ });
625
+ if (resolved && _optionalChain([traceApi, 'optionalAccess', _18 => _18.trace])) {
703
626
  try {
704
- const activeSpan = traceApi.trace.getActiveSpan?.();
627
+ const activeSpan = _optionalChain([traceApi, 'access', _19 => _19.trace, 'access', _20 => _20.getActiveSpan, 'optionalCall', _21 => _21()]);
705
628
  if (activeSpan) {
706
- const spanContext = activeSpan.spanContext?.();
629
+ const spanContext = _optionalChain([activeSpan, 'access', _22 => _22.spanContext, 'optionalCall', _23 => _23()]);
707
630
  if (spanContext) {
708
631
  const meta = entry.meta;
709
632
  meta.traceId = spanContext.traceId;
@@ -714,7 +637,7 @@ function otelTraceMiddleware(options = {}) {
714
637
  }
715
638
  }
716
639
  }
717
- } catch {
640
+ } catch (e6) {
718
641
  }
719
642
  }
720
643
  next(entry);
@@ -725,8 +648,8 @@ function otelTraceMiddleware(options = {}) {
725
648
  var DEFAULT_REDACT_VALUE = "[REDACTED]";
726
649
  function redactionMiddleware(options) {
727
650
  const paths = new Set(options.paths.map((p) => p.toLowerCase()));
728
- const replacement = options.replacement ?? DEFAULT_REDACT_VALUE;
729
- const deep = options.deep ?? true;
651
+ const replacement = _nullishCoalesce(options.replacement, () => ( DEFAULT_REDACT_VALUE));
652
+ const deep = _nullishCoalesce(options.deep, () => ( true));
730
653
  function redactObject(obj) {
731
654
  const result = {};
732
655
  for (const [key, value] of Object.entries(obj)) {
@@ -756,11 +679,11 @@ function redactionMiddleware(options) {
756
679
 
757
680
  // src/middleware/sampling.ts
758
681
  function samplingMiddleware(options = {}) {
759
- const keyFn = options.keyFn ?? ((entry) => entry.message);
760
- const maxPerWindow = options.maxPerWindow ?? 100;
761
- const windowMs = options.windowMs ?? 6e4;
762
- const sampleRate = options.sampleRate ?? 1;
763
- const priorityLevel = options.priorityLevel ?? 40;
682
+ const keyFn = _nullishCoalesce(options.keyFn, () => ( ((entry) => entry.message)));
683
+ const maxPerWindow = _nullishCoalesce(options.maxPerWindow, () => ( 100));
684
+ const windowMs = _nullishCoalesce(options.windowMs, () => ( 6e4));
685
+ const sampleRate = _nullishCoalesce(options.sampleRate, () => ( 1));
686
+ const priorityLevel = _nullishCoalesce(options.priorityLevel, () => ( 40));
764
687
  const buckets = /* @__PURE__ */ new Map();
765
688
  return (entry, next) => {
766
689
  if (entry.level >= priorityLevel) {
@@ -794,11 +717,11 @@ function samplingMiddleware(options = {}) {
794
717
  // src/middleware/user-agent.ts
795
718
  function userAgentMiddleware(options = {}) {
796
719
  const sourceField = options.sourceField;
797
- const targetField = options.targetField ?? "client";
720
+ const targetField = _nullishCoalesce(options.targetField, () => ( "client"));
798
721
  return (entry, next) => {
799
722
  const meta = entry.meta;
800
723
  const context = entry.context;
801
- const ua = (sourceField ? meta[sourceField] : void 0) || meta.userAgent || meta["user-agent"] || context?.userAgent || context?.["user-agent"];
724
+ const ua = (sourceField ? meta[sourceField] : void 0) || meta.userAgent || meta["user-agent"] || _optionalChain([context, 'optionalAccess', _24 => _24.userAgent]) || _optionalChain([context, 'optionalAccess', _25 => _25["user-agent"]]);
802
725
  if (ua) {
803
726
  const info = parseUserAgent(ua);
804
727
  entry.meta = {
@@ -831,8 +754,8 @@ function parseUserAgent(ua) {
831
754
 
832
755
  // src/transports/batch.ts
833
756
  function batchTransport(inner, options = {}) {
834
- const batchSize = options.batchSize ?? 100;
835
- const flushIntervalMs = options.flushIntervalMs ?? 5e3;
757
+ const batchSize = _nullishCoalesce(options.batchSize, () => ( 100));
758
+ const flushIntervalMs = _nullishCoalesce(options.flushIntervalMs, () => ( 5e3));
836
759
  let buffer = [];
837
760
  let flushTimer = null;
838
761
  function scheduleFlush() {
@@ -853,7 +776,7 @@ function batchTransport(inner, options = {}) {
853
776
  result.catch(() => {
854
777
  });
855
778
  }
856
- } catch {
779
+ } catch (e7) {
857
780
  }
858
781
  }
859
782
  }
@@ -874,11 +797,11 @@ function batchTransport(inner, options = {}) {
874
797
  flushTimer = null;
875
798
  }
876
799
  doFlush();
877
- await inner.flush?.();
800
+ await _optionalChain([inner, 'access', _26 => _26.flush, 'optionalCall', _27 => _27()]);
878
801
  },
879
802
  async close() {
880
- await this.flush?.();
881
- await inner.close?.();
803
+ await _optionalChain([this, 'access', _28 => _28.flush, 'optionalCall', _29 => _29()]);
804
+ await _optionalChain([inner, 'access', _30 => _30.close, 'optionalCall', _31 => _31()]);
882
805
  }
883
806
  };
884
807
  }
@@ -887,8 +810,8 @@ function batchTransport(inner, options = {}) {
887
810
  function browserJsonStreamTransport(options) {
888
811
  const stream = options.stream;
889
812
  const writer = stream.getWriter();
890
- const serialize = options.serializer ?? ((entry) => `${JSON.stringify(entry)}
891
- `);
813
+ const serialize = _nullishCoalesce(options.serializer, () => ( ((entry) => `${JSON.stringify(entry)}
814
+ `)));
892
815
  return {
893
816
  name: "browser-stream",
894
817
  level: options.level,
@@ -912,8 +835,8 @@ function browserJsonStreamTransport(options) {
912
835
 
913
836
  // src/transports/console.ts
914
837
  function consoleTransport(options = {}) {
915
- const useConsoleLevels = options.useConsoleLevels ?? true;
916
- const formatter = options.formatter ?? ((entry) => JSON.stringify(entry));
838
+ const useConsoleLevels = _nullishCoalesce(options.useConsoleLevels, () => ( true));
839
+ const formatter = _nullishCoalesce(options.formatter, () => ( ((entry) => JSON.stringify(entry))));
917
840
  return {
918
841
  name: "console",
919
842
  level: options.level,
@@ -1033,7 +956,7 @@ ${JSON.stringify(entry.meta, null, 2).slice(
1033
956
  )}
1034
957
  \`\`\``
1035
958
  },
1036
- entry.error?.stack ? {
959
+ _optionalChain([entry, 'access', _32 => _32.error, 'optionalAccess', _33 => _33.stack]) ? {
1037
960
  name: "Stack",
1038
961
  value: `\`\`\`js
1039
962
  ${entry.error.stack.slice(0, 1e3)}
@@ -1054,12 +977,12 @@ function getLevelColor(level) {
1054
977
  // src/transports/loki.ts
1055
978
  function lokiTransport(options) {
1056
979
  const { host, level } = options;
1057
- const staticLabels = options.labels ?? { app: "voltlog" };
1058
- const batchSize = options.batchSize ?? 10;
1059
- const interval = options.interval ?? 5e3;
980
+ const staticLabels = _nullishCoalesce(options.labels, () => ( { app: "voltlog" }));
981
+ const batchSize = _nullishCoalesce(options.batchSize, () => ( 10));
982
+ const interval = _nullishCoalesce(options.interval, () => ( 5e3));
1060
983
  const includeMetadata = options.includeMetadata !== false;
1061
- const retryEnabled = options.retry ?? false;
1062
- const maxRetries = options.maxRetries ?? 3;
984
+ const retryEnabled = _nullishCoalesce(options.retry, () => ( false));
985
+ const maxRetries = _nullishCoalesce(options.maxRetries, () => ( 3));
1063
986
  const url = `${host.replace(/\/$/, "")}/loki/api/v1/push`;
1064
987
  const headers = {
1065
988
  "Content-Type": "application/json"
@@ -1182,7 +1105,7 @@ function lokiTransport(options) {
1182
1105
  await doFlush();
1183
1106
  },
1184
1107
  async close() {
1185
- await this.flush?.();
1108
+ await _optionalChain([this, 'access', _34 => _34.flush, 'optionalCall', _35 => _35()]);
1186
1109
  }
1187
1110
  };
1188
1111
  }
@@ -1198,8 +1121,8 @@ var OTEL_SEVERITY_MAP = {
1198
1121
  };
1199
1122
  function otelTransport(options) {
1200
1123
  const { endpoint, serviceName, level, resource = {} } = options;
1201
- const batchSize = options.batchSize ?? 20;
1202
- const interval = options.interval ?? 5e3;
1124
+ const batchSize = _nullishCoalesce(options.batchSize, () => ( 20));
1125
+ const interval = _nullishCoalesce(options.interval, () => ( 5e3));
1203
1126
  const url = `${endpoint.replace(/\/$/, "")}/v1/logs`;
1204
1127
  const headers = {
1205
1128
  "Content-Type": "application/json",
@@ -1215,7 +1138,7 @@ function otelTransport(options) {
1215
1138
  let buffer = [];
1216
1139
  let timer = null;
1217
1140
  function toOtlpLogRecord(entry) {
1218
- const severity = OTEL_SEVERITY_MAP[entry.levelName] ?? OTEL_SEVERITY_MAP.INFO;
1141
+ const severity = _nullishCoalesce(OTEL_SEVERITY_MAP[entry.levelName], () => ( OTEL_SEVERITY_MAP.INFO));
1219
1142
  const attributes = [];
1220
1143
  if (entry.meta && typeof entry.meta === "object") {
1221
1144
  for (const [key, val] of Object.entries(entry.meta)) {
@@ -1260,19 +1183,19 @@ function otelTransport(options) {
1260
1183
  const record = {
1261
1184
  timeUnixNano: String(entry.timestamp * 1e6),
1262
1185
  // ms → ns
1263
- severityNumber: severity?.number,
1264
- severityText: severity?.text,
1186
+ severityNumber: _optionalChain([severity, 'optionalAccess', _36 => _36.number]),
1187
+ severityText: _optionalChain([severity, 'optionalAccess', _37 => _37.text]),
1265
1188
  body: { stringValue: entry.message },
1266
1189
  attributes
1267
1190
  };
1268
1191
  const meta = entry.meta;
1269
- if (meta?.traceId) {
1192
+ if (_optionalChain([meta, 'optionalAccess', _38 => _38.traceId])) {
1270
1193
  record.traceId = meta.traceId;
1271
1194
  }
1272
- if (meta?.spanId) {
1195
+ if (_optionalChain([meta, 'optionalAccess', _39 => _39.spanId])) {
1273
1196
  record.spanId = meta.spanId;
1274
1197
  }
1275
- if (meta?.traceFlags !== void 0) {
1198
+ if (_optionalChain([meta, 'optionalAccess', _40 => _40.traceFlags]) !== void 0) {
1276
1199
  record.flags = meta.traceFlags;
1277
1200
  }
1278
1201
  return record;
@@ -1343,7 +1266,7 @@ function otelTransport(options) {
1343
1266
  await sendBatch(batch);
1344
1267
  },
1345
1268
  async close() {
1346
- await this.flush?.();
1269
+ await _optionalChain([this, 'access', _41 => _41.flush, 'optionalCall', _42 => _42()]);
1347
1270
  }
1348
1271
  };
1349
1272
  }
@@ -1384,29 +1307,29 @@ var DIRECTION_ARROWS = {
1384
1307
  OUT: "\u2190"
1385
1308
  };
1386
1309
  function prettyTransport(options = {}) {
1387
- const showTimestamps = options.timestamps ?? true;
1388
- const useColors = options.colors ?? true;
1389
- const hideMeta = options.hideMeta ?? false;
1390
- const prettyMeta = options.prettyMeta ?? false;
1310
+ const showTimestamps = _nullishCoalesce(options.timestamps, () => ( true));
1311
+ const useColors = _nullishCoalesce(options.colors, () => ( true));
1312
+ const hideMeta = _nullishCoalesce(options.hideMeta, () => ( false));
1313
+ const prettyMeta = _nullishCoalesce(options.prettyMeta, () => ( false));
1391
1314
  function colorize(text, color) {
1392
1315
  return useColors ? `${color}${text}${RESET}` : text;
1393
1316
  }
1394
1317
  function formatExchange(entry) {
1395
1318
  const meta = entry.meta;
1396
1319
  if (!meta || !meta.action || !meta.messageType) return null;
1397
- const icon = EXCHANGE_ICONS[meta.messageType] ?? "\u2022";
1398
- const arrow = DIRECTION_ARROWS[meta.direction ?? "IN"] ?? "\u2192";
1399
- const cpId = meta.chargePointId ?? "unknown";
1320
+ const icon = _nullishCoalesce(EXCHANGE_ICONS[meta.messageType], () => ( "\u2022"));
1321
+ const arrow = _nullishCoalesce(DIRECTION_ARROWS[_nullishCoalesce(meta.direction, () => ( "IN"))], () => ( "\u2192"));
1322
+ const cpId = _nullishCoalesce(meta.chargePointId, () => ( "unknown"));
1400
1323
  const action = meta.action;
1401
1324
  const msgType = meta.messageType;
1402
- const dir = meta.direction ?? "";
1325
+ const dir = _nullishCoalesce(meta.direction, () => ( ""));
1403
1326
  let line = `${icon} ${colorize(cpId, BOLD)} ${arrow} ${colorize(
1404
1327
  action,
1405
1328
  BOLD
1406
1329
  )} [${dir}] ${colorize(msgType, DIM)}`;
1407
1330
  if (meta.status || meta.latencyMs !== void 0) {
1408
1331
  const statusIcon = meta.messageType === "CALLERROR" ? "\u274C" : "\u2714";
1409
- const status = meta.status ?? "";
1332
+ const status = _nullishCoalesce(meta.status, () => ( ""));
1410
1333
  const latency = meta.latencyMs !== void 0 ? `(${meta.latencyMs}ms)` : "";
1411
1334
  line += `
1412
1335
  ${statusIcon} ${status} ${colorize(latency, DIM)}`;
@@ -1414,8 +1337,8 @@ ${statusIcon} ${status} ${colorize(latency, DIM)}`;
1414
1337
  return line;
1415
1338
  }
1416
1339
  function formatStandard(entry) {
1417
- const icon = ICONS[entry.levelName] ?? "\u2022";
1418
- const levelColor = COLORS[entry.levelName] ?? "";
1340
+ const icon = _nullishCoalesce(ICONS[entry.levelName], () => ( "\u2022"));
1341
+ const levelColor = _nullishCoalesce(COLORS[entry.levelName], () => ( ""));
1419
1342
  const level = colorize(entry.levelName.padEnd(5), levelColor);
1420
1343
  const ts = showTimestamps ? `${colorize(new Date(entry.timestamp).toISOString(), DIM)} ` : "";
1421
1344
  let line = `${icon} ${ts}${level} ${entry.message}`;
@@ -1445,8 +1368,8 @@ ${statusIcon} ${status} ${colorize(latency, DIM)}`;
1445
1368
  if (entry.error) {
1446
1369
  line += `
1447
1370
  ${colorize(
1448
- `${entry.error.name ?? "Error"}: ${entry.error.message}`,
1449
- COLORS.ERROR ?? ""
1371
+ `${_nullishCoalesce(entry.error.name, () => ( "Error"))}: ${entry.error.message}`,
1372
+ _nullishCoalesce(COLORS.ERROR, () => ( ""))
1450
1373
  )}`;
1451
1374
  if (entry.error.stack) {
1452
1375
  line += `
@@ -1478,7 +1401,7 @@ ${colorize(entry.error.stack, DIM)}`;
1478
1401
 
1479
1402
  // src/transports/ring-buffer.ts
1480
1403
  function ringBufferTransport(options = {}) {
1481
- const maxSize = options.maxSize ?? 1e3;
1404
+ const maxSize = _nullishCoalesce(options.maxSize, () => ( 1e3));
1482
1405
  const buffer = [];
1483
1406
  let head = 0;
1484
1407
  let count = 0;
@@ -1501,15 +1424,15 @@ function ringBufferTransport(options = {}) {
1501
1424
  } else {
1502
1425
  entries = [...buffer.slice(head), ...buffer.slice(0, head)];
1503
1426
  }
1504
- if (query?.level) {
1427
+ if (_optionalChain([query, 'optionalAccess', _43 => _43.level])) {
1505
1428
  const minLevel = resolveLevel(query.level);
1506
1429
  entries = entries.filter((e) => e.level >= minLevel);
1507
1430
  }
1508
- if (query?.since) {
1431
+ if (_optionalChain([query, 'optionalAccess', _44 => _44.since])) {
1509
1432
  const since = query.since;
1510
1433
  entries = entries.filter((e) => e.timestamp >= since);
1511
1434
  }
1512
- if (query?.limit) {
1435
+ if (_optionalChain([query, 'optionalAccess', _45 => _45.limit])) {
1513
1436
  entries = entries.slice(-query.limit);
1514
1437
  }
1515
1438
  return entries;
@@ -1528,8 +1451,8 @@ function ringBufferTransport(options = {}) {
1528
1451
  // src/transports/sentry.ts
1529
1452
  function sentryTransport(options) {
1530
1453
  const { sentry } = options;
1531
- const errorLevelValue = resolveLevel(options.errorLevel ?? "ERROR");
1532
- const breadcrumbLevelValue = resolveLevel(options.breadcrumbLevel ?? "INFO");
1454
+ const errorLevelValue = resolveLevel(_nullishCoalesce(options.errorLevel, () => ( "ERROR")));
1455
+ const breadcrumbLevelValue = resolveLevel(_nullishCoalesce(options.breadcrumbLevel, () => ( "INFO")));
1533
1456
  return {
1534
1457
  name: "sentry",
1535
1458
  write(entry) {
@@ -1571,7 +1494,7 @@ function slackTransport(options) {
1571
1494
  const { webhookUrl, username, iconEmoji, level } = options;
1572
1495
  return {
1573
1496
  name: "slack",
1574
- level: level ?? "ERROR",
1497
+ level: _nullishCoalesce(level, () => ( "ERROR")),
1575
1498
  // Default to ERROR to prevent spamming
1576
1499
  async write(entry) {
1577
1500
  try {
@@ -1631,7 +1554,7 @@ function formatSlackMessage(entry, username, icon_emoji) {
1631
1554
  }
1632
1555
  });
1633
1556
  }
1634
- if (entry.error?.stack) {
1557
+ if (_optionalChain([entry, 'access', _46 => _46.error, 'optionalAccess', _47 => _47.stack])) {
1635
1558
  blocks.push({
1636
1559
  type: "section",
1637
1560
  text: {
@@ -1681,11 +1604,11 @@ function webhookTransport(options) {
1681
1604
  retry = false,
1682
1605
  maxRetries = 3
1683
1606
  } = options;
1684
- const serialize = options.serializer ?? ((entries) => JSON.stringify({
1607
+ const serialize = _nullishCoalesce(options.serializer, () => ( ((entries) => JSON.stringify({
1685
1608
  entries,
1686
1609
  count: entries.length,
1687
1610
  timestamp: Date.now()
1688
- }));
1611
+ }))));
1689
1612
  let buffer = [];
1690
1613
  let flushTimer = null;
1691
1614
  async function sendBatch(entries, attempt = 0) {
@@ -1703,7 +1626,7 @@ function webhookTransport(options) {
1703
1626
  await new Promise((r) => setTimeout(r, delay));
1704
1627
  return sendBatch(entries, attempt + 1);
1705
1628
  }
1706
- } catch {
1629
+ } catch (e8) {
1707
1630
  if (retry && attempt < maxRetries) {
1708
1631
  const delay = Math.min(1e3 * 2 ** attempt, 3e4);
1709
1632
  await new Promise((r) => setTimeout(r, delay));
@@ -1748,7 +1671,43 @@ function webhookTransport(options) {
1748
1671
  }
1749
1672
  },
1750
1673
  async close() {
1751
- await this.flush?.();
1674
+ await _optionalChain([this, 'access', _48 => _48.flush, 'optionalCall', _49 => _49()]);
1752
1675
  }
1753
1676
  };
1754
1677
  }
1678
+
1679
+
1680
+
1681
+
1682
+
1683
+
1684
+
1685
+
1686
+
1687
+
1688
+
1689
+
1690
+
1691
+
1692
+
1693
+
1694
+
1695
+
1696
+
1697
+
1698
+
1699
+
1700
+
1701
+
1702
+
1703
+
1704
+
1705
+
1706
+
1707
+
1708
+
1709
+
1710
+
1711
+
1712
+
1713
+ 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.otelTraceMiddleware = otelTraceMiddleware; 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;