@graphql-hive/logger 0.0.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/dist/index.cjs ADDED
@@ -0,0 +1,761 @@
1
+ 'use strict';
2
+
3
+ function getDefaultExportFromCjs (x) {
4
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
5
+ }
6
+
7
+ function tryStringify (o) {
8
+ try { return JSON.stringify(o) } catch(e) { return '"[Circular]"' }
9
+ }
10
+
11
+ var quickFormatUnescaped = format;
12
+
13
+ function format(f, args, opts) {
14
+ var ss = (opts && opts.stringify) || tryStringify;
15
+ var offset = 1;
16
+ if (typeof f === 'object' && f !== null) {
17
+ var len = args.length + offset;
18
+ if (len === 1) return f
19
+ var objects = new Array(len);
20
+ objects[0] = ss(f);
21
+ for (var index = 1; index < len; index++) {
22
+ objects[index] = ss(args[index]);
23
+ }
24
+ return objects.join(' ')
25
+ }
26
+ if (typeof f !== 'string') {
27
+ return f
28
+ }
29
+ var argLen = args.length;
30
+ if (argLen === 0) return f
31
+ var str = '';
32
+ var a = 1 - offset;
33
+ var lastPos = -1;
34
+ var flen = (f && f.length) || 0;
35
+ for (var i = 0; i < flen;) {
36
+ if (f.charCodeAt(i) === 37 && i + 1 < flen) {
37
+ lastPos = lastPos > -1 ? lastPos : 0;
38
+ switch (f.charCodeAt(i + 1)) {
39
+ case 100: // 'd'
40
+ case 102: // 'f'
41
+ if (a >= argLen)
42
+ break
43
+ if (args[a] == null) break
44
+ if (lastPos < i)
45
+ str += f.slice(lastPos, i);
46
+ str += Number(args[a]);
47
+ lastPos = i + 2;
48
+ i++;
49
+ break
50
+ case 105: // 'i'
51
+ if (a >= argLen)
52
+ break
53
+ if (args[a] == null) break
54
+ if (lastPos < i)
55
+ str += f.slice(lastPos, i);
56
+ str += Math.floor(Number(args[a]));
57
+ lastPos = i + 2;
58
+ i++;
59
+ break
60
+ case 79: // 'O'
61
+ case 111: // 'o'
62
+ case 106: // 'j'
63
+ if (a >= argLen)
64
+ break
65
+ if (args[a] === undefined) break
66
+ if (lastPos < i)
67
+ str += f.slice(lastPos, i);
68
+ var type = typeof args[a];
69
+ if (type === 'string') {
70
+ str += '\'' + args[a] + '\'';
71
+ lastPos = i + 2;
72
+ i++;
73
+ break
74
+ }
75
+ if (type === 'function') {
76
+ str += args[a].name || '<anonymous>';
77
+ lastPos = i + 2;
78
+ i++;
79
+ break
80
+ }
81
+ str += ss(args[a]);
82
+ lastPos = i + 2;
83
+ i++;
84
+ break
85
+ case 115: // 's'
86
+ if (a >= argLen)
87
+ break
88
+ if (lastPos < i)
89
+ str += f.slice(lastPos, i);
90
+ str += String(args[a]);
91
+ lastPos = i + 2;
92
+ i++;
93
+ break
94
+ case 37: // '%'
95
+ if (lastPos < i)
96
+ str += f.slice(lastPos, i);
97
+ str += '%';
98
+ lastPos = i + 2;
99
+ i++;
100
+ a--;
101
+ break
102
+ }
103
+ ++a;
104
+ }
105
+ ++i;
106
+ }
107
+ if (lastPos === -1)
108
+ return f
109
+ else if (lastPos < flen) {
110
+ str += f.slice(lastPos);
111
+ }
112
+
113
+ return str
114
+ }
115
+
116
+ var format$1 = /*@__PURE__*/getDefaultExportFromCjs(quickFormatUnescaped);
117
+
118
+ const logLevel = {
119
+ trace: 0,
120
+ debug: 1,
121
+ info: 2,
122
+ warn: 3,
123
+ error: 4
124
+ };
125
+ function shouldLog(setLevel, loggingLevel) {
126
+ setLevel = typeof setLevel === "function" ? setLevel() : setLevel;
127
+ return setLevel !== false && // logging is not disabled
128
+ logLevel[setLevel] <= logLevel[loggingLevel];
129
+ }
130
+ function logLevelToString(level) {
131
+ switch (level) {
132
+ case "trace":
133
+ return "TRC";
134
+ case "debug":
135
+ return "DBG";
136
+ case "info":
137
+ return "INF";
138
+ case "warn":
139
+ return "WRN";
140
+ case "error":
141
+ return "ERR";
142
+ default:
143
+ throw new Error(`Unknown log level "${level}"`);
144
+ }
145
+ }
146
+ function isPromise(val) {
147
+ const obj = Object(val);
148
+ return typeof obj.then === "function" && typeof obj.catch === "function" && typeof obj.finally === "function";
149
+ }
150
+ function parseAttrs(attrs, depth = 0) {
151
+ if (depth > 10) {
152
+ throw new Error("Too much recursion while unwrapping function attributes");
153
+ }
154
+ if (typeof attrs === "function") {
155
+ return parseAttrs(attrs(), depth + 1);
156
+ }
157
+ if (Array.isArray(attrs)) {
158
+ return attrs.map((val) => unwrapAttrVal(val, depth + 1));
159
+ }
160
+ if (Object.prototype.toString.call(attrs) === "[object Object]") {
161
+ const unwrapped = {};
162
+ for (const key of Object.keys(attrs)) {
163
+ const val = attrs[key];
164
+ unwrapped[key] = unwrapAttrVal(val, depth + 1);
165
+ }
166
+ return unwrapped;
167
+ }
168
+ return objectifyClass(attrs);
169
+ }
170
+ function unwrapAttrVal(attr, depth = 0) {
171
+ if (depth > 10) {
172
+ throw new Error(
173
+ "Too much recursion while unwrapping function attribute values"
174
+ );
175
+ }
176
+ if (!attr) {
177
+ return attr;
178
+ }
179
+ if (isPrimitive(attr)) {
180
+ return attr;
181
+ }
182
+ if (typeof attr === "function") {
183
+ return unwrapAttrVal(attr(), depth + 1);
184
+ }
185
+ if (Array.isArray(attr)) {
186
+ return attr.map((val) => unwrapAttrVal(val, depth + 1));
187
+ }
188
+ if (Object.prototype.toString.call(attr) === "[object Object]") {
189
+ const unwrapped = {};
190
+ for (const key of Object.keys(attr)) {
191
+ const val = attr[key];
192
+ unwrapped[key] = unwrapAttrVal(val, depth + 1);
193
+ }
194
+ return unwrapped;
195
+ }
196
+ return objectifyClass(attr);
197
+ }
198
+ function isPrimitive(val) {
199
+ return val !== Object(val);
200
+ }
201
+ function objectifyClass(val) {
202
+ if (!val) {
203
+ return {};
204
+ }
205
+ const props = {};
206
+ for (const propName of Object.getOwnPropertyNames(val)) {
207
+ props[propName] = val[propName];
208
+ }
209
+ for (const protoPropName of Object.getOwnPropertyNames(
210
+ Object.getPrototypeOf(val)
211
+ )) {
212
+ const propVal = val[protoPropName];
213
+ if (typeof propVal === "function") {
214
+ continue;
215
+ }
216
+ props[protoPropName] = propVal;
217
+ }
218
+ return {
219
+ ...props,
220
+ class: val.constructor.name
221
+ };
222
+ }
223
+ function getEnv(key) {
224
+ return globalThis.process?.env?.[key] || // @ts-expect-error can exist in wrangler and maybe other runtimes
225
+ globalThis.env?.[key] || // @ts-expect-error can exist in deno
226
+ globalThis.Deno?.env?.get(key) || // @ts-expect-error could be
227
+ globalThis[key];
228
+ }
229
+ function truthyEnv(key) {
230
+ return ["1", "t", "true", "y", "yes"].includes(
231
+ getEnv(key)?.toLowerCase() || ""
232
+ );
233
+ }
234
+
235
+ var fastSafeStringify = stringify;
236
+ stringify.default = stringify;
237
+ stringify.stable = deterministicStringify;
238
+ stringify.stableStringify = deterministicStringify;
239
+
240
+ var LIMIT_REPLACE_NODE = '[...]';
241
+ var CIRCULAR_REPLACE_NODE = '[Circular]';
242
+
243
+ var arr = [];
244
+ var replacerStack = [];
245
+
246
+ function defaultOptions () {
247
+ return {
248
+ depthLimit: Number.MAX_SAFE_INTEGER,
249
+ edgesLimit: Number.MAX_SAFE_INTEGER
250
+ }
251
+ }
252
+
253
+ // Regular stringify
254
+ function stringify (obj, replacer, spacer, options) {
255
+ if (typeof options === 'undefined') {
256
+ options = defaultOptions();
257
+ }
258
+
259
+ decirc(obj, '', 0, [], undefined, 0, options);
260
+ var res;
261
+ try {
262
+ if (replacerStack.length === 0) {
263
+ res = JSON.stringify(obj, replacer, spacer);
264
+ } else {
265
+ res = JSON.stringify(obj, replaceGetterValues(replacer), spacer);
266
+ }
267
+ } catch (_) {
268
+ return JSON.stringify('[unable to serialize, circular reference is too complex to analyze]')
269
+ } finally {
270
+ while (arr.length !== 0) {
271
+ var part = arr.pop();
272
+ if (part.length === 4) {
273
+ Object.defineProperty(part[0], part[1], part[3]);
274
+ } else {
275
+ part[0][part[1]] = part[2];
276
+ }
277
+ }
278
+ }
279
+ return res
280
+ }
281
+
282
+ function setReplace (replace, val, k, parent) {
283
+ var propertyDescriptor = Object.getOwnPropertyDescriptor(parent, k);
284
+ if (propertyDescriptor.get !== undefined) {
285
+ if (propertyDescriptor.configurable) {
286
+ Object.defineProperty(parent, k, { value: replace });
287
+ arr.push([parent, k, val, propertyDescriptor]);
288
+ } else {
289
+ replacerStack.push([val, k, replace]);
290
+ }
291
+ } else {
292
+ parent[k] = replace;
293
+ arr.push([parent, k, val]);
294
+ }
295
+ }
296
+
297
+ function decirc (val, k, edgeIndex, stack, parent, depth, options) {
298
+ depth += 1;
299
+ var i;
300
+ if (typeof val === 'object' && val !== null) {
301
+ for (i = 0; i < stack.length; i++) {
302
+ if (stack[i] === val) {
303
+ setReplace(CIRCULAR_REPLACE_NODE, val, k, parent);
304
+ return
305
+ }
306
+ }
307
+
308
+ if (
309
+ typeof options.depthLimit !== 'undefined' &&
310
+ depth > options.depthLimit
311
+ ) {
312
+ setReplace(LIMIT_REPLACE_NODE, val, k, parent);
313
+ return
314
+ }
315
+
316
+ if (
317
+ typeof options.edgesLimit !== 'undefined' &&
318
+ edgeIndex + 1 > options.edgesLimit
319
+ ) {
320
+ setReplace(LIMIT_REPLACE_NODE, val, k, parent);
321
+ return
322
+ }
323
+
324
+ stack.push(val);
325
+ // Optimize for Arrays. Big arrays could kill the performance otherwise!
326
+ if (Array.isArray(val)) {
327
+ for (i = 0; i < val.length; i++) {
328
+ decirc(val[i], i, i, stack, val, depth, options);
329
+ }
330
+ } else {
331
+ var keys = Object.keys(val);
332
+ for (i = 0; i < keys.length; i++) {
333
+ var key = keys[i];
334
+ decirc(val[key], key, i, stack, val, depth, options);
335
+ }
336
+ }
337
+ stack.pop();
338
+ }
339
+ }
340
+
341
+ // Stable-stringify
342
+ function compareFunction (a, b) {
343
+ if (a < b) {
344
+ return -1
345
+ }
346
+ if (a > b) {
347
+ return 1
348
+ }
349
+ return 0
350
+ }
351
+
352
+ function deterministicStringify (obj, replacer, spacer, options) {
353
+ if (typeof options === 'undefined') {
354
+ options = defaultOptions();
355
+ }
356
+
357
+ var tmp = deterministicDecirc(obj, '', 0, [], undefined, 0, options) || obj;
358
+ var res;
359
+ try {
360
+ if (replacerStack.length === 0) {
361
+ res = JSON.stringify(tmp, replacer, spacer);
362
+ } else {
363
+ res = JSON.stringify(tmp, replaceGetterValues(replacer), spacer);
364
+ }
365
+ } catch (_) {
366
+ return JSON.stringify('[unable to serialize, circular reference is too complex to analyze]')
367
+ } finally {
368
+ // Ensure that we restore the object as it was.
369
+ while (arr.length !== 0) {
370
+ var part = arr.pop();
371
+ if (part.length === 4) {
372
+ Object.defineProperty(part[0], part[1], part[3]);
373
+ } else {
374
+ part[0][part[1]] = part[2];
375
+ }
376
+ }
377
+ }
378
+ return res
379
+ }
380
+
381
+ function deterministicDecirc (val, k, edgeIndex, stack, parent, depth, options) {
382
+ depth += 1;
383
+ var i;
384
+ if (typeof val === 'object' && val !== null) {
385
+ for (i = 0; i < stack.length; i++) {
386
+ if (stack[i] === val) {
387
+ setReplace(CIRCULAR_REPLACE_NODE, val, k, parent);
388
+ return
389
+ }
390
+ }
391
+ try {
392
+ if (typeof val.toJSON === 'function') {
393
+ return
394
+ }
395
+ } catch (_) {
396
+ return
397
+ }
398
+
399
+ if (
400
+ typeof options.depthLimit !== 'undefined' &&
401
+ depth > options.depthLimit
402
+ ) {
403
+ setReplace(LIMIT_REPLACE_NODE, val, k, parent);
404
+ return
405
+ }
406
+
407
+ if (
408
+ typeof options.edgesLimit !== 'undefined' &&
409
+ edgeIndex + 1 > options.edgesLimit
410
+ ) {
411
+ setReplace(LIMIT_REPLACE_NODE, val, k, parent);
412
+ return
413
+ }
414
+
415
+ stack.push(val);
416
+ // Optimize for Arrays. Big arrays could kill the performance otherwise!
417
+ if (Array.isArray(val)) {
418
+ for (i = 0; i < val.length; i++) {
419
+ deterministicDecirc(val[i], i, i, stack, val, depth, options);
420
+ }
421
+ } else {
422
+ // Create a temporary object in the required way
423
+ var tmp = {};
424
+ var keys = Object.keys(val).sort(compareFunction);
425
+ for (i = 0; i < keys.length; i++) {
426
+ var key = keys[i];
427
+ deterministicDecirc(val[key], key, i, stack, val, depth, options);
428
+ tmp[key] = val[key];
429
+ }
430
+ if (typeof parent !== 'undefined') {
431
+ arr.push([parent, k, val]);
432
+ parent[k] = tmp;
433
+ } else {
434
+ return tmp
435
+ }
436
+ }
437
+ stack.pop();
438
+ }
439
+ }
440
+
441
+ // wraps replacer function to handle values we couldn't replace
442
+ // and mark them as replaced value
443
+ function replaceGetterValues (replacer) {
444
+ replacer =
445
+ typeof replacer !== 'undefined'
446
+ ? replacer
447
+ : function (k, v) {
448
+ return v
449
+ };
450
+ return function (key, val) {
451
+ if (replacerStack.length > 0) {
452
+ for (var i = 0; i < replacerStack.length; i++) {
453
+ var part = replacerStack[i];
454
+ if (part[1] === key && part[0] === val) {
455
+ val = part[2];
456
+ replacerStack.splice(i, 1);
457
+ break
458
+ }
459
+ }
460
+ }
461
+ return replacer.call(this, key, val)
462
+ }
463
+ }
464
+
465
+ var fastSafeStringify$1 = /*@__PURE__*/getDefaultExportFromCjs(fastSafeStringify);
466
+
467
+ function jsonStringify(val, pretty) {
468
+ return fastSafeStringify$1(val, void 0, pretty ? 2 : void 0);
469
+ }
470
+ class MemoryLogWriter {
471
+ logs = [];
472
+ write(level, attrs, msg) {
473
+ this.logs.push({
474
+ level,
475
+ ...msg ? { msg } : {},
476
+ ...attrs ? { attrs } : {}
477
+ });
478
+ }
479
+ flush() {
480
+ }
481
+ }
482
+ const asciMap = {
483
+ timestamp: "\x1B[90m",
484
+ // bright black
485
+ trace: "\x1B[36m",
486
+ // cyan
487
+ debug: "\x1B[90m",
488
+ // bright black
489
+ info: "\x1B[32m",
490
+ // green
491
+ warn: "\x1B[33m",
492
+ // yellow
493
+ error: "\x1B[41;39m",
494
+ // red; white
495
+ message: "\x1B[1m",
496
+ // bold
497
+ reset: "\x1B[0m"
498
+ // reset
499
+ };
500
+ class ConsoleLogWriter {
501
+ #nocolor = (
502
+ // no color if we're running in browser-like (edge) environments
503
+ // TODO: is this the most accurate way to detect it?
504
+ typeof process === "undefined" || // no color if https://no-color.org/
505
+ truthyEnv("NO_COLOR")
506
+ );
507
+ color(style, text) {
508
+ if (!text) {
509
+ return text;
510
+ }
511
+ if (this.#nocolor) {
512
+ return text;
513
+ }
514
+ return asciMap[style] + text + asciMap.reset;
515
+ }
516
+ write(level, attrs, msg) {
517
+ console[level === "trace" ? "debug" : level](
518
+ [
519
+ this.color("timestamp", (/* @__PURE__ */ new Date()).toISOString()),
520
+ this.color(level, logLevelToString(level)),
521
+ this.color("message", msg),
522
+ // we want to stringify because we want all properties (even nested ones)be properly displayed
523
+ attrs ? jsonStringify(attrs, truthyEnv("LOG_JSON_PRETTY")) : void 0
524
+ ].join(" ")
525
+ );
526
+ }
527
+ flush() {
528
+ }
529
+ }
530
+ class JSONLogWriter {
531
+ write(level, attrs, msg) {
532
+ console.log(
533
+ jsonStringify(
534
+ {
535
+ ...attrs,
536
+ level,
537
+ ...msg ? { msg } : {},
538
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
539
+ },
540
+ truthyEnv("LOG_JSON_PRETTY")
541
+ )
542
+ );
543
+ }
544
+ flush() {
545
+ }
546
+ }
547
+
548
+ class Logger {
549
+ #level;
550
+ #prefix;
551
+ #attrs;
552
+ #writers;
553
+ #pendingWrites = /* @__PURE__ */ new Set();
554
+ constructor(opts = {}) {
555
+ let logLevelEnv = getEnv("LOG_LEVEL");
556
+ if (logLevelEnv && !(logLevelEnv in logLevel)) {
557
+ throw new Error(
558
+ `Invalid LOG_LEVEL environment variable "${logLevelEnv}". Must be one of: ${[...Object.keys(logLevel), "false"].join(", ")}`
559
+ );
560
+ }
561
+ this.#level = opts.level ?? logLevelEnv ?? (truthyEnv("DEBUG") ? "debug" : "info");
562
+ this.#prefix = opts.prefix;
563
+ this.#attrs = opts.attrs;
564
+ this.#writers = opts.writers ?? [new ConsoleLogWriter()];
565
+ }
566
+ /** The prefix that's prepended to each log message. */
567
+ get prefix() {
568
+ return this.#prefix;
569
+ }
570
+ /**
571
+ * The attributes that are added to each log. If the log itself contains
572
+ * attributes with keys existing in {@link attrs}, the log's attributes will
573
+ * override.
574
+ */
575
+ get attrs() {
576
+ return this.#attrs;
577
+ }
578
+ /** The current {@link LogLevel} of the logger. You can change the level using the {@link setLevel} method. */
579
+ get level() {
580
+ return typeof this.#level === "function" ? this.#level() : this.#level;
581
+ }
582
+ /**
583
+ * Sets the new {@link LogLevel} of the logger. All subsequent logs, and {@link child child loggers} whose
584
+ * level did not change, will respect the new level.
585
+ */
586
+ setLevel(level) {
587
+ this.#level = level;
588
+ }
589
+ write(level, attrs, msg) {
590
+ const pendingWrites = this.#writers.map((writer) => writer.write(level, attrs, msg)).filter(isPromise);
591
+ for (const pendingWrite of pendingWrites) {
592
+ this.#pendingWrites.add(pendingWrite);
593
+ pendingWrite.catch(() => {
594
+ });
595
+ pendingWrite.finally(() => this.#pendingWrites.delete(pendingWrite));
596
+ }
597
+ }
598
+ flush() {
599
+ if (this.#pendingWrites.size) {
600
+ return Promise.all(this.#pendingWrites).then(() => {
601
+ });
602
+ }
603
+ return;
604
+ }
605
+ child(prefixOrAttrs, prefix) {
606
+ if (typeof prefixOrAttrs === "string") {
607
+ return new Logger({
608
+ level: () => this.level,
609
+ // inherits the parent level (yet can be changed on child only when using setLevel)
610
+ prefix: (this.#prefix || "") + prefixOrAttrs,
611
+ attrs: this.#attrs,
612
+ writers: this.#writers
613
+ });
614
+ }
615
+ return new Logger({
616
+ level: () => this.level,
617
+ // inherits the parent level (yet can be changed on child only when using setLevel)
618
+ prefix: (this.#prefix || "") + (prefix || "") || void 0,
619
+ attrs: { ...this.#attrs, ...prefixOrAttrs },
620
+ writers: this.#writers
621
+ });
622
+ }
623
+ log(level, maybeAttrsOrMsg, ...rest) {
624
+ if (!shouldLog(this.#level, level)) {
625
+ return;
626
+ }
627
+ let msg;
628
+ let attrs;
629
+ if (typeof maybeAttrsOrMsg === "string") {
630
+ msg = maybeAttrsOrMsg;
631
+ } else if (maybeAttrsOrMsg) {
632
+ attrs = maybeAttrsOrMsg;
633
+ if (typeof rest[0] === "string") {
634
+ msg = rest.shift();
635
+ }
636
+ }
637
+ if (this.#prefix) {
638
+ msg = `${this.#prefix}${msg || ""}`.trim();
639
+ }
640
+ attrs = attrs ? parseAttrs(attrs) : attrs;
641
+ attrs = this.#attrs ? { ...parseAttrs(this.#attrs), ...attrs } : attrs;
642
+ msg = msg ? format$1(msg, rest) : msg;
643
+ this.write(level, attrs, msg);
644
+ if (truthyEnv("LOG_TRACE_LOGS")) {
645
+ console.trace("\u{1F446}");
646
+ }
647
+ }
648
+ trace(...args) {
649
+ this.log(
650
+ "trace",
651
+ ...args
652
+ );
653
+ }
654
+ debug(...args) {
655
+ this.log(
656
+ "debug",
657
+ ...args
658
+ );
659
+ }
660
+ info(...args) {
661
+ this.log(
662
+ "info",
663
+ ...args
664
+ );
665
+ }
666
+ warn(...args) {
667
+ this.log(
668
+ "warn",
669
+ ...args
670
+ );
671
+ }
672
+ error(...args) {
673
+ this.log(
674
+ "error",
675
+ ...args
676
+ );
677
+ }
678
+ }
679
+
680
+ class LegacyLogger {
681
+ #logger;
682
+ constructor(logger) {
683
+ this.#logger = logger;
684
+ }
685
+ static from(logger) {
686
+ return new LegacyLogger(logger);
687
+ }
688
+ #log(level, ...[maybeMsgOrArg, ...restArgs]) {
689
+ if (typeof maybeMsgOrArg === "string") {
690
+ if (restArgs.length) {
691
+ this.#logger.log(level, restArgs, maybeMsgOrArg);
692
+ } else {
693
+ this.#logger.log(level, maybeMsgOrArg);
694
+ }
695
+ } else {
696
+ if (restArgs.length) {
697
+ this.#logger.log(level, [maybeMsgOrArg, ...restArgs]);
698
+ } else {
699
+ this.#logger.log(level, maybeMsgOrArg);
700
+ }
701
+ }
702
+ }
703
+ log(...args) {
704
+ this.#log("info", ...args);
705
+ }
706
+ warn(...args) {
707
+ this.#log("warn", ...args);
708
+ }
709
+ info(...args) {
710
+ this.#log("info", ...args);
711
+ }
712
+ error(...args) {
713
+ this.#log("error", ...args);
714
+ }
715
+ debug(...lazyArgs) {
716
+ if (!shouldLog(this.#logger.level, "debug")) {
717
+ return;
718
+ }
719
+ this.#log("debug", ...handleLazyMessage(lazyArgs));
720
+ }
721
+ child(name) {
722
+ name = stringifyName(name) + // append space if object is strigified to space out the prefix
723
+ (typeof name === "object" ? " " : "");
724
+ if (this.#logger.prefix === name) {
725
+ return this;
726
+ }
727
+ return LegacyLogger.from(this.#logger.child(name));
728
+ }
729
+ addPrefix(prefix) {
730
+ prefix = stringifyName(prefix);
731
+ if (this.#logger.prefix?.includes(prefix)) {
732
+ return this;
733
+ }
734
+ return LegacyLogger.from(this.#logger.child(prefix));
735
+ }
736
+ }
737
+ function stringifyName(name) {
738
+ if (typeof name === "string" || typeof name === "number") {
739
+ return `${name}`;
740
+ }
741
+ const names = [];
742
+ for (const [key, value] of Object.entries(name)) {
743
+ names.push(`${key}=${value}`);
744
+ }
745
+ return `${names.join(", ")}`;
746
+ }
747
+ function handleLazyMessage(lazyArgs) {
748
+ return lazyArgs.flat(Infinity).flatMap((arg) => {
749
+ if (typeof arg === "function") {
750
+ return arg();
751
+ }
752
+ return arg;
753
+ });
754
+ }
755
+
756
+ exports.ConsoleLogWriter = ConsoleLogWriter;
757
+ exports.JSONLogWriter = JSONLogWriter;
758
+ exports.LegacyLogger = LegacyLogger;
759
+ exports.Logger = Logger;
760
+ exports.MemoryLogWriter = MemoryLogWriter;
761
+ exports.jsonStringify = jsonStringify;