@visulima/pail 4.0.0-alpha.4 → 4.0.0-alpha.6

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