@visulima/pail 4.0.0-alpha.12 → 4.0.0-alpha.13

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