@visulima/pail 2.1.27 → 2.1.29

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 (82) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/index.browser.cjs +1 -19
  3. package/dist/index.browser.mjs +1 -14
  4. package/dist/index.server.cjs +5 -442
  5. package/dist/index.server.mjs +5 -437
  6. package/dist/packem_shared/CallerProcessor-DJnmMPMj.cjs +1 -0
  7. package/dist/packem_shared/CallerProcessor-mNkBei3j.mjs +1 -0
  8. package/dist/packem_shared/JsonFileReporter-BnxuhH4o.cjs +2 -0
  9. package/dist/packem_shared/JsonFileReporter-Og8hyKfg.mjs +4 -0
  10. package/dist/packem_shared/JsonReporter-BdExg5gk.mjs +1 -0
  11. package/dist/packem_shared/JsonReporter-CjvkrXUp.cjs +1 -0
  12. package/dist/packem_shared/JsonReporter-DRGJgjAO.mjs +2 -0
  13. package/dist/packem_shared/JsonReporter-DuF0Ho5i.cjs +2 -0
  14. package/dist/packem_shared/MessageFormatterProcessor-BjBZzL2D.mjs +1 -0
  15. package/dist/packem_shared/MessageFormatterProcessor-CCRIUIdT.cjs +1 -0
  16. package/dist/packem_shared/PrettyReporter-BRFlkORc.mjs +5 -0
  17. package/dist/packem_shared/PrettyReporter-BuKPqA5T.cjs +5 -0
  18. package/dist/packem_shared/PrettyReporter-DDsX0vlT.mjs +13 -0
  19. package/dist/packem_shared/PrettyReporter-Dx1OfdGj.cjs +13 -0
  20. package/dist/packem_shared/RedactProcessor-BBJysXaX.cjs +1 -0
  21. package/dist/packem_shared/RedactProcessor-CxKTN42V.mjs +3 -0
  22. package/dist/packem_shared/SimpleReporter-BV0taliz.mjs +11 -0
  23. package/dist/packem_shared/SimpleReporter-YuzZZabX.cjs +11 -0
  24. package/dist/packem_shared/abstract-json-reporter-Z6bVrpPK.cjs +1 -0
  25. package/dist/packem_shared/abstract-json-reporter-tFmKAzRZ.mjs +1 -0
  26. package/dist/packem_shared/abstract-pretty-reporter-C2vDqWAQ.cjs +1 -0
  27. package/dist/packem_shared/abstract-pretty-reporter-CRcf4WZd.mjs +1 -0
  28. package/dist/packem_shared/constants-BFrKdBPm.cjs +1 -0
  29. package/dist/packem_shared/constants-BMS51p6Y.mjs +1 -0
  30. package/dist/packem_shared/format-label-CKRxcWAQ.cjs +8 -0
  31. package/dist/packem_shared/format-label-D2xt_3df.mjs +8 -0
  32. package/dist/packem_shared/get-longest-label-7LkwzzHo.cjs +1 -0
  33. package/dist/packem_shared/get-longest-label-B0NrI-o2.mjs +1 -0
  34. package/dist/packem_shared/pail.browser-DC6QwLTj.cjs +1 -0
  35. package/dist/packem_shared/pail.browser-DkNIDzgk.mjs +1 -0
  36. package/dist/packem_shared/write-console-log-3G15muTS.cjs +1 -0
  37. package/dist/packem_shared/write-console-log-BP95fgQZ.mjs +1 -0
  38. package/dist/packem_shared/write-stream-CD8XFv1L.mjs +1 -0
  39. package/dist/packem_shared/write-stream-Dl-usQqh.cjs +1 -0
  40. package/dist/processor.browser.cjs +1 -11
  41. package/dist/processor.browser.mjs +1 -2
  42. package/dist/processor.server.cjs +1 -13
  43. package/dist/processor.server.mjs +1 -3
  44. package/dist/reporter.browser.cjs +1 -11
  45. package/dist/reporter.browser.mjs +1 -2
  46. package/dist/reporter.server.cjs +1 -15
  47. package/dist/reporter.server.mjs +1 -4
  48. package/package.json +2 -2
  49. package/dist/packem_shared/CallerProcessor-CNhuyGAa.mjs +0 -58
  50. package/dist/packem_shared/CallerProcessor-DJ5euiUK.cjs +0 -60
  51. package/dist/packem_shared/JsonFileReporter-BazAMbEI.mjs +0 -133
  52. package/dist/packem_shared/JsonFileReporter-PNmBNTr1.cjs +0 -135
  53. package/dist/packem_shared/JsonReporter-CKWF4Ibl.mjs +0 -20
  54. package/dist/packem_shared/JsonReporter-CcOVaf3A.cjs +0 -34
  55. package/dist/packem_shared/JsonReporter-Cg5R1FXn.cjs +0 -22
  56. package/dist/packem_shared/JsonReporter-DFFyVZyh.mjs +0 -32
  57. package/dist/packem_shared/MessageFormatterProcessor-Cd4HntPG.mjs +0 -53
  58. package/dist/packem_shared/MessageFormatterProcessor-t4t6CpzV.cjs +0 -55
  59. package/dist/packem_shared/PrettyReporter-3oMWkX6j.cjs +0 -200
  60. package/dist/packem_shared/PrettyReporter-Bx3QLZrW.mjs +0 -162
  61. package/dist/packem_shared/PrettyReporter-C2hjNe-y.mjs +0 -192
  62. package/dist/packem_shared/PrettyReporter-mFCjMb0i.cjs +0 -168
  63. package/dist/packem_shared/RedactProcessor-CfNkF2lC.mjs +0 -26
  64. package/dist/packem_shared/RedactProcessor-DWE5iqAQ.cjs +0 -26
  65. package/dist/packem_shared/SimpleReporter-CXXqr1h3.cjs +0 -186
  66. package/dist/packem_shared/SimpleReporter-TOcMSqJb.mjs +0 -178
  67. package/dist/packem_shared/abstract-json-reporter-okwLqT9k.cjs +0 -57
  68. package/dist/packem_shared/abstract-json-reporter-sxnmNIlg.mjs +0 -55
  69. package/dist/packem_shared/abstract-pretty-reporter-BR_6_JVa.cjs +0 -49
  70. package/dist/packem_shared/abstract-pretty-reporter-izJgxoMv.mjs +0 -46
  71. package/dist/packem_shared/constants-BYYZ5WNW.mjs +0 -114
  72. package/dist/packem_shared/constants-DHfYGxxG.cjs +0 -118
  73. package/dist/packem_shared/format-label-DYEhjrTZ.cjs +0 -621
  74. package/dist/packem_shared/format-label-Uj-cxY3j.mjs +0 -609
  75. package/dist/packem_shared/get-longest-label-CM8kLFWH.mjs +0 -11
  76. package/dist/packem_shared/get-longest-label-CQ7lRhgD.cjs +0 -13
  77. package/dist/packem_shared/pail.browser-Bp1fz428.mjs +0 -384
  78. package/dist/packem_shared/pail.browser-O53Q_cus.cjs +0 -387
  79. package/dist/packem_shared/write-console-log-Cu0-IDN-.cjs +0 -18
  80. package/dist/packem_shared/write-console-log-Tptfzg9D.mjs +0 -16
  81. package/dist/packem_shared/write-stream-BBAF33Zm.mjs +0 -8
  82. package/dist/packem_shared/write-stream-CkNf2Ju8.cjs +0 -10
@@ -1,387 +0,0 @@
1
- 'use strict';
2
-
3
- const safeStableStringify = require('safe-stable-stringify');
4
- const constants = require('./constants-DHfYGxxG.cjs');
5
- const writeConsoleLog = require('./write-console-log-Cu0-IDN-.cjs');
6
- const getLongestLabel = require('./get-longest-label-CQ7lRhgD.cjs');
7
-
8
- var __defProp$3 = Object.defineProperty;
9
- var __name$3 = (target, value) => __defProp$3(target, "name", { value, configurable: true });
10
- class RawReporter {
11
- static {
12
- __name$3(this, "RawReporter");
13
- }
14
- // eslint-disable-next-line class-methods-use-this
15
- log(meta) {
16
- const { context = [], message, type } = meta;
17
- const consoleLogFunction = writeConsoleLog.writeConsoleLogBasedOnLevel(type.level);
18
- consoleLogFunction(message, ...context);
19
- }
20
- }
21
-
22
- var __defProp$2 = Object.defineProperty;
23
- var __name$2 = (target, value) => __defProp$2(target, "name", { value, configurable: true });
24
- const arrayify = /* @__PURE__ */ __name$2((x) => {
25
- if (x === void 0) {
26
- return [];
27
- }
28
- return Array.isArray(x) ? x : [x];
29
- }, "arrayify");
30
-
31
- var __defProp$1 = Object.defineProperty;
32
- var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
33
- const mergeTypes = /* @__PURE__ */ __name$1((standard, custom) => {
34
- const types = { ...standard };
35
- Object.keys(custom).forEach((type) => {
36
- types[type] = { ...types[type], ...custom[type] };
37
- });
38
- return types;
39
- }, "mergeTypes");
40
-
41
- var __defProp = Object.defineProperty;
42
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
43
- class PailBrowserImpl {
44
- static {
45
- __name(this, "PailBrowserImpl");
46
- }
47
- timersMap;
48
- countMap;
49
- seqTimers;
50
- lastLog;
51
- logLevels;
52
- disabled;
53
- scopeName;
54
- types;
55
- longestLabel;
56
- processors;
57
- generalLogLevel;
58
- reporters;
59
- throttle;
60
- throttleMin;
61
- stringify;
62
- groups;
63
- startTimerMessage;
64
- endTimerMessage;
65
- rawReporter;
66
- constructor(options) {
67
- this.throttle = options.throttle ?? 1e3;
68
- this.throttleMin = options.throttleMin ?? 5;
69
- this.stringify = safeStableStringify.configure({
70
- strict: true
71
- });
72
- this.startTimerMessage = options.messages?.timerStart ?? "Initialized timer...";
73
- this.endTimerMessage = options.messages?.timerEnd ?? "Timer run for:";
74
- this.types = mergeTypes(constants.LOG_TYPES, options.types ?? {});
75
- this.longestLabel = getLongestLabel.getLongestLabel(this.types);
76
- this.logLevels = { ...constants.EXTENDED_RFC_5424_LOG_LEVELS, ...options.logLevels };
77
- this.generalLogLevel = this._normalizeLogLevel(options.logLevel);
78
- this.reporters = /* @__PURE__ */ new Set();
79
- this.processors = /* @__PURE__ */ new Set();
80
- this.disabled = options.disabled ?? false;
81
- this.scopeName = arrayify(options.scope).filter(Boolean);
82
- this.timersMap = /* @__PURE__ */ new Map();
83
- this.countMap = /* @__PURE__ */ new Map();
84
- this.groups = [];
85
- this.seqTimers = /* @__PURE__ */ new Set();
86
- for (const type in this.types) {
87
- this[type] = this._logger.bind(this, type, false);
88
- }
89
- this.lastLog = {};
90
- if (Array.isArray(options.reporters)) {
91
- this.registerReporters(options.reporters);
92
- }
93
- this.rawReporter = this.extendReporter(options.rawReporter ?? new RawReporter());
94
- if (Array.isArray(options.processors)) {
95
- this.registerProcessors(options.processors);
96
- }
97
- }
98
- wrapConsole() {
99
- for (const type in this.types) {
100
- if (!console["__" + type]) {
101
- console["__" + type] = console[type];
102
- }
103
- console[type] = this[type];
104
- }
105
- }
106
- restoreConsole() {
107
- for (const type in this.types) {
108
- if (console["__" + type]) {
109
- console[type] = console["__" + type];
110
- delete console["__" + type];
111
- }
112
- }
113
- }
114
- wrapException() {
115
- {
116
- process.on("uncaughtException", (error) => {
117
- this.error(error);
118
- });
119
- process.on("unhandledRejection", (error) => {
120
- this.error(error);
121
- });
122
- }
123
- }
124
- /**
125
- * Disables logging
126
- */
127
- disable() {
128
- this.disabled = true;
129
- }
130
- /**
131
- * Enables logging
132
- */
133
- enable() {
134
- this.disabled = false;
135
- }
136
- isEnabled() {
137
- return !this.disabled;
138
- }
139
- scope(...name) {
140
- if (name.length === 0) {
141
- throw new Error("No scope name was defined.");
142
- }
143
- this.scopeName = name.flat();
144
- return this;
145
- }
146
- unscope() {
147
- this.scopeName = [];
148
- }
149
- time(label = "default") {
150
- if (this.seqTimers.has(label)) {
151
- this._logger("warn", false, {
152
- message: "Timer '" + label + "' already exists",
153
- prefix: label
154
- });
155
- } else {
156
- this.seqTimers.add(label);
157
- this.timersMap.set(label, Date.now());
158
- this._logger("start", false, {
159
- message: this.startTimerMessage,
160
- prefix: label
161
- });
162
- }
163
- }
164
- timeLog(label, ...data) {
165
- if (!label && this.seqTimers.size > 0) {
166
- label = [...this.seqTimers].pop();
167
- }
168
- if (label && this.timersMap.has(label)) {
169
- const span = Date.now() - this.timersMap.get(label);
170
- this._logger("info", false, {
171
- context: data,
172
- message: span < 1e3 ? span + " ms" : (span / 1e3).toFixed(2) + " s",
173
- prefix: label
174
- });
175
- } else {
176
- this._logger("warn", false, {
177
- context: data,
178
- message: "Timer not found",
179
- prefix: label
180
- });
181
- }
182
- }
183
- timeEnd(label) {
184
- if (!label && this.seqTimers.size > 0) {
185
- label = [...this.seqTimers].pop();
186
- }
187
- if (label && this.timersMap.has(label)) {
188
- const span = Date.now() - this.timersMap.get(label);
189
- this.timersMap.delete(label);
190
- this._logger("stop", false, {
191
- message: this.endTimerMessage + " " + (span < 1e3 ? span + " ms" : (span / 1e3).toFixed(2) + " s"),
192
- prefix: label
193
- });
194
- } else {
195
- this._logger("warn", false, {
196
- message: "Timer not found",
197
- prefix: label
198
- });
199
- }
200
- }
201
- group(label = "console.group") {
202
- if (typeof window === "undefined") {
203
- this.groups.push(label);
204
- } else {
205
- console.group(label);
206
- }
207
- }
208
- groupEnd() {
209
- if (typeof window === "undefined") {
210
- this.groups.pop();
211
- } else {
212
- console.groupEnd();
213
- }
214
- }
215
- count(label = "default") {
216
- const current = this.countMap.get(label) ?? 0;
217
- this.countMap.set(label, current + 1);
218
- this._logger("log", false, {
219
- message: label + ": " + (current + 1),
220
- prefix: label
221
- });
222
- }
223
- countReset(label = "default") {
224
- if (this.countMap.has(label)) {
225
- this.countMap.delete(label);
226
- } else {
227
- this._logger("warn", false, {
228
- message: "Count for " + label + " does not exist",
229
- prefix: label
230
- });
231
- }
232
- }
233
- // eslint-disable-next-line class-methods-use-this
234
- clear() {
235
- console.clear();
236
- }
237
- raw(message, ...arguments_) {
238
- if (this.disabled) {
239
- return;
240
- }
241
- this._logger("log", true, {
242
- context: arguments_,
243
- message
244
- });
245
- }
246
- extendReporter(reporter) {
247
- if (typeof reporter.setLoggerTypes === "function") {
248
- reporter.setLoggerTypes(this.types);
249
- }
250
- if (typeof reporter.setStringify === "function") {
251
- reporter.setStringify(this.stringify);
252
- }
253
- return reporter;
254
- }
255
- registerReporters(reporters) {
256
- for (const reporter of reporters) {
257
- this.reporters.add(this.extendReporter(reporter));
258
- }
259
- }
260
- _report(meta, raw) {
261
- if (raw) {
262
- this.rawReporter.log(Object.freeze(meta));
263
- } else {
264
- for (const reporter of this.reporters) {
265
- reporter.log(Object.freeze(meta));
266
- }
267
- }
268
- }
269
- registerProcessors(processors) {
270
- for (const processor of processors) {
271
- if (typeof processor.setStringify === "function") {
272
- processor.setStringify(this.stringify);
273
- }
274
- this.processors.add(processor);
275
- }
276
- }
277
- // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents
278
- _normalizeLogLevel(level) {
279
- return level && this.logLevels[level] ? level : "debug";
280
- }
281
- // eslint-disable-next-line sonarjs/cognitive-complexity,@typescript-eslint/no-explicit-any
282
- _buildMeta(typeName, type, ...arguments_) {
283
- const meta = {
284
- badge: void 0,
285
- context: void 0,
286
- error: void 0,
287
- label: void 0,
288
- message: constants.EMPTY_SYMBOL,
289
- prefix: void 0,
290
- repeated: void 0,
291
- scope: void 0,
292
- suffix: void 0
293
- };
294
- meta.type = {
295
- level: type.logLevel,
296
- name: typeName
297
- };
298
- meta.groups = this.groups;
299
- meta.scope = this.scopeName;
300
- meta.date = /* @__PURE__ */ new Date();
301
- if (arguments_.length === 1 && typeof arguments_[0] === "object" && arguments_[0] !== null) {
302
- if (arguments_[0] instanceof Error) {
303
- meta.error = arguments_[0];
304
- } else if ("message" in arguments_[0]) {
305
- const { context, message, prefix, suffix } = arguments_[0];
306
- if (context) {
307
- meta.context = context;
308
- }
309
- if (prefix) {
310
- meta.prefix = prefix;
311
- }
312
- if (suffix) {
313
- meta.suffix = suffix;
314
- }
315
- meta.message = message;
316
- } else {
317
- meta.message = arguments_[0];
318
- }
319
- } else if (arguments_.length > 1 && typeof arguments_[0] === "string") {
320
- meta.message = arguments_[0];
321
- meta.context = arguments_.slice(1);
322
- } else {
323
- meta.message = arguments_[0];
324
- }
325
- if (type.logLevel === "trace") {
326
- meta.traceError = new Error("Trace");
327
- }
328
- if (type.badge) {
329
- meta.badge = type.badge;
330
- }
331
- if (type.label) {
332
- meta.label = type.label;
333
- }
334
- return meta;
335
- }
336
- // eslint-disable-next-line sonarjs/cognitive-complexity,@typescript-eslint/no-explicit-any
337
- _logger(type, raw, ...messageObject) {
338
- if (this.disabled) {
339
- return;
340
- }
341
- const logLevel = this._normalizeLogLevel(this.types[type].logLevel);
342
- if (this.logLevels[logLevel] >= this.logLevels[this.generalLogLevel]) {
343
- let meta = this._buildMeta(type, this.types[type], ...messageObject);
344
- const resolveLog = /* @__PURE__ */ __name((newLog = false) => {
345
- const repeated = (this.lastLog.count || 0) - this.throttleMin;
346
- if (this.lastLog.object && repeated > 0) {
347
- const lastMeta = { ...this.lastLog.object };
348
- if (repeated > 1) {
349
- lastMeta.repeated = repeated;
350
- }
351
- this._report(lastMeta, raw);
352
- this.lastLog.count = 1;
353
- }
354
- if (newLog) {
355
- for (const processor of this.processors) {
356
- meta = { ...processor.process(meta) };
357
- }
358
- this.lastLog.object = meta;
359
- this._report(meta, raw);
360
- }
361
- }, "resolveLog");
362
- clearTimeout(this.lastLog.timeout);
363
- const diffTime = this.lastLog.time && meta.date ? new Date(meta.date).getTime() - this.lastLog.time.getTime() : 0;
364
- this.lastLog.time = new Date(meta.date);
365
- if (diffTime < this.throttle) {
366
- try {
367
- const serializedLog = JSON.stringify([meta.label, meta.scope, meta.type, meta.message, meta.prefix, meta.suffix, meta.context]);
368
- const isSameLog = this.lastLog.serialized === serializedLog;
369
- this.lastLog.serialized = serializedLog;
370
- if (isSameLog) {
371
- this.lastLog.count = (this.lastLog.count || 0) + 1;
372
- if (this.lastLog.count > this.throttleMin) {
373
- this.lastLog.timeout = setTimeout(resolveLog, this.throttle);
374
- return;
375
- }
376
- }
377
- } catch {
378
- }
379
- }
380
- resolveLog(true);
381
- }
382
- }
383
- }
384
- const PailBrowser = PailBrowserImpl;
385
-
386
- exports.PailBrowser = PailBrowser;
387
- exports.PailBrowserImpl = PailBrowserImpl;
@@ -1,18 +0,0 @@
1
- 'use strict';
2
-
3
- var __defProp = Object.defineProperty;
4
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
- const writeConsoleLogBasedOnLevel = /* @__PURE__ */ __name((level) => {
6
- if (level === "error") {
7
- return console.__error ?? console.error;
8
- }
9
- if (level === "warn") {
10
- return console.__warn ?? console.warn;
11
- }
12
- if (level === "trace") {
13
- return console.__trace ?? console.trace;
14
- }
15
- return console.__log ?? console.log;
16
- }, "writeConsoleLogBasedOnLevel");
17
-
18
- exports.writeConsoleLogBasedOnLevel = writeConsoleLogBasedOnLevel;
@@ -1,16 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
- const writeConsoleLogBasedOnLevel = /* @__PURE__ */ __name((level) => {
4
- if (level === "error") {
5
- return console.__error ?? console.error;
6
- }
7
- if (level === "warn") {
8
- return console.__warn ?? console.warn;
9
- }
10
- if (level === "trace") {
11
- return console.__trace ?? console.trace;
12
- }
13
- return console.__log ?? console.log;
14
- }, "writeConsoleLogBasedOnLevel");
15
-
16
- export { writeConsoleLogBasedOnLevel as w };
@@ -1,8 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
- const writeStream = /* @__PURE__ */ __name((data, stream) => {
4
- const write = stream.__write ?? stream.write;
5
- return write.call(stream, data);
6
- }, "writeStream");
7
-
8
- export { writeStream as w };
@@ -1,10 +0,0 @@
1
- 'use strict';
2
-
3
- var __defProp = Object.defineProperty;
4
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
- const writeStream = /* @__PURE__ */ __name((data, stream) => {
6
- const write = stream.__write ?? stream.write;
7
- return write.call(stream, data);
8
- }, "writeStream");
9
-
10
- exports.writeStream = writeStream;