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