@visulima/pail 4.0.0-alpha.3 → 4.0.0-alpha.5

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.
Files changed (27) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/index.browser.js +1488 -2
  3. package/dist/index.server.js +2656 -12
  4. package/dist/interactive/index.js +1 -1
  5. package/dist/packem_shared/AbstractJsonReporter-DWRpTtGw.js +204 -0
  6. package/dist/packem_shared/{interactive-stream-hook-DG4BtN12.js → InteractiveStreamHook-ePIURL_U.js} +1 -9
  7. package/dist/packem_shared/{JsonReporter-VzgyLEYz.js → JsonReporter-BV5lMnJX.js} +1 -1
  8. package/dist/packem_shared/{PrettyReporter-DySIXBjQ.js → PrettyReporter-BYL3NrdA.js} +49 -4
  9. package/dist/packem_shared/{format-label-De49vNPd.js → PrettyReporter-DLQtmATi.js} +267 -2
  10. package/dist/packem_shared/Spinner-B9JUdsbY.js +2150 -0
  11. package/dist/packem_shared/abstract-pretty-reporter-DckLMlGF.js +2496 -0
  12. package/dist/packem_shared/constants-B1RjD_ps.js +99 -0
  13. package/dist/packem_shared/getBarChar-BWj1UrH3.js +404 -0
  14. package/dist/packem_shared/{index-BomQ3E6J.js → index-DnkF86LQ.js} +9 -1
  15. package/dist/processor/message-formatter-processor.js +648 -1
  16. package/dist/reporter/file/json-file-reporter.js +1 -1
  17. package/dist/reporter/http/abstract-http-reporter.js +1 -1
  18. package/dist/reporter/json/index.js +2 -2
  19. package/dist/reporter/pretty/index.browser.js +1 -1
  20. package/dist/reporter/pretty/index.js +1 -1
  21. package/dist/reporter/simple/simple-reporter.server.js +1 -6
  22. package/package.json +4 -4
  23. package/dist/packem_shared/InteractiveStreamHook-DiSubbJ1.js +0 -21
  24. package/dist/packem_shared/PrettyReporter-C2wVB7yu.js +0 -222
  25. package/dist/packem_shared/abstract-pretty-reporter-Di_sdm2r.js +0 -50
  26. package/dist/packem_shared/get-longest-label-C9PWeyKq.js +0 -9
  27. package/dist/packem_shared/pail.browser-u2CSR_af.js +0 -1427
@@ -1,7 +1,1493 @@
1
- import { P as PailBrowser } from './packem_shared/pail.browser-u2CSR_af.js';
2
- import MessageFormatterProcessor from './processor/message-formatter-processor.js';
1
+ import { a as EXTENDED_RFC_5424_LOG_LEVELS, E as EMPTY_SYMBOL, L as LOG_TYPES } from './packem_shared/constants-omsTHUWB.js';
2
+ import { w as writeConsoleLogBasedOnLevel } from './packem_shared/write-console-log-based-on-level-DBmRYXpj.js';
3
+ import { g as getLongestLabel, b as build } from './packem_shared/index-DnkF86LQ.js';
3
4
  import JsonReporter from './packem_shared/JsonReporter-BRw4skd5.js';
4
5
 
6
+ function getDefaultExportFromCjs (x) {
7
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
8
+ }
9
+
10
+ var safeStableStringify = {exports: {}};
11
+
12
+ var hasRequiredSafeStableStringify;
13
+
14
+ function requireSafeStableStringify () {
15
+ if (hasRequiredSafeStableStringify) return safeStableStringify.exports;
16
+ hasRequiredSafeStableStringify = 1;
17
+ (function (module, exports$1) {
18
+ const { hasOwnProperty } = Object.prototype;
19
+ const stringify = configure();
20
+ stringify.configure = configure;
21
+ stringify.stringify = stringify;
22
+ stringify.default = stringify;
23
+ exports$1.stringify = stringify;
24
+ exports$1.configure = configure;
25
+ module.exports = stringify;
26
+ const strEscapeSequencesRegExp = /[\u0000-\u001f\u0022\u005c\ud800-\udfff]/;
27
+ function strEscape(str) {
28
+ if (str.length < 5e3 && !strEscapeSequencesRegExp.test(str)) {
29
+ return `"${str}"`;
30
+ }
31
+ return JSON.stringify(str);
32
+ }
33
+ function sort(array, comparator) {
34
+ if (array.length > 200 || comparator) {
35
+ return array.sort(comparator);
36
+ }
37
+ for (let i = 1; i < array.length; i++) {
38
+ const currentValue = array[i];
39
+ let position = i;
40
+ while (position !== 0 && array[position - 1] > currentValue) {
41
+ array[position] = array[position - 1];
42
+ position--;
43
+ }
44
+ array[position] = currentValue;
45
+ }
46
+ return array;
47
+ }
48
+ const typedArrayPrototypeGetSymbolToStringTag = Object.getOwnPropertyDescriptor(
49
+ Object.getPrototypeOf(
50
+ Object.getPrototypeOf(
51
+ new Int8Array()
52
+ )
53
+ ),
54
+ Symbol.toStringTag
55
+ ).get;
56
+ function isTypedArrayWithEntries(value) {
57
+ return typedArrayPrototypeGetSymbolToStringTag.call(value) !== void 0 && value.length !== 0;
58
+ }
59
+ function stringifyTypedArray(array, separator, maximumBreadth) {
60
+ if (array.length < maximumBreadth) {
61
+ maximumBreadth = array.length;
62
+ }
63
+ const whitespace = separator === "," ? "" : " ";
64
+ let res = `"0":${whitespace}${array[0]}`;
65
+ for (let i = 1; i < maximumBreadth; i++) {
66
+ res += `${separator}"${i}":${whitespace}${array[i]}`;
67
+ }
68
+ return res;
69
+ }
70
+ function getCircularValueOption(options) {
71
+ if (hasOwnProperty.call(options, "circularValue")) {
72
+ const circularValue = options.circularValue;
73
+ if (typeof circularValue === "string") {
74
+ return `"${circularValue}"`;
75
+ }
76
+ if (circularValue == null) {
77
+ return circularValue;
78
+ }
79
+ if (circularValue === Error || circularValue === TypeError) {
80
+ return {
81
+ toString() {
82
+ throw new TypeError("Converting circular structure to JSON");
83
+ }
84
+ };
85
+ }
86
+ throw new TypeError('The "circularValue" argument must be of type string or the value null or undefined');
87
+ }
88
+ return '"[Circular]"';
89
+ }
90
+ function getDeterministicOption(options) {
91
+ let value;
92
+ if (hasOwnProperty.call(options, "deterministic")) {
93
+ value = options.deterministic;
94
+ if (typeof value !== "boolean" && typeof value !== "function") {
95
+ throw new TypeError('The "deterministic" argument must be of type boolean or comparator function');
96
+ }
97
+ }
98
+ return value === void 0 ? true : value;
99
+ }
100
+ function getBooleanOption(options, key) {
101
+ let value;
102
+ if (hasOwnProperty.call(options, key)) {
103
+ value = options[key];
104
+ if (typeof value !== "boolean") {
105
+ throw new TypeError(`The "${key}" argument must be of type boolean`);
106
+ }
107
+ }
108
+ return value === void 0 ? true : value;
109
+ }
110
+ function getPositiveIntegerOption(options, key) {
111
+ let value;
112
+ if (hasOwnProperty.call(options, key)) {
113
+ value = options[key];
114
+ if (typeof value !== "number") {
115
+ throw new TypeError(`The "${key}" argument must be of type number`);
116
+ }
117
+ if (!Number.isInteger(value)) {
118
+ throw new TypeError(`The "${key}" argument must be an integer`);
119
+ }
120
+ if (value < 1) {
121
+ throw new RangeError(`The "${key}" argument must be >= 1`);
122
+ }
123
+ }
124
+ return value === void 0 ? Infinity : value;
125
+ }
126
+ function getItemCount(number) {
127
+ if (number === 1) {
128
+ return "1 item";
129
+ }
130
+ return `${number} items`;
131
+ }
132
+ function getUniqueReplacerSet(replacerArray) {
133
+ const replacerSet = /* @__PURE__ */ new Set();
134
+ for (const value of replacerArray) {
135
+ if (typeof value === "string" || typeof value === "number") {
136
+ replacerSet.add(String(value));
137
+ }
138
+ }
139
+ return replacerSet;
140
+ }
141
+ function getStrictOption(options) {
142
+ if (hasOwnProperty.call(options, "strict")) {
143
+ const value = options.strict;
144
+ if (typeof value !== "boolean") {
145
+ throw new TypeError('The "strict" argument must be of type boolean');
146
+ }
147
+ if (value) {
148
+ return (value2) => {
149
+ let message = `Object can not safely be stringified. Received type ${typeof value2}`;
150
+ if (typeof value2 !== "function") message += ` (${value2.toString()})`;
151
+ throw new Error(message);
152
+ };
153
+ }
154
+ }
155
+ }
156
+ function configure(options) {
157
+ options = { ...options };
158
+ const fail = getStrictOption(options);
159
+ if (fail) {
160
+ if (options.bigint === void 0) {
161
+ options.bigint = false;
162
+ }
163
+ if (!("circularValue" in options)) {
164
+ options.circularValue = Error;
165
+ }
166
+ }
167
+ const circularValue = getCircularValueOption(options);
168
+ const bigint = getBooleanOption(options, "bigint");
169
+ const deterministic = getDeterministicOption(options);
170
+ const comparator = typeof deterministic === "function" ? deterministic : void 0;
171
+ const maximumDepth = getPositiveIntegerOption(options, "maximumDepth");
172
+ const maximumBreadth = getPositiveIntegerOption(options, "maximumBreadth");
173
+ function stringifyFnReplacer(key, parent, stack, replacer, spacer, indentation) {
174
+ let value = parent[key];
175
+ if (typeof value === "object" && value !== null && typeof value.toJSON === "function") {
176
+ value = value.toJSON(key);
177
+ }
178
+ value = replacer.call(parent, key, value);
179
+ switch (typeof value) {
180
+ case "string":
181
+ return strEscape(value);
182
+ case "object": {
183
+ if (value === null) {
184
+ return "null";
185
+ }
186
+ if (stack.indexOf(value) !== -1) {
187
+ return circularValue;
188
+ }
189
+ let res = "";
190
+ let join = ",";
191
+ const originalIndentation = indentation;
192
+ if (Array.isArray(value)) {
193
+ if (value.length === 0) {
194
+ return "[]";
195
+ }
196
+ if (maximumDepth < stack.length + 1) {
197
+ return '"[Array]"';
198
+ }
199
+ stack.push(value);
200
+ if (spacer !== "") {
201
+ indentation += spacer;
202
+ res += `
203
+ ${indentation}`;
204
+ join = `,
205
+ ${indentation}`;
206
+ }
207
+ const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
208
+ let i = 0;
209
+ for (; i < maximumValuesToStringify - 1; i++) {
210
+ const tmp2 = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
211
+ res += tmp2 !== void 0 ? tmp2 : "null";
212
+ res += join;
213
+ }
214
+ const tmp = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
215
+ res += tmp !== void 0 ? tmp : "null";
216
+ if (value.length - 1 > maximumBreadth) {
217
+ const removedKeys = value.length - maximumBreadth - 1;
218
+ res += `${join}"... ${getItemCount(removedKeys)} not stringified"`;
219
+ }
220
+ if (spacer !== "") {
221
+ res += `
222
+ ${originalIndentation}`;
223
+ }
224
+ stack.pop();
225
+ return `[${res}]`;
226
+ }
227
+ let keys = Object.keys(value);
228
+ const keyLength = keys.length;
229
+ if (keyLength === 0) {
230
+ return "{}";
231
+ }
232
+ if (maximumDepth < stack.length + 1) {
233
+ return '"[Object]"';
234
+ }
235
+ let whitespace = "";
236
+ let separator = "";
237
+ if (spacer !== "") {
238
+ indentation += spacer;
239
+ join = `,
240
+ ${indentation}`;
241
+ whitespace = " ";
242
+ }
243
+ const maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
244
+ if (deterministic && !isTypedArrayWithEntries(value)) {
245
+ keys = sort(keys, comparator);
246
+ }
247
+ stack.push(value);
248
+ for (let i = 0; i < maximumPropertiesToStringify; i++) {
249
+ const key2 = keys[i];
250
+ const tmp = stringifyFnReplacer(key2, value, stack, replacer, spacer, indentation);
251
+ if (tmp !== void 0) {
252
+ res += `${separator}${strEscape(key2)}:${whitespace}${tmp}`;
253
+ separator = join;
254
+ }
255
+ }
256
+ if (keyLength > maximumBreadth) {
257
+ const removedKeys = keyLength - maximumBreadth;
258
+ res += `${separator}"...":${whitespace}"${getItemCount(removedKeys)} not stringified"`;
259
+ separator = join;
260
+ }
261
+ if (spacer !== "" && separator.length > 1) {
262
+ res = `
263
+ ${indentation}${res}
264
+ ${originalIndentation}`;
265
+ }
266
+ stack.pop();
267
+ return `{${res}}`;
268
+ }
269
+ case "number":
270
+ return isFinite(value) ? String(value) : fail ? fail(value) : "null";
271
+ case "boolean":
272
+ return value === true ? "true" : "false";
273
+ case "undefined":
274
+ return void 0;
275
+ case "bigint":
276
+ if (bigint) {
277
+ return String(value);
278
+ }
279
+ // fallthrough
280
+ default:
281
+ return fail ? fail(value) : void 0;
282
+ }
283
+ }
284
+ function stringifyArrayReplacer(key, value, stack, replacer, spacer, indentation) {
285
+ if (typeof value === "object" && value !== null && typeof value.toJSON === "function") {
286
+ value = value.toJSON(key);
287
+ }
288
+ switch (typeof value) {
289
+ case "string":
290
+ return strEscape(value);
291
+ case "object": {
292
+ if (value === null) {
293
+ return "null";
294
+ }
295
+ if (stack.indexOf(value) !== -1) {
296
+ return circularValue;
297
+ }
298
+ const originalIndentation = indentation;
299
+ let res = "";
300
+ let join = ",";
301
+ if (Array.isArray(value)) {
302
+ if (value.length === 0) {
303
+ return "[]";
304
+ }
305
+ if (maximumDepth < stack.length + 1) {
306
+ return '"[Array]"';
307
+ }
308
+ stack.push(value);
309
+ if (spacer !== "") {
310
+ indentation += spacer;
311
+ res += `
312
+ ${indentation}`;
313
+ join = `,
314
+ ${indentation}`;
315
+ }
316
+ const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
317
+ let i = 0;
318
+ for (; i < maximumValuesToStringify - 1; i++) {
319
+ const tmp2 = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
320
+ res += tmp2 !== void 0 ? tmp2 : "null";
321
+ res += join;
322
+ }
323
+ const tmp = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
324
+ res += tmp !== void 0 ? tmp : "null";
325
+ if (value.length - 1 > maximumBreadth) {
326
+ const removedKeys = value.length - maximumBreadth - 1;
327
+ res += `${join}"... ${getItemCount(removedKeys)} not stringified"`;
328
+ }
329
+ if (spacer !== "") {
330
+ res += `
331
+ ${originalIndentation}`;
332
+ }
333
+ stack.pop();
334
+ return `[${res}]`;
335
+ }
336
+ stack.push(value);
337
+ let whitespace = "";
338
+ if (spacer !== "") {
339
+ indentation += spacer;
340
+ join = `,
341
+ ${indentation}`;
342
+ whitespace = " ";
343
+ }
344
+ let separator = "";
345
+ for (const key2 of replacer) {
346
+ const tmp = stringifyArrayReplacer(key2, value[key2], stack, replacer, spacer, indentation);
347
+ if (tmp !== void 0) {
348
+ res += `${separator}${strEscape(key2)}:${whitespace}${tmp}`;
349
+ separator = join;
350
+ }
351
+ }
352
+ if (spacer !== "" && separator.length > 1) {
353
+ res = `
354
+ ${indentation}${res}
355
+ ${originalIndentation}`;
356
+ }
357
+ stack.pop();
358
+ return `{${res}}`;
359
+ }
360
+ case "number":
361
+ return isFinite(value) ? String(value) : fail ? fail(value) : "null";
362
+ case "boolean":
363
+ return value === true ? "true" : "false";
364
+ case "undefined":
365
+ return void 0;
366
+ case "bigint":
367
+ if (bigint) {
368
+ return String(value);
369
+ }
370
+ // fallthrough
371
+ default:
372
+ return fail ? fail(value) : void 0;
373
+ }
374
+ }
375
+ function stringifyIndent(key, value, stack, spacer, indentation) {
376
+ switch (typeof value) {
377
+ case "string":
378
+ return strEscape(value);
379
+ case "object": {
380
+ if (value === null) {
381
+ return "null";
382
+ }
383
+ if (typeof value.toJSON === "function") {
384
+ value = value.toJSON(key);
385
+ if (typeof value !== "object") {
386
+ return stringifyIndent(key, value, stack, spacer, indentation);
387
+ }
388
+ if (value === null) {
389
+ return "null";
390
+ }
391
+ }
392
+ if (stack.indexOf(value) !== -1) {
393
+ return circularValue;
394
+ }
395
+ const originalIndentation = indentation;
396
+ if (Array.isArray(value)) {
397
+ if (value.length === 0) {
398
+ return "[]";
399
+ }
400
+ if (maximumDepth < stack.length + 1) {
401
+ return '"[Array]"';
402
+ }
403
+ stack.push(value);
404
+ indentation += spacer;
405
+ let res2 = `
406
+ ${indentation}`;
407
+ const join2 = `,
408
+ ${indentation}`;
409
+ const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
410
+ let i = 0;
411
+ for (; i < maximumValuesToStringify - 1; i++) {
412
+ const tmp2 = stringifyIndent(String(i), value[i], stack, spacer, indentation);
413
+ res2 += tmp2 !== void 0 ? tmp2 : "null";
414
+ res2 += join2;
415
+ }
416
+ const tmp = stringifyIndent(String(i), value[i], stack, spacer, indentation);
417
+ res2 += tmp !== void 0 ? tmp : "null";
418
+ if (value.length - 1 > maximumBreadth) {
419
+ const removedKeys = value.length - maximumBreadth - 1;
420
+ res2 += `${join2}"... ${getItemCount(removedKeys)} not stringified"`;
421
+ }
422
+ res2 += `
423
+ ${originalIndentation}`;
424
+ stack.pop();
425
+ return `[${res2}]`;
426
+ }
427
+ let keys = Object.keys(value);
428
+ const keyLength = keys.length;
429
+ if (keyLength === 0) {
430
+ return "{}";
431
+ }
432
+ if (maximumDepth < stack.length + 1) {
433
+ return '"[Object]"';
434
+ }
435
+ indentation += spacer;
436
+ const join = `,
437
+ ${indentation}`;
438
+ let res = "";
439
+ let separator = "";
440
+ let maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
441
+ if (isTypedArrayWithEntries(value)) {
442
+ res += stringifyTypedArray(value, join, maximumBreadth);
443
+ keys = keys.slice(value.length);
444
+ maximumPropertiesToStringify -= value.length;
445
+ separator = join;
446
+ }
447
+ if (deterministic) {
448
+ keys = sort(keys, comparator);
449
+ }
450
+ stack.push(value);
451
+ for (let i = 0; i < maximumPropertiesToStringify; i++) {
452
+ const key2 = keys[i];
453
+ const tmp = stringifyIndent(key2, value[key2], stack, spacer, indentation);
454
+ if (tmp !== void 0) {
455
+ res += `${separator}${strEscape(key2)}: ${tmp}`;
456
+ separator = join;
457
+ }
458
+ }
459
+ if (keyLength > maximumBreadth) {
460
+ const removedKeys = keyLength - maximumBreadth;
461
+ res += `${separator}"...": "${getItemCount(removedKeys)} not stringified"`;
462
+ separator = join;
463
+ }
464
+ if (separator !== "") {
465
+ res = `
466
+ ${indentation}${res}
467
+ ${originalIndentation}`;
468
+ }
469
+ stack.pop();
470
+ return `{${res}}`;
471
+ }
472
+ case "number":
473
+ return isFinite(value) ? String(value) : fail ? fail(value) : "null";
474
+ case "boolean":
475
+ return value === true ? "true" : "false";
476
+ case "undefined":
477
+ return void 0;
478
+ case "bigint":
479
+ if (bigint) {
480
+ return String(value);
481
+ }
482
+ // fallthrough
483
+ default:
484
+ return fail ? fail(value) : void 0;
485
+ }
486
+ }
487
+ function stringifySimple(key, value, stack) {
488
+ switch (typeof value) {
489
+ case "string":
490
+ return strEscape(value);
491
+ case "object": {
492
+ if (value === null) {
493
+ return "null";
494
+ }
495
+ if (typeof value.toJSON === "function") {
496
+ value = value.toJSON(key);
497
+ if (typeof value !== "object") {
498
+ return stringifySimple(key, value, stack);
499
+ }
500
+ if (value === null) {
501
+ return "null";
502
+ }
503
+ }
504
+ if (stack.indexOf(value) !== -1) {
505
+ return circularValue;
506
+ }
507
+ let res = "";
508
+ const hasLength = value.length !== void 0;
509
+ if (hasLength && Array.isArray(value)) {
510
+ if (value.length === 0) {
511
+ return "[]";
512
+ }
513
+ if (maximumDepth < stack.length + 1) {
514
+ return '"[Array]"';
515
+ }
516
+ stack.push(value);
517
+ const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
518
+ let i = 0;
519
+ for (; i < maximumValuesToStringify - 1; i++) {
520
+ const tmp2 = stringifySimple(String(i), value[i], stack);
521
+ res += tmp2 !== void 0 ? tmp2 : "null";
522
+ res += ",";
523
+ }
524
+ const tmp = stringifySimple(String(i), value[i], stack);
525
+ res += tmp !== void 0 ? tmp : "null";
526
+ if (value.length - 1 > maximumBreadth) {
527
+ const removedKeys = value.length - maximumBreadth - 1;
528
+ res += `,"... ${getItemCount(removedKeys)} not stringified"`;
529
+ }
530
+ stack.pop();
531
+ return `[${res}]`;
532
+ }
533
+ let keys = Object.keys(value);
534
+ const keyLength = keys.length;
535
+ if (keyLength === 0) {
536
+ return "{}";
537
+ }
538
+ if (maximumDepth < stack.length + 1) {
539
+ return '"[Object]"';
540
+ }
541
+ let separator = "";
542
+ let maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
543
+ if (hasLength && isTypedArrayWithEntries(value)) {
544
+ res += stringifyTypedArray(value, ",", maximumBreadth);
545
+ keys = keys.slice(value.length);
546
+ maximumPropertiesToStringify -= value.length;
547
+ separator = ",";
548
+ }
549
+ if (deterministic) {
550
+ keys = sort(keys, comparator);
551
+ }
552
+ stack.push(value);
553
+ for (let i = 0; i < maximumPropertiesToStringify; i++) {
554
+ const key2 = keys[i];
555
+ const tmp = stringifySimple(key2, value[key2], stack);
556
+ if (tmp !== void 0) {
557
+ res += `${separator}${strEscape(key2)}:${tmp}`;
558
+ separator = ",";
559
+ }
560
+ }
561
+ if (keyLength > maximumBreadth) {
562
+ const removedKeys = keyLength - maximumBreadth;
563
+ res += `${separator}"...":"${getItemCount(removedKeys)} not stringified"`;
564
+ }
565
+ stack.pop();
566
+ return `{${res}}`;
567
+ }
568
+ case "number":
569
+ return isFinite(value) ? String(value) : fail ? fail(value) : "null";
570
+ case "boolean":
571
+ return value === true ? "true" : "false";
572
+ case "undefined":
573
+ return void 0;
574
+ case "bigint":
575
+ if (bigint) {
576
+ return String(value);
577
+ }
578
+ // fallthrough
579
+ default:
580
+ return fail ? fail(value) : void 0;
581
+ }
582
+ }
583
+ function stringify2(value, replacer, space) {
584
+ if (arguments.length > 1) {
585
+ let spacer = "";
586
+ if (typeof space === "number") {
587
+ spacer = " ".repeat(Math.min(space, 10));
588
+ } else if (typeof space === "string") {
589
+ spacer = space.slice(0, 10);
590
+ }
591
+ if (replacer != null) {
592
+ if (typeof replacer === "function") {
593
+ return stringifyFnReplacer("", { "": value }, [], replacer, spacer, "");
594
+ }
595
+ if (Array.isArray(replacer)) {
596
+ return stringifyArrayReplacer("", value, [], getUniqueReplacerSet(replacer), spacer, "");
597
+ }
598
+ }
599
+ if (spacer.length !== 0) {
600
+ return stringifyIndent("", value, [], spacer, "");
601
+ }
602
+ }
603
+ return stringifySimple("", value, []);
604
+ }
605
+ return stringify2;
606
+ }
607
+ } (safeStableStringify, safeStableStringify.exports));
608
+ return safeStableStringify.exports;
609
+ }
610
+
611
+ var safeStableStringifyExports = requireSafeStableStringify();
612
+ const cjsModule = /*@__PURE__*/getDefaultExportFromCjs(safeStableStringifyExports);
613
+
614
+ const configure = cjsModule.configure;
615
+
616
+ class RawReporter {
617
+ // eslint-disable-next-line class-methods-use-this
618
+ log(meta) {
619
+ const { context = [], message, type } = meta;
620
+ const consoleLogFunction = writeConsoleLogBasedOnLevel(type.level);
621
+ consoleLogFunction(message, ...context);
622
+ }
623
+ }
624
+
625
+ const arrayify = (x) => {
626
+ if (x === void 0) {
627
+ return [];
628
+ }
629
+ return Array.isArray(x) ? x : [x];
630
+ };
631
+
632
+ const mergeTypes = (standard, custom) => {
633
+ const types = { ...standard };
634
+ Object.keys(custom).forEach((type) => {
635
+ types[type] = { ...types[type], ...custom[type] };
636
+ });
637
+ return types;
638
+ };
639
+
640
+ const preventLoop = (function_) => {
641
+ let doing = false;
642
+ return function(...args) {
643
+ if (doing) {
644
+ return void 0;
645
+ }
646
+ doing = true;
647
+ try {
648
+ const result = function_.apply(this, args);
649
+ doing = false;
650
+ return result;
651
+ } catch (error) {
652
+ doing = false;
653
+ throw error;
654
+ }
655
+ };
656
+ };
657
+ class PailBrowserImpl {
658
+ timersMap;
659
+ countMap;
660
+ seqTimers;
661
+ lastLog;
662
+ logLevels;
663
+ disabled;
664
+ paused;
665
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
666
+ messageQueue;
667
+ scopeName;
668
+ types;
669
+ longestLabel;
670
+ processors;
671
+ generalLogLevel;
672
+ reporters;
673
+ throttle;
674
+ throttleMin;
675
+ stringify;
676
+ groups;
677
+ startTimerMessage;
678
+ endTimerMessage;
679
+ rawReporter;
680
+ force = {};
681
+ /**
682
+ * Creates a new Pail browser logger instance.
683
+ *
684
+ * Initializes the logger with the provided configuration options,
685
+ * setting up reporters, processors, log levels, and other internal state.
686
+ * @param options Configuration options for the logger
687
+ */
688
+ constructor(options) {
689
+ this.throttle = options.throttle ?? 1e3;
690
+ this.throttleMin = options.throttleMin ?? 5;
691
+ const parentLongestLabel = options.parentLongestLabel;
692
+ const parentTypes = options.parentTypes;
693
+ const parentStringify = options.parentStringify;
694
+ const parentLogLevels = options.parentLogLevels;
695
+ this.stringify = parentStringify ?? configure({
696
+ strict: true
697
+ });
698
+ this.startTimerMessage = options.messages?.timerStart ?? "Initialized timer...";
699
+ this.endTimerMessage = options.messages?.timerEnd ?? "Timer run for:";
700
+ if (parentTypes && parentLongestLabel) {
701
+ this.types = parentTypes;
702
+ this.longestLabel = parentLongestLabel;
703
+ } else {
704
+ this.types = mergeTypes(LOG_TYPES, options.types ?? {});
705
+ this.longestLabel = getLongestLabel(this.types);
706
+ }
707
+ this.logLevels = parentLogLevels && !options.logLevels ? parentLogLevels : { ...EXTENDED_RFC_5424_LOG_LEVELS, ...options.logLevels };
708
+ this.generalLogLevel = this.#normalizeLogLevel(options.logLevel);
709
+ this.reporters = /* @__PURE__ */ new Set();
710
+ this.processors = /* @__PURE__ */ new Set();
711
+ this.disabled = options.disabled ?? false;
712
+ this.paused = false;
713
+ this.messageQueue = [];
714
+ this.scopeName = arrayify(options.scope).filter(Boolean);
715
+ this.timersMap = /* @__PURE__ */ new Map();
716
+ this.countMap = /* @__PURE__ */ new Map();
717
+ this.groups = [];
718
+ this.seqTimers = /* @__PURE__ */ new Set();
719
+ this.lastLog = {};
720
+ this.logger = preventLoop(this.logger).bind(this);
721
+ this.#initializeBoundMethods();
722
+ if (Array.isArray(options.reporters)) {
723
+ this.registerReporters(options.reporters);
724
+ }
725
+ this.rawReporter = this.extendReporter(options.rawReporter ?? new RawReporter());
726
+ if (Array.isArray(options.processors)) {
727
+ this.registerProcessors(options.processors);
728
+ }
729
+ }
730
+ /**
731
+ * Initializes bound methods for all logger types.
732
+ *
733
+ * Creates bound methods for both regular and force logging methods.
734
+ * This is separated to allow reuse when types haven't changed.
735
+ */
736
+ #initializeBoundMethods() {
737
+ for (const type in this.types) {
738
+ this[type] = this.logger.bind(this, type, false, false);
739
+ }
740
+ for (const type in this.types) {
741
+ this.force[type] = this.logger.bind(this, type, false, true);
742
+ }
743
+ }
744
+ /**
745
+ * Wraps the global console methods to redirect them through the logger.
746
+ *
747
+ * This method replaces console methods (log, info, warn, error, etc.) with
748
+ * calls to the corresponding logger methods. The original console methods
749
+ * are backed up and can be restored using restoreConsole().
750
+ * @example
751
+ * ```typescript
752
+ * const logger = createPail();
753
+ * logger.wrapConsole();
754
+ *
755
+ * console.log("This will go through the logger");
756
+ * console.error("This too!");
757
+ *
758
+ * logger.restoreConsole(); // Restore original console methods
759
+ * ```
760
+ */
761
+ wrapConsole() {
762
+ for (const type in this.types) {
763
+ if (!console[`__${type}`]) {
764
+ console[`__${type}`] = console[type];
765
+ }
766
+ console[type] = this[type];
767
+ }
768
+ }
769
+ /**
770
+ * Restores the original global console methods.
771
+ *
772
+ * This method restores the console methods that were backed up by wrapConsole().
773
+ * After calling this, console methods will work as they did before wrapping.
774
+ * @example
775
+ * ```typescript
776
+ * const logger = createPail();
777
+ * logger.wrapConsole();
778
+ *
779
+ * // Console methods are now wrapped
780
+ * logger.restoreConsole();
781
+ * // Console methods are restored to original behavior
782
+ * ```
783
+ */
784
+ restoreConsole() {
785
+ for (const type in this.types) {
786
+ if (console[`__${type}`]) {
787
+ console[type] = console[`__${type}`];
788
+ delete console[`__${type}`];
789
+ }
790
+ }
791
+ }
792
+ /**
793
+ * Wraps uncaught exception and unhandled rejection handlers.
794
+ *
795
+ * This method sets up global error handlers that will log uncaught exceptions
796
+ * and unhandled promise rejections through the logger. This is useful for
797
+ * capturing and logging application crashes.
798
+ * @example
799
+ * ```typescript
800
+ * const logger = createPail();
801
+ * logger.wrapException();
802
+ *
803
+ * // Now uncaught errors will be logged
804
+ * throw new Error("This will be logged");
805
+ * ```
806
+ */
807
+ wrapException() {
808
+ {
809
+ process.on("uncaughtException", (error) => {
810
+ this.error(error);
811
+ });
812
+ process.on("unhandledRejection", (error) => {
813
+ this.error(error);
814
+ });
815
+ }
816
+ }
817
+ /**
818
+ * Disables all logging output.
819
+ *
820
+ * When disabled, all log calls will be silently ignored and no output
821
+ * will be produced by any reporters. This can be useful for temporarily
822
+ * suppressing log output in production or during testing.
823
+ * @example
824
+ * ```typescript
825
+ * const logger = createPail();
826
+ * logger.disable();
827
+ * logger.info("This won't be logged"); // Silent
828
+ * logger.enable();
829
+ * logger.info("This will be logged"); // Output produced
830
+ * ```
831
+ */
832
+ disable() {
833
+ this.disabled = true;
834
+ }
835
+ /**
836
+ * Enables logging output.
837
+ *
838
+ * Re-enables logging after it has been disabled. All subsequent log calls
839
+ * will produce output according to the configured reporters.
840
+ * @example
841
+ * ```typescript
842
+ * const logger = createPail();
843
+ * logger.disable();
844
+ * logger.info("This won't be logged");
845
+ * logger.enable(); // Re-enable logging
846
+ * logger.info("This will be logged");
847
+ * ```
848
+ */
849
+ enable() {
850
+ this.disabled = false;
851
+ }
852
+ /**
853
+ * Checks if logging is currently enabled.
854
+ *
855
+ * Returns true if logging is enabled and false if it has been disabled.
856
+ * @returns True if logging is enabled, false if disabled
857
+ * @example
858
+ * ```typescript
859
+ * const logger = createPail();
860
+ * console.log(logger.isEnabled()); // true
861
+ * logger.disable();
862
+ * console.log(logger.isEnabled()); // false
863
+ * ```
864
+ */
865
+ isEnabled() {
866
+ return !this.disabled;
867
+ }
868
+ /**
869
+ * Pauses logging and starts queuing messages.
870
+ *
871
+ * When paused, all log calls will be queued instead of being output immediately.
872
+ * The queued messages will be processed when resume() is called. This is useful
873
+ * for temporarily buffering log output during critical operations.
874
+ * @example
875
+ * ```typescript
876
+ * const logger = createPail();
877
+ * logger.pause();
878
+ * logger.info("This will be queued"); // Queued, not output yet
879
+ * logger.warn("This too"); // Also queued
880
+ * logger.resume(); // Now both messages are output
881
+ * ```
882
+ */
883
+ pause() {
884
+ this.paused = true;
885
+ }
886
+ /**
887
+ * Resumes logging and flushes all queued messages.
888
+ *
889
+ * Processes all messages that were queued during the pause period and
890
+ * resumes normal logging behavior. Messages are output in the order
891
+ * they were originally called.
892
+ * @example
893
+ * ```typescript
894
+ * const logger = createPail();
895
+ * logger.pause();
896
+ * logger.info("Message 1"); // Queued
897
+ * logger.info("Message 2"); // Queued
898
+ * logger.resume(); // Both messages are now output in order
899
+ * logger.info("Message 3"); // Output immediately
900
+ * ```
901
+ */
902
+ resume() {
903
+ this.paused = false;
904
+ const queue = this.messageQueue.splice(0);
905
+ for (const { messageObject, raw, type } of queue) {
906
+ this.logger(type, raw, false, ...messageObject);
907
+ }
908
+ }
909
+ /**
910
+ * Creates a scoped logger instance.
911
+ *
912
+ * Returns a new logger instance that inherits all configuration but adds
913
+ * the specified scope names to all log messages. This is useful for
914
+ * categorizing logs by component, module, or feature.
915
+ * @template N - The new custom logger type names
916
+ * @param name Scope names to apply to all log messages
917
+ * @returns A new scoped logger instance
918
+ * @throws {Error} If no scope name is provided
919
+ * @example
920
+ * ```typescript
921
+ * const logger = createPail();
922
+ * const scopedLogger = logger.scope("auth", "login");
923
+ * scopedLogger.info("User logged in"); // Will include scope: ["auth", "login"]
924
+ * ```
925
+ */
926
+ scope(...name) {
927
+ if (name.length === 0) {
928
+ throw new Error("No scope name was defined.");
929
+ }
930
+ this.scopeName = name.flat();
931
+ return this;
932
+ }
933
+ /**
934
+ * Removes the current scope from the logger.
935
+ *
936
+ * Clears all scope names that were set by previous scope() calls.
937
+ * After calling this, log messages will no longer include scope information.
938
+ * @example
939
+ * ```typescript
940
+ * const logger = createPail();
941
+ * const scopedLogger = logger.scope("auth");
942
+ * scopedLogger.info("Scoped message"); // Has scope
943
+ * scopedLogger.unscope();
944
+ * scopedLogger.info("Unscoped message"); // No scope
945
+ * ```
946
+ */
947
+ unscope() {
948
+ this.scopeName = [];
949
+ }
950
+ /**
951
+ * Creates a child logger that inherits settings from the parent.
952
+ *
953
+ * Returns a new logger instance that inherits all configuration from the parent
954
+ * (reporters, processors, types, log levels, throttle settings, etc.) while allowing
955
+ * you to override only what you need. Child loggers are independent instances with
956
+ * their own state (timers, counters, etc.).
957
+ * @template N - The new custom logger type names
958
+ * @template LC - The new log level types
959
+ * @param options Configuration options to override or extend parent settings
960
+ * @returns A new child logger instance
961
+ * @example
962
+ * ```typescript
963
+ * const parent = createPail({
964
+ * logLevel: "info",
965
+ * types: { http: { label: "HTTP", logLevel: "info" } },
966
+ * reporters: [new PrettyReporter()],
967
+ * });
968
+ *
969
+ * // Child inherits parent settings but overrides log level
970
+ * const child = parent.child({ logLevel: "debug" });
971
+ * child.info("This will be logged"); // Uses debug level from child
972
+ * child.http("GET /api 200"); // Inherits http type from parent
973
+ *
974
+ * // Child can add new types
975
+ * const childWithNewType = parent.child({
976
+ * types: { db: { label: "DB", logLevel: "info" } },
977
+ * });
978
+ * childWithNewType.db("Query executed"); // New type available
979
+ * ```
980
+ */
981
+ // eslint-disable-next-line sonarjs/cognitive-complexity
982
+ child(options) {
983
+ const typesChanged = options?.types !== void 0 && options.types !== null;
984
+ const mergedTypes = typesChanged ? mergeTypes(this.types, options.types) : this.types;
985
+ const childReporters = options?.reporters ?? [];
986
+ const allReporters = childReporters.length > 0 ? [...this.reporters, ...childReporters] : [...this.reporters];
987
+ const childProcessors = options?.processors ?? [];
988
+ const allProcessors = childProcessors.length > 0 ? [...this.processors, ...childProcessors] : [...this.processors];
989
+ const mergedLogLevels = options?.logLevels ? { ...this.logLevels, ...options.logLevels } : this.logLevels;
990
+ let mergedScope;
991
+ if (options?.scope) {
992
+ const childScope = arrayify(options.scope).filter(Boolean);
993
+ mergedScope = this.scopeName.length > 0 ? [...this.scopeName, ...childScope] : childScope;
994
+ } else {
995
+ mergedScope = this.scopeName.length > 0 ? this.scopeName : [];
996
+ }
997
+ const mergedMessages = options?.messages ? {
998
+ timerEnd: this.endTimerMessage,
999
+ timerStart: this.startTimerMessage,
1000
+ ...options.messages
1001
+ } : {
1002
+ timerEnd: this.endTimerMessage,
1003
+ timerStart: this.startTimerMessage
1004
+ };
1005
+ const childOptions = {
1006
+ disabled: options?.disabled ?? this.disabled,
1007
+ logLevel: options?.logLevel ?? this.generalLogLevel,
1008
+ logLevels: mergedLogLevels,
1009
+ messages: mergedMessages,
1010
+ processors: allProcessors,
1011
+ rawReporter: options?.rawReporter ?? this.rawReporter,
1012
+ reporters: allReporters,
1013
+ scope: mergedScope,
1014
+ throttle: options?.throttle ?? this.throttle,
1015
+ throttleMin: options?.throttleMin ?? this.throttleMin
1016
+ };
1017
+ if (typesChanged) {
1018
+ childOptions.parentTypes = mergedTypes;
1019
+ childOptions.parentLongestLabel = getLongestLabel(mergedTypes);
1020
+ } else {
1021
+ childOptions.parentTypes = this.types;
1022
+ childOptions.parentLongestLabel = this.longestLabel;
1023
+ }
1024
+ if (!options?.logLevels) {
1025
+ childOptions.parentLogLevels = this.logLevels;
1026
+ }
1027
+ if (!options?.messages) {
1028
+ childOptions.parentMessages = {
1029
+ timerEnd: this.endTimerMessage,
1030
+ timerStart: this.startTimerMessage
1031
+ };
1032
+ }
1033
+ childOptions.parentStringify = this.stringify;
1034
+ return new PailBrowserImpl(childOptions);
1035
+ }
1036
+ /**
1037
+ * Starts a timer with the specified label.
1038
+ *
1039
+ * Records the current timestamp and associates it with the given label.
1040
+ * Multiple timers can be active simultaneously with different labels.
1041
+ * @param label The timer label (defaults to "default")
1042
+ * @example
1043
+ * ```typescript
1044
+ * const logger = createPail();
1045
+ * logger.time("operation");
1046
+ * // ... some operation ...
1047
+ * logger.timeEnd("operation"); // Logs: "Timer run for: X ms"
1048
+ * ```
1049
+ */
1050
+ time(label = "default") {
1051
+ if (this.seqTimers.has(label)) {
1052
+ this.logger("warn", false, false, {
1053
+ message: `Timer '${label}' already exists`,
1054
+ prefix: label
1055
+ });
1056
+ } else {
1057
+ this.seqTimers.add(label);
1058
+ this.timersMap.set(label, Date.now());
1059
+ this.logger("start", false, false, {
1060
+ message: this.startTimerMessage,
1061
+ prefix: label
1062
+ });
1063
+ }
1064
+ }
1065
+ /**
1066
+ * Logs the current elapsed time for a timer without stopping it.
1067
+ *
1068
+ * Calculates and logs the time elapsed since the timer was started,
1069
+ * but keeps the timer running. If no label is provided, uses the
1070
+ * most recently started timer.
1071
+ * @param label The timer label (uses last timer if not specified)
1072
+ * @param data Additional data to include in the log message
1073
+ * @example
1074
+ * ```typescript
1075
+ * const logger = createPail();
1076
+ * logger.time("task");
1077
+ * // ... some work ...
1078
+ * logger.timeLog("task"); // Logs current elapsed time
1079
+ * // ... more work ...
1080
+ * logger.timeEnd("task"); // Logs final time and stops timer
1081
+ * ```
1082
+ */
1083
+ timeLog(label, ...data) {
1084
+ if (!label && this.seqTimers.size > 0) {
1085
+ label = [...this.seqTimers].pop();
1086
+ }
1087
+ if (label && this.timersMap.has(label)) {
1088
+ const span = Date.now() - this.timersMap.get(label);
1089
+ this.logger("info", false, false, {
1090
+ context: data,
1091
+ message: span < 1e3 ? `${span} ms` : `${(span / 1e3).toFixed(2)} s`,
1092
+ prefix: label
1093
+ });
1094
+ } else {
1095
+ this.logger("warn", false, false, {
1096
+ context: data,
1097
+ message: "Timer not found",
1098
+ prefix: label
1099
+ });
1100
+ }
1101
+ }
1102
+ /**
1103
+ * Stops a timer and logs the final elapsed time.
1104
+ *
1105
+ * Calculates the total time elapsed since the timer was started,
1106
+ * logs the result, and removes the timer. If no label is provided,
1107
+ * uses the most recently started timer.
1108
+ * @param label The timer label (uses last timer if not specified)
1109
+ * @example
1110
+ * ```typescript
1111
+ * const logger = createPail();
1112
+ * logger.time("operation");
1113
+ * // ... perform operation ...
1114
+ * logger.timeEnd("operation"); // Logs: "Timer run for: X ms"
1115
+ * ```
1116
+ */
1117
+ timeEnd(label) {
1118
+ if (!label && this.seqTimers.size > 0) {
1119
+ label = [...this.seqTimers].pop();
1120
+ }
1121
+ if (label && this.timersMap.has(label)) {
1122
+ const span = Date.now() - this.timersMap.get(label);
1123
+ this.timersMap.delete(label);
1124
+ this.logger("stop", false, false, {
1125
+ message: `${this.endTimerMessage} ${span < 1e3 ? `${span} ms` : `${(span / 1e3).toFixed(2)} s`}`,
1126
+ prefix: label
1127
+ });
1128
+ } else {
1129
+ this.logger("warn", false, false, {
1130
+ message: "Timer not found",
1131
+ prefix: label
1132
+ });
1133
+ }
1134
+ }
1135
+ /**
1136
+ * Starts a log group with the specified label.
1137
+ *
1138
+ * Groups related log messages together. In browser environments,
1139
+ * this uses the native console.group() functionality. In other
1140
+ * environments, it tracks group nesting internally.
1141
+ * @param label The group label (defaults to "console.group")
1142
+ * @example
1143
+ * ```typescript
1144
+ * const logger = createPail();
1145
+ * logger.group("Database Operations");
1146
+ * logger.info("Connecting to database");
1147
+ * logger.info("Running migration");
1148
+ * logger.groupEnd(); // End the group
1149
+ * ```
1150
+ */
1151
+ group(label = "console.group") {
1152
+ if (globalThis.window === void 0) {
1153
+ this.groups.push(label);
1154
+ } else {
1155
+ console.group(label);
1156
+ }
1157
+ }
1158
+ /**
1159
+ * Ends the current log group.
1160
+ *
1161
+ * Closes the most recently opened log group. In browser environments,
1162
+ * this uses the native console.groupEnd() functionality.
1163
+ * @example
1164
+ * ```typescript
1165
+ * const logger = createPail();
1166
+ * logger.group("Processing");
1167
+ * logger.info("Step 1");
1168
+ * logger.info("Step 2");
1169
+ * logger.groupEnd(); // Closes the "Processing" group
1170
+ * ```
1171
+ */
1172
+ groupEnd() {
1173
+ if (globalThis.window === void 0) {
1174
+ this.groups.pop();
1175
+ } else {
1176
+ console.groupEnd();
1177
+ }
1178
+ }
1179
+ /**
1180
+ * Increments and logs a counter with the specified label.
1181
+ *
1182
+ * Maintains an internal counter for each label and logs the current count
1183
+ * each time it's called. Useful for tracking how many times certain
1184
+ * code paths are executed.
1185
+ * @param label The counter label (defaults to "default")
1186
+ * @example
1187
+ * ```typescript
1188
+ * const logger = createPail();
1189
+ * logger.count("requests"); // Logs: "requests: 1"
1190
+ * logger.count("requests"); // Logs: "requests: 2"
1191
+ * logger.count("errors"); // Logs: "errors: 1"
1192
+ * ```
1193
+ */
1194
+ count(label = "default") {
1195
+ const current = this.countMap.get(label) ?? 0;
1196
+ this.countMap.set(label, current + 1);
1197
+ this.logger("log", false, false, {
1198
+ message: `${label}: ${current + 1}`,
1199
+ prefix: label
1200
+ });
1201
+ }
1202
+ /**
1203
+ * Resets a counter to zero.
1204
+ *
1205
+ * Removes the counter with the specified label, effectively resetting
1206
+ * it to zero. If the counter doesn't exist, logs a warning.
1207
+ * @param label The counter label to reset (defaults to "default")
1208
+ * @example
1209
+ * ```typescript
1210
+ * const logger = createPail();
1211
+ * logger.count("requests"); // Logs: "requests: 1"
1212
+ * logger.countReset("requests"); // Resets counter
1213
+ * logger.count("requests"); // Logs: "requests: 1" (starts over)
1214
+ * ```
1215
+ */
1216
+ countReset(label = "default") {
1217
+ if (this.countMap.has(label)) {
1218
+ this.countMap.delete(label);
1219
+ } else {
1220
+ this.logger("warn", false, false, {
1221
+ message: `Count for ${label} does not exist`,
1222
+ prefix: label
1223
+ });
1224
+ }
1225
+ }
1226
+ /**
1227
+ * Clears the console output.
1228
+ *
1229
+ * Calls the native console.clear() method to clear all output from
1230
+ * the console. This is a convenience method that wraps the native
1231
+ * console.clear() functionality.
1232
+ * @example
1233
+ * ```typescript
1234
+ * const logger = createPail();
1235
+ * logger.info("Some message");
1236
+ * logger.clear(); // Clears the console
1237
+ * ```
1238
+ */
1239
+ // eslint-disable-next-line class-methods-use-this
1240
+ clear() {
1241
+ console.clear();
1242
+ }
1243
+ /**
1244
+ * Logs a raw message bypassing normal processing.
1245
+ *
1246
+ * Sends a message directly to the raw reporter without going through
1247
+ * the normal logging pipeline (processors, throttling, etc.). This is
1248
+ * useful for logging that needs to bypass all formatting and processing.
1249
+ * @param message The raw message to log
1250
+ * @param arguments_ Additional arguments to include
1251
+ * @example
1252
+ * ```typescript
1253
+ * const logger = createPail();
1254
+ * logger.raw("Direct message", { data: "value" });
1255
+ * ```
1256
+ */
1257
+ raw(message, ...arguments_) {
1258
+ if (this.disabled) {
1259
+ return;
1260
+ }
1261
+ this.logger("log", true, false, {
1262
+ context: arguments_,
1263
+ message
1264
+ });
1265
+ }
1266
+ extendReporter(reporter) {
1267
+ if (typeof reporter.setLoggerTypes === "function") {
1268
+ reporter.setLoggerTypes(this.types);
1269
+ }
1270
+ if (typeof reporter.setStringify === "function") {
1271
+ reporter.setStringify(this.stringify);
1272
+ }
1273
+ return reporter;
1274
+ }
1275
+ registerReporters(reporters) {
1276
+ for (const reporter of reporters) {
1277
+ this.reporters.add(this.extendReporter(reporter));
1278
+ }
1279
+ }
1280
+ registerProcessors(processors) {
1281
+ for (const processor of processors) {
1282
+ if (typeof processor.setStringify === "function") {
1283
+ processor.setStringify(this.stringify);
1284
+ }
1285
+ this.processors.add(processor);
1286
+ }
1287
+ }
1288
+ #report(meta, raw) {
1289
+ if (raw) {
1290
+ this.rawReporter.log(Object.freeze(meta));
1291
+ } else {
1292
+ for (const reporter of this.reporters) {
1293
+ reporter.log(Object.freeze(meta));
1294
+ }
1295
+ }
1296
+ }
1297
+ #normalizeLogLevel(level) {
1298
+ return level && this.logLevels[level] ? level : "debug";
1299
+ }
1300
+ // eslint-disable-next-line sonarjs/cognitive-complexity
1301
+ #buildMeta(typeName, type, ...arguments_) {
1302
+ const meta = {
1303
+ badge: void 0,
1304
+ context: void 0,
1305
+ error: void 0,
1306
+ label: void 0,
1307
+ message: EMPTY_SYMBOL,
1308
+ prefix: void 0,
1309
+ repeated: void 0,
1310
+ scope: void 0,
1311
+ suffix: void 0
1312
+ };
1313
+ meta.type = {
1314
+ level: type.logLevel,
1315
+ name: typeName
1316
+ };
1317
+ meta.groups = this.groups;
1318
+ meta.scope = this.scopeName;
1319
+ meta.date = /* @__PURE__ */ new Date();
1320
+ if (arguments_.length > 0 && arguments_[0] instanceof Error) {
1321
+ meta.error = arguments_[0];
1322
+ if (arguments_.length > 1) {
1323
+ meta.context = arguments_.slice(1);
1324
+ }
1325
+ } else if (arguments_.length > 0 && typeof arguments_[0] === "object" && arguments_[0] !== null && "message" in arguments_[0]) {
1326
+ const { context, message, prefix, suffix } = arguments_[0];
1327
+ if (context) {
1328
+ meta.context = context;
1329
+ }
1330
+ if (prefix) {
1331
+ meta.prefix = prefix;
1332
+ }
1333
+ if (suffix) {
1334
+ meta.suffix = suffix;
1335
+ }
1336
+ meta.message = message;
1337
+ if (arguments_.length > 1) {
1338
+ const additionalContext = arguments_.slice(1);
1339
+ if (meta.context) {
1340
+ meta.context = Array.isArray(meta.context) ? [...meta.context, ...additionalContext] : [meta.context, ...additionalContext];
1341
+ } else {
1342
+ meta.context = additionalContext;
1343
+ }
1344
+ }
1345
+ } else if (arguments_.length > 1) {
1346
+ meta.message = arguments_[0];
1347
+ meta.context = arguments_.slice(1);
1348
+ } else if (arguments_.length === 1) {
1349
+ meta.message = arguments_[0];
1350
+ } else {
1351
+ meta.message = void 0;
1352
+ }
1353
+ if (type.logLevel === "trace") {
1354
+ meta.traceError = new Error("Trace");
1355
+ }
1356
+ if (type.badge) {
1357
+ meta.badge = type.badge;
1358
+ }
1359
+ if (type.label) {
1360
+ meta.label = type.label;
1361
+ }
1362
+ return meta;
1363
+ }
1364
+ // eslint-disable-next-line sonarjs/cognitive-complexity
1365
+ logger(type, raw, force, ...messageObject) {
1366
+ if (this.disabled) {
1367
+ return;
1368
+ }
1369
+ if (this.paused) {
1370
+ this.messageQueue.push({ messageObject, raw, type });
1371
+ return;
1372
+ }
1373
+ const typeConfig = this.types[type];
1374
+ if (!typeConfig) {
1375
+ return;
1376
+ }
1377
+ const logLevel = this.#normalizeLogLevel(typeConfig.logLevel);
1378
+ if (force || this.logLevels[logLevel] >= this.logLevels[this.generalLogLevel]) {
1379
+ let meta = this.#buildMeta(type, typeConfig, ...messageObject);
1380
+ const resolveLog = (newLog = false) => {
1381
+ const repeated = (this.lastLog.count || 0) - this.throttleMin;
1382
+ if (this.lastLog.object && repeated > 0) {
1383
+ const lastMeta = { ...this.lastLog.object };
1384
+ if (repeated > 1) {
1385
+ lastMeta.repeated = repeated;
1386
+ }
1387
+ this.#report(lastMeta, raw);
1388
+ this.lastLog.count = 1;
1389
+ }
1390
+ if (newLog) {
1391
+ for (const processor of this.processors) {
1392
+ meta = { ...processor.process(meta) };
1393
+ }
1394
+ this.lastLog.object = meta;
1395
+ this.#report(meta, raw);
1396
+ }
1397
+ };
1398
+ clearTimeout(this.lastLog.timeout);
1399
+ const diffTime = this.lastLog.time && meta.date ? new Date(meta.date).getTime() - this.lastLog.time.getTime() : 0;
1400
+ this.lastLog.time = new Date(meta.date);
1401
+ if (diffTime < this.throttle) {
1402
+ try {
1403
+ const isSameLog = this.lastLog.object && JSON.stringify([meta.label, meta.scope, meta.type, meta.message, meta.prefix, meta.suffix, meta.context]) === JSON.stringify([
1404
+ this.lastLog.object.label,
1405
+ this.lastLog.object.scope,
1406
+ this.lastLog.object.type,
1407
+ this.lastLog.object.message,
1408
+ this.lastLog.object.prefix,
1409
+ this.lastLog.object.suffix,
1410
+ this.lastLog.object.context
1411
+ ]);
1412
+ if (isSameLog) {
1413
+ this.lastLog.count = (this.lastLog.count || 0) + 1;
1414
+ if (this.lastLog.count > this.throttleMin) {
1415
+ this.lastLog.timeout = setTimeout(resolveLog, this.throttle);
1416
+ return;
1417
+ }
1418
+ }
1419
+ } catch {
1420
+ }
1421
+ }
1422
+ resolveLog(true);
1423
+ }
1424
+ }
1425
+ }
1426
+ const PailBrowser = PailBrowserImpl;
1427
+
1428
+ class MessageFormatterProcessor {
1429
+ /** Custom stringify function for object serialization */
1430
+ #stringify;
1431
+ /** Custom formatters for message interpolation */
1432
+ #formatters;
1433
+ /**
1434
+ * Creates a new MessageFormatterProcessor instance.
1435
+ * @param options Configuration options
1436
+ * @param options.formatters Custom formatters for message interpolation
1437
+ */
1438
+ constructor(options = {}) {
1439
+ this.#formatters = options.formatters;
1440
+ }
1441
+ /**
1442
+ * Sets the stringify function for object serialization.
1443
+ * @param function_ The stringify function to use for serializing objects
1444
+ */
1445
+ setStringify(function_) {
1446
+ this.#stringify = function_;
1447
+ }
1448
+ /**
1449
+ * Processes log metadata to format messages.
1450
+ *
1451
+ * Applies string interpolation and custom formatters to the message
1452
+ * and contextual data in the log metadata.
1453
+ * @param meta The log metadata to process
1454
+ * @returns The processed metadata with formatted messages
1455
+ */
1456
+ process(meta) {
1457
+ const formatter = build({
1458
+ formatters: this.#formatters});
1459
+ if (meta.message !== void 0) {
1460
+ meta.message = this.#format(formatter, meta.message, meta.context ?? []);
1461
+ }
1462
+ return meta;
1463
+ }
1464
+ /**
1465
+ * Recursively formats data using the formatter.
1466
+ *
1467
+ * Applies string interpolation and formatting to strings, arrays, and objects.
1468
+ * @param formatter The formatter function to use
1469
+ * @param data The data to format (string, array, or object)
1470
+ * @param arguments_ Additional arguments for formatting
1471
+ * @returns The formatted data
1472
+ * @private
1473
+ */
1474
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1475
+ #format(formatter, data, arguments_ = []) {
1476
+ if (typeof data === "string") {
1477
+ return formatter(data, arguments_);
1478
+ }
1479
+ if (typeof data === "object" && data !== null) {
1480
+ for (const index in data) {
1481
+ const value = data[index];
1482
+ if (typeof value === "string" || Array.isArray(value) || typeof value === "object") {
1483
+ data[index] = this.#format(formatter, value, arguments_);
1484
+ }
1485
+ }
1486
+ }
1487
+ return data;
1488
+ }
1489
+ }
1490
+
5
1491
  const createPail = (options) => new PailBrowser({
6
1492
  processors: [new MessageFormatterProcessor()],
7
1493
  reporters: [new JsonReporter()],