nightingale 16.2.0 → 17.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +1 -1
  3. package/dist/definitions/formatter-utils/formatRecordToString.d.ts +1 -1
  4. package/dist/definitions/formatter-utils/formatRecordToString.d.ts.map +1 -1
  5. package/dist/definitions/formatter-utils/index.d.ts +1 -4
  6. package/dist/definitions/formatter-utils/index.d.ts.map +1 -1
  7. package/dist/definitions/formatters/BrowserConsoleFormatter.d.ts +3 -3
  8. package/dist/definitions/formatters/BrowserConsoleFormatter.d.ts.map +1 -1
  9. package/dist/definitions/formatters/JSONFormatter.d.ts.map +1 -1
  10. package/dist/definitions/handlers/ConsoleCLIHandler.d.ts +1 -0
  11. package/dist/definitions/handlers/ConsoleCLIHandler.d.ts.map +1 -1
  12. package/dist/definitions/handlers/ConsoleHandler.d.ts +2 -1
  13. package/dist/definitions/handlers/ConsoleHandler.d.ts.map +1 -1
  14. package/dist/definitions/handlers/defaultFormatter.d.ts +2 -0
  15. package/dist/definitions/handlers/defaultFormatter.d.ts.map +1 -0
  16. package/dist/definitions/handlers/defaultFormatter.target-node.d.ts +2 -0
  17. package/dist/definitions/handlers/defaultFormatter.target-node.d.ts.map +1 -0
  18. package/dist/definitions/loggers/LoggerCLI.d.ts +6 -1
  19. package/dist/definitions/loggers/LoggerCLI.d.ts.map +1 -1
  20. package/dist/definitions/loggers/LoggerCLI.test.d.ts +2 -0
  21. package/dist/definitions/loggers/LoggerCLI.test.d.ts.map +1 -0
  22. package/dist/definitions/outputs/cliConsoleOutput.d.ts +1 -1
  23. package/dist/definitions/outputs/cliConsoleOutput.d.ts.map +1 -1
  24. package/dist/definitions/outputs/consoleOutput.d.ts +1 -1
  25. package/dist/definitions/outputs/consoleOutput.d.ts.map +1 -1
  26. package/dist/definitions/outputs/consoleOutput.target-node.d.ts +3 -0
  27. package/dist/definitions/outputs/consoleOutput.target-node.d.ts.map +1 -0
  28. package/dist/index-browser.es.js +262 -357
  29. package/dist/index-browser.es.js.map +1 -1
  30. package/dist/index-node20.mjs +266 -362
  31. package/dist/index-node20.mjs.map +1 -1
  32. package/package.json +14 -12
  33. package/src/formatter-utils/formatObject.test.ts +1 -3
  34. package/src/formatter-utils/formatRecordToString.ts +2 -2
  35. package/src/formatter-utils/index.ts +1 -5
  36. package/src/formatters/ANSIFormatter.test.ts +1 -1
  37. package/src/formatters/BrowserConsoleFormatter.ts +4 -6
  38. package/src/formatters/HTMLFormatter.test.ts +2 -2
  39. package/src/formatters/JSONFormatter.test.ts +5 -5
  40. package/src/formatters/JSONFormatter.ts +19 -15
  41. package/src/formatters/MarkdownFormatter.test.ts +3 -1
  42. package/src/formatters/RawFormatter.test.ts +2 -2
  43. package/src/handlers/ConsoleCLIHandler.ts +11 -2
  44. package/src/handlers/ConsoleHandler.ts +3 -11
  45. package/src/handlers/StringHandler.ts +1 -1
  46. package/src/handlers/defaultFormatter.target-node.ts +7 -0
  47. package/src/handlers/defaultFormatter.ts +3 -0
  48. package/src/loggers/LoggerCLI.test.ts +19 -0
  49. package/src/loggers/LoggerCLI.ts +22 -2
  50. package/src/outputs/cliConsoleOutput.ts +2 -9
  51. package/src/outputs/consoleOutput.target-node.ts +10 -0
  52. package/src/outputs/consoleOutput.ts +2 -10
@@ -10,7 +10,7 @@ if (process.env.NODE_ENV !== "production" && globalOrWindow.__NIGHTINGALE_GLOBAL
10
10
  }
11
11
  if (!globalOrWindow.__NIGHTINGALE_CONFIG) {
12
12
  globalOrWindow.__NIGHTINGALE_CONFIG = [];
13
- globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map();
13
+ globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE = /* @__PURE__ */ new Map();
14
14
  globalOrWindow.__NIGHTINGALE_CONFIG_DEFAULT = {
15
15
  handlers: [],
16
16
  processors: []
@@ -43,7 +43,9 @@ function handleConfig(config) {
43
43
  }
44
44
  if (config.processor) {
45
45
  if (config.processors) {
46
- throw new Error("Cannot have processors and processors for the same config");
46
+ throw new Error(
47
+ "Cannot have processors and processors for the same config"
48
+ );
47
49
  }
48
50
  config.processors = [config.processor];
49
51
  delete config.processor;
@@ -52,7 +54,6 @@ function handleConfig(config) {
52
54
  }
53
55
  function configure(config) {
54
56
  if (globalOrWindow.__NIGHTINGALE_CONFIG.length > 0) {
55
- // eslint-disable-next-line no-console
56
57
  console.log("nightingale: warning: config overridden");
57
58
  }
58
59
  clearCache();
@@ -63,12 +64,12 @@ function addConfig(config, unshift = false) {
63
64
  globalOrWindow.__NIGHTINGALE_CONFIG[unshift ? "unshift" : "push"](config);
64
65
  clearCache();
65
66
  }
66
- const configIsForKey = key => config => {
67
+ const configIsForKey = (key) => (config) => {
67
68
  if (config.keys) return config.keys.includes(key);
68
69
  if (config.pattern) return config.pattern.test(key);
69
70
  return true;
70
71
  };
71
- globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = key => {
72
+ globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = (key) => {
72
73
  const globalCache = globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE;
73
74
  const existingCache = globalCache.get(key);
74
75
  if (existingCache) {
@@ -78,7 +79,7 @@ globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = key => {
78
79
  handlers: [],
79
80
  processors: []
80
81
  };
81
- globalOrWindow.__NIGHTINGALE_CONFIG.filter(configIsForKey(key)).some(config => {
82
+ globalOrWindow.__NIGHTINGALE_CONFIG.filter(configIsForKey(key)).some((config) => {
82
83
  if (config.handlers) loggerConfig.handlers.push(...config.handlers);
83
84
  if (config.processors) loggerConfig.processors.push(...config.processors);
84
85
  return config.stop;
@@ -88,12 +89,11 @@ globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = key => {
88
89
  };
89
90
  if (globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
90
91
  globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (key, level) => {
91
- const {
92
- handlers,
93
- processors
94
- } = globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key);
92
+ const { handlers, processors } = globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key);
95
93
  return {
96
- handlers: handlers.filter(handler => level >= handler.minLevel && (!handler.isHandling || handler.isHandling(level, key))),
94
+ handlers: handlers.filter(
95
+ (handler) => level >= handler.minLevel && (!handler.isHandling || handler.isHandling(level, key))
96
+ ),
97
97
  processors
98
98
  };
99
99
  };
@@ -111,14 +111,14 @@ const levelToStyles = {
111
111
  };
112
112
 
113
113
  const levelToSymbol = {
114
- [Level.TRACE]: "",
115
- [Level.DEBUG]: "",
116
- [Level.INFO]: "",
117
- [Level.WARN]: "",
118
- [Level.ERROR]: "",
114
+ [Level.TRACE]: "\u2022",
115
+ [Level.DEBUG]: "\u2022",
116
+ [Level.INFO]: "\u2192",
117
+ [Level.WARN]: "\u26A0",
118
+ [Level.ERROR]: "\u2716",
119
119
  [Level.CRITICAL]: "!",
120
- [Level.FATAL]: "",
121
- [Level.EMERGENCY]: ""
120
+ [Level.FATAL]: "\u203C",
121
+ [Level.EMERGENCY]: "\u203C"
122
122
  };
123
123
 
124
124
  const styleToHexColor = {
@@ -127,14 +127,8 @@ const styleToHexColor = {
127
127
 
128
128
  const styleToHtmlStyleThemeLight = {
129
129
  // text style
130
- bold: {
131
- open: "font-weight: bold",
132
- close: "font-weight: normal"
133
- },
134
- italic: {
135
- open: "font-style: italic",
136
- close: "font-style: normal"
137
- },
130
+ bold: { open: "font-weight: bold", close: "font-weight: normal" },
131
+ italic: { open: "font-style: italic", close: "font-style: normal" },
138
132
  underline: {
139
133
  open: "text-decoration: underline",
140
134
  close: "text-decoration: none"
@@ -147,78 +141,24 @@ const styleToHtmlStyleThemeLight = {
147
141
  open: "text-decoration: line-through",
148
142
  close: "text-decoration: none"
149
143
  },
150
- black: {
151
- open: "color: black",
152
- close: "color: currentcolor"
153
- },
154
- red: {
155
- open: "color: #ff0020",
156
- close: "color: currentcolor"
157
- },
158
- green: {
159
- open: "color: #00b317",
160
- close: "color: currentcolor"
161
- },
162
- yellow: {
163
- open: "color: #ffcc00",
164
- close: "color: currentcolor"
165
- },
166
- blue: {
167
- open: "color: #00a0ff",
168
- close: "color: currentcolor"
169
- },
170
- magenta: {
171
- open: "color: #ff00a0",
172
- close: "color: currentcolor"
173
- },
174
- cyan: {
175
- open: "color: #00cfd8",
176
- close: "color: currentcolor"
177
- },
178
- white: {
179
- open: "color: white",
180
- close: "color: currentcolor"
181
- },
182
- gray: {
183
- open: "color: gray",
184
- close: "color: currentcolor"
185
- },
186
- dim: {
187
- open: "color: #808080",
188
- close: "color: currentcolor"
189
- },
190
- bgBlack: {
191
- open: "background: black",
192
- close: "background: initial"
193
- },
194
- bgRed: {
195
- open: "background: #ff0020",
196
- close: "background: initial"
197
- },
198
- bgGreen: {
199
- open: "background: #00b317",
200
- close: "background: initial"
201
- },
202
- bgYellow: {
203
- open: "background: #ffcc00",
204
- close: "background: initial"
205
- },
206
- bgBlue: {
207
- open: "background: #00a0ff",
208
- close: "background: initial"
209
- },
210
- bgMagenta: {
211
- open: "background: #ff00a0",
212
- close: "background: initial"
213
- },
214
- bgCyan: {
215
- open: "background: #00cfd8",
216
- close: "background: initial"
217
- },
218
- bgWhite: {
219
- open: "background: white",
220
- close: "background: initial"
221
- },
144
+ black: { open: "color: black", close: "color: currentcolor" },
145
+ red: { open: "color: #ff0020", close: "color: currentcolor" },
146
+ green: { open: "color: #00b317", close: "color: currentcolor" },
147
+ yellow: { open: "color: #ffcc00", close: "color: currentcolor" },
148
+ blue: { open: "color: #00a0ff", close: "color: currentcolor" },
149
+ magenta: { open: "color: #ff00a0", close: "color: currentcolor" },
150
+ cyan: { open: "color: #00cfd8", close: "color: currentcolor" },
151
+ white: { open: "color: white", close: "color: currentcolor" },
152
+ gray: { open: "color: gray", close: "color: currentcolor" },
153
+ dim: { open: "color: #808080", close: "color: currentcolor" },
154
+ bgBlack: { open: "background: black", close: "background: initial" },
155
+ bgRed: { open: "background: #ff0020", close: "background: initial" },
156
+ bgGreen: { open: "background: #00b317", close: "background: initial" },
157
+ bgYellow: { open: "background: #ffcc00", close: "background: initial" },
158
+ bgBlue: { open: "background: #00a0ff", close: "background: initial" },
159
+ bgMagenta: { open: "background: #ff00a0", close: "background: initial" },
160
+ bgCyan: { open: "background: #00cfd8", close: "background: initial" },
161
+ bgWhite: { open: "background: white", close: "background: initial" },
222
162
  orange: {
223
163
  open: `color: #${styleToHexColor.orange}`,
224
164
  close: "color: currentcolor"
@@ -230,14 +170,9 @@ const styleToHtmlStyleThemeDark = {
230
170
  bgBlack: styleToHtmlStyleThemeLight.bgWhite,
231
171
  white: styleToHtmlStyleThemeLight.black,
232
172
  bgWhite: styleToHtmlStyleThemeLight.bgBlack,
233
- gray: {
234
- open: "color: lightgray",
235
- close: "color: currentcolor"
236
- }
173
+ gray: { open: "color: lightgray", close: "color: currentcolor" }
237
174
  };
238
175
 
239
- /* eslint sort-keys: error */
240
-
241
176
  const formatStyles = {
242
177
  bigint: ["yellow", "bold"],
243
178
  boolean: ["green"],
@@ -252,8 +187,6 @@ const formatStyles = {
252
187
  undefined: ["dim"]
253
188
  };
254
189
 
255
- /* eslint-disable @typescript-eslint/no-use-before-define */
256
-
257
190
  const noStyleFn = (styles, value) => value;
258
191
  function tryStringify(arg) {
259
192
  try {
@@ -262,12 +195,12 @@ function tryStringify(arg) {
262
195
  return "[Circular]";
263
196
  }
264
197
  }
265
- const sameRawFormattedValue = value => ({
198
+ const sameRawFormattedValue = (value) => ({
266
199
  stringValue: value,
267
200
  formattedValue: value
268
201
  });
269
202
  const numericSeparator = "_";
270
- const formatIntegerValue = integerAsString => {
203
+ const formatIntegerValue = (integerAsString) => {
271
204
  let result = "";
272
205
  let i = integerAsString.length;
273
206
  const start = integerAsString.startsWith("-") ? 1 : 0;
@@ -276,7 +209,7 @@ const formatIntegerValue = integerAsString => {
276
209
  }
277
210
  return i === integerAsString.length ? integerAsString : `${integerAsString.slice(0, i)}${result}`;
278
211
  };
279
- const formatDecimalIntegerValue = integerAsString => {
212
+ const formatDecimalIntegerValue = (integerAsString) => {
280
213
  let result = "";
281
214
  let i = 0;
282
215
  for (; i < integerAsString.length - 3; i += 3) {
@@ -284,7 +217,7 @@ const formatDecimalIntegerValue = integerAsString => {
284
217
  }
285
218
  return i === 0 ? integerAsString : `${result}${integerAsString.slice(i)}`;
286
219
  };
287
- const formatNumberValue = value => {
220
+ const formatNumberValue = (value) => {
288
221
  if (Number.isNaN(value)) {
289
222
  return "NaN";
290
223
  }
@@ -311,12 +244,7 @@ const formatNumberValue = value => {
311
244
  return `${formatIntegerValue(integerAsString)}.${formatDecimalIntegerValue(String(value).slice(integerAsString.length + 1))}`;
312
245
  }
313
246
  };
314
- function internalFormatValue(value, styleFn, styles, {
315
- padding,
316
- depth,
317
- maxDepth,
318
- objects
319
- }) {
247
+ function internalFormatValue(value, styleFn, styles, { padding, depth, maxDepth, objects }) {
320
248
  const typeofValue = typeof value;
321
249
  if (!styles) {
322
250
  if (value === null) {
@@ -361,23 +289,27 @@ function internalFormatValue(value, styleFn, styles, {
361
289
  let stringValue;
362
290
  if (value === null) {
363
291
  stringValue = "null";
364
- } else if (value === undefined) {
292
+ } else if (value === void 0) {
365
293
  stringValue = "undefined";
366
294
  } else if (typeofValue === "number") {
367
295
  stringValue = formatNumberValue(value);
368
296
  } else if (typeofValue === "boolean") {
369
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
370
297
  stringValue = value.toString();
371
298
  } else if (value.constructor === Object) {
372
299
  if (depth >= maxDepth) {
373
300
  stringValue = "{Object...}";
374
301
  } else {
375
- return internalFormatObject(value, styleFn, undefined, {
376
- padding,
377
- depth: depth + 1,
378
- maxDepth,
379
- objects
380
- });
302
+ return internalFormatObject(
303
+ value,
304
+ styleFn,
305
+ void 0,
306
+ {
307
+ padding,
308
+ depth: depth + 1,
309
+ maxDepth,
310
+ objects
311
+ }
312
+ );
381
313
  }
382
314
  } else if (Array.isArray(value)) {
383
315
  if (depth >= maxDepth) {
@@ -392,7 +324,8 @@ function internalFormatValue(value, styleFn, styles, {
392
324
  }
393
325
  } else if (value instanceof Error) {
394
326
  const stack = value.stack;
395
- stringValue = stack?.startsWith(value.message) || stack?.startsWith(`${value.name}: ${value.message}`) ? stack : `${value.message}\n${stack || ""}`;
327
+ stringValue = stack?.startsWith(value.message) || stack?.startsWith(`${value.name}: ${value.message}`) ? stack : `${value.message}
328
+ ${stack || ""}`;
396
329
  } else if (value instanceof Map) {
397
330
  const name = value.constructor.name;
398
331
  if (depth >= maxDepth) {
@@ -441,34 +374,28 @@ function internalFormatValue(value, styleFn, styles, {
441
374
  };
442
375
  }
443
376
  const separator = ",";
444
- const internalFormatKey = (key, styleFn) => {
377
+ const internalFormatKey = (key, styleFn, internalFormatParams) => {
445
378
  return {
446
379
  stringKey: `${key}: `,
447
380
  formattedKey: `${styleFn(["dim", "bold"], `${key}:`)} `
448
381
  };
449
382
  };
450
- const internalNoKey = () => {
451
- return {
452
- stringKey: "",
453
- formattedKey: ""
454
- };
383
+ const internalNoKey = (key, styleFn, internalFormatParams) => {
384
+ return { stringKey: "", formattedKey: "" };
455
385
  };
456
386
  const internalFormatMapKey = (key, styleFn, internalFormatParams) => {
457
- const {
458
- stringValue,
459
- formattedValue
460
- } = internalFormatValue(key, noStyleFn, undefined, internalFormatParams);
387
+ const { stringValue, formattedValue } = internalFormatValue(
388
+ key,
389
+ noStyleFn,
390
+ void 0,
391
+ internalFormatParams
392
+ );
461
393
  return {
462
394
  stringKey: `${stringValue} => `,
463
395
  formattedKey: `${styleFn(["dim", "bold"], `${formattedValue}:`)} `
464
396
  };
465
397
  };
466
- const internalFormatIterator = (values, styleFn, objectStyles, {
467
- padding,
468
- depth,
469
- maxDepth,
470
- objects
471
- }, {
398
+ const internalFormatIterator = (values, styleFn, objectStyles, { padding, depth, maxDepth, objects }, {
472
399
  prefix,
473
400
  suffix,
474
401
  prefixSuffixSpace = " ",
@@ -477,48 +404,52 @@ const internalFormatIterator = (values, styleFn, objectStyles, {
477
404
  let breakLine = false;
478
405
  const formattedSeparator = () => styleFn(["gray"], separator);
479
406
  const valuesMaxIndex = values.length - 1;
480
- const formattedValues = values.map(({
481
- key,
482
- value
483
- }, index) => {
484
- const internalFormatParams = {
485
- padding,
486
- depth: depth + 1,
487
- maxDepth,
488
- objects
489
- };
490
-
491
- // key must be formatted before value (browser-formatter needs order)
492
- const {
493
- stringKey,
494
- formattedKey
495
- } = formatKey(key, styleFn, internalFormatParams);
496
- let {
497
- stringValue,
498
- formattedValue
499
- } = internalFormatValue(value, styleFn, key && objectStyles ? objectStyles[key] : undefined, internalFormatParams);
500
- if (stringValue && (stringValue.length > 80 || stringValue.includes("\n"))) {
501
- breakLine = true;
502
- stringValue = stringValue.replace(/\n/g, `\n${padding}`);
503
- formattedValue = formattedValue.replace(/\n/g, `\n${padding}`);
407
+ const formattedValues = values.map(
408
+ ({ key, value }, index) => {
409
+ const nextDepth = depth + 1;
410
+ const internalFormatParams = {
411
+ padding,
412
+ depth: nextDepth,
413
+ maxDepth,
414
+ objects
415
+ };
416
+ const { stringKey, formattedKey } = formatKey(
417
+ key,
418
+ styleFn,
419
+ internalFormatParams
420
+ );
421
+ let { stringValue, formattedValue } = internalFormatValue(
422
+ value,
423
+ styleFn,
424
+ key && objectStyles ? objectStyles[key] : void 0,
425
+ internalFormatParams
426
+ );
427
+ if (stringValue && (stringValue.length > 80 || stringValue.includes("\n"))) {
428
+ breakLine = true;
429
+ stringValue = stringValue.replace(/\n/g, `
430
+ ${padding}`);
431
+ formattedValue = formattedValue.replace(/\n/g, `
432
+ ${padding}`);
433
+ }
434
+ return {
435
+ stringValue: stringKey + stringValue + (index === valuesMaxIndex ? "" : separator),
436
+ formattedValue: formattedKey + formattedValue + (index === valuesMaxIndex ? "" : formattedSeparator())
437
+ // note: we need to format the separator for each values for browser-formatter
438
+ };
504
439
  }
505
- return {
506
- stringValue: stringKey + stringValue + (index === valuesMaxIndex ? "" : separator),
507
- formattedValue: formattedKey + formattedValue + (index === valuesMaxIndex ? "" : formattedSeparator())
508
- // note: we need to format the separator for each values for browser-formatter
509
- };
510
- });
440
+ );
511
441
  return {
512
- stringValue: prefix + formattedValues.map(breakLine ? v => `\n${padding}${v.stringValue}` : fv => fv.stringValue).join(breakLine ? "\n" : " ") + suffix,
513
- formattedValue: `${prefix}${breakLine ? "" : prefixSuffixSpace}${formattedValues.map(breakLine ? v => `\n${padding}${v.formattedValue}` : v => v.formattedValue).join(breakLine ? "" : " ")}${breakLine ? ",\n" : prefixSuffixSpace}${suffix}`
442
+ stringValue: prefix + formattedValues.map(
443
+ breakLine ? (v) => `
444
+ ${padding}${v.stringValue}` : (fv) => fv.stringValue
445
+ ).join(breakLine ? "\n" : " ") + suffix,
446
+ formattedValue: `${prefix}${breakLine ? "" : prefixSuffixSpace}${formattedValues.map(
447
+ breakLine ? (v) => `
448
+ ${padding}${v.formattedValue}` : (v) => v.formattedValue
449
+ ).join(breakLine ? "" : " ")}${breakLine ? ",\n" : prefixSuffixSpace}${suffix}`
514
450
  };
515
451
  };
516
- function internalFormatObject(object, styleFn, objectStyles, {
517
- padding,
518
- depth,
519
- maxDepth,
520
- objects
521
- }) {
452
+ function internalFormatObject(object, styleFn, objectStyles, { padding, depth, maxDepth, objects }) {
522
453
  if (objects.has(object)) {
523
454
  return sameRawFormattedValue("{Circular Object}");
524
455
  }
@@ -527,28 +458,17 @@ function internalFormatObject(object, styleFn, objectStyles, {
527
458
  return sameRawFormattedValue("{}");
528
459
  }
529
460
  objects.add(object);
530
- const result = internalFormatIterator(keys.map(key => ({
531
- key,
532
- value: object[key]
533
- })), styleFn, objectStyles, {
534
- padding,
535
- depth,
536
- maxDepth,
537
- objects
538
- }, {
539
- prefix: "{",
540
- suffix: "}",
541
- formatKey: internalFormatKey
542
- });
461
+ const result = internalFormatIterator(
462
+ keys.map((key) => ({ key, value: object[key] })),
463
+ styleFn,
464
+ objectStyles,
465
+ { padding, depth, maxDepth, objects },
466
+ { prefix: "{", suffix: "}", formatKey: internalFormatKey }
467
+ );
543
468
  objects.delete(object);
544
469
  return result;
545
470
  }
546
- function internalFormatMap(name, map, styleFn, {
547
- padding,
548
- depth,
549
- maxDepth,
550
- objects
551
- }) {
471
+ function internalFormatMap(name, map, styleFn, { padding, depth, maxDepth, objects }) {
552
472
  if (objects.has(map)) {
553
473
  return sameRawFormattedValue(`{Circular ${name}}`);
554
474
  }
@@ -557,28 +477,17 @@ function internalFormatMap(name, map, styleFn, {
557
477
  return sameRawFormattedValue(`${name} {}`);
558
478
  }
559
479
  objects.add(map);
560
- const result = internalFormatIterator(keys.map(key => ({
561
- key,
562
- value: map.get(key)
563
- })), styleFn, undefined, {
564
- padding,
565
- depth,
566
- maxDepth,
567
- objects
568
- }, {
569
- prefix: `${name} {`,
570
- suffix: "}",
571
- formatKey: internalFormatMapKey
572
- });
480
+ const result = internalFormatIterator(
481
+ keys.map((key) => ({ key, value: map.get(key) })),
482
+ styleFn,
483
+ void 0,
484
+ { padding, depth, maxDepth, objects },
485
+ { prefix: `${name} {`, suffix: "}", formatKey: internalFormatMapKey }
486
+ );
573
487
  objects.delete(map);
574
488
  return result;
575
489
  }
576
- function internalFormatArray(array, styleFn, {
577
- padding,
578
- depth,
579
- maxDepth,
580
- objects
581
- }) {
490
+ function internalFormatArray(array, styleFn, { padding, depth, maxDepth, objects }) {
582
491
  if (objects.has(array)) {
583
492
  return sameRawFormattedValue("{Circular Array}");
584
493
  }
@@ -586,29 +495,22 @@ function internalFormatArray(array, styleFn, {
586
495
  return sameRawFormattedValue("[]");
587
496
  }
588
497
  objects.add(array);
589
- const result = internalFormatIterator(array.map(value => ({
590
- key: undefined,
591
- value
592
- })), styleFn, undefined, {
593
- padding,
594
- depth,
595
- maxDepth,
596
- objects
597
- }, {
598
- prefix: "[",
599
- suffix: "]",
600
- prefixSuffixSpace: "",
601
- formatKey: internalNoKey
602
- });
498
+ const result = internalFormatIterator(
499
+ array.map((value) => ({ key: void 0, value })),
500
+ styleFn,
501
+ void 0,
502
+ { padding, depth, maxDepth, objects },
503
+ {
504
+ prefix: "[",
505
+ suffix: "]",
506
+ prefixSuffixSpace: "",
507
+ formatKey: internalNoKey
508
+ }
509
+ );
603
510
  objects.delete(array);
604
511
  return result;
605
512
  }
606
- function internalFormatSet(name, set, styleFn, {
607
- padding,
608
- depth,
609
- maxDepth,
610
- objects
611
- }) {
513
+ function internalFormatSet(name, set, styleFn, { padding, depth, maxDepth, objects }) {
612
514
  if (objects.has(set)) {
613
515
  return sameRawFormattedValue(`{Circular ${name}}`);
614
516
  }
@@ -617,34 +519,28 @@ function internalFormatSet(name, set, styleFn, {
617
519
  return sameRawFormattedValue(`${name} []`);
618
520
  }
619
521
  objects.add(set);
620
- const result = internalFormatIterator(values.map(value => ({
621
- key: undefined,
622
- value
623
- })), styleFn, undefined, {
624
- padding,
625
- depth,
626
- maxDepth,
627
- objects
628
- }, {
629
- prefix: `${name} [`,
630
- suffix: "]",
631
- formatKey: internalNoKey
632
- });
522
+ const result = internalFormatIterator(
523
+ values.map((value) => ({ key: void 0, value })),
524
+ styleFn,
525
+ void 0,
526
+ { padding, depth, maxDepth, objects },
527
+ { prefix: `${name} [`, suffix: "]", formatKey: internalNoKey }
528
+ );
633
529
  objects.delete(set);
634
530
  return result;
635
531
  }
636
- function formatObject(object, styleFn = noStyleFn, objectStyles, {
637
- padding = " ",
638
- maxDepth = 10
639
- } = {}) {
640
- const {
641
- formattedValue: result
642
- } = internalFormatObject(object, styleFn, objectStyles, {
643
- padding,
644
- maxDepth,
645
- depth: 0,
646
- objects: new Set()
647
- });
532
+ function formatObject(object, styleFn = noStyleFn, objectStyles, { padding = " ", maxDepth = 10 } = {}) {
533
+ const { formattedValue: result } = internalFormatObject(
534
+ object,
535
+ styleFn,
536
+ objectStyles,
537
+ {
538
+ padding,
539
+ maxDepth,
540
+ depth: 0,
541
+ objects: /* @__PURE__ */ new Set()
542
+ }
543
+ );
648
544
  if (result === "{}") {
649
545
  return "";
650
546
  }
@@ -659,8 +555,9 @@ function formatRecordToString(record, style) {
659
555
  parts.push(style(["dim"], record.key));
660
556
  }
661
557
  if (record.datetime) {
662
- parts.push(style(["gray", "bold"], record.datetime.toTimeString().split(" ", 2)[0]));
663
- /* new Date().toFormat('HH24:MI:SS') */
558
+ parts.push(
559
+ style(["gray", "bold"], record.datetime.toTimeString().split(" ", 2)[0])
560
+ );
664
561
  }
665
562
  let message = record.symbol || levelToSymbol[record.level] || "";
666
563
  const styles = record.styles || levelToStyles[record.level];
@@ -688,24 +585,23 @@ function formatRecordToString(record, style) {
688
585
  parts.push(stringObject);
689
586
  };
690
587
  formatRecordObject("metadata", record.metadata, record.metadataStyles);
691
- formatRecordObject("extra", record.extra, undefined);
692
- formatRecordObject("context", record.context, undefined);
693
- return parts.join(" ");
588
+ formatRecordObject("extra", record.extra, void 0);
589
+ formatRecordObject("context", record.context, void 0);
590
+ return [parts.join(" ")];
694
591
  }
695
592
 
696
- /* eslint-disable complexity */
697
593
  const specialRegexpChars = /[$()+.?[\\\]^{|}]/;
698
- const createTestFunctionFromRegexp = regexp => string => regexp.test(string);
699
- const createTestFunctionFromRegexpString = value => {
594
+ const createTestFunctionFromRegexp = (regexp) => (string) => regexp.test(string);
595
+ const createTestFunctionFromRegexpString = (value) => {
700
596
  if (!value.endsWith("/")) throw new Error("Invalid RegExp DEBUG value");
701
597
  return createTestFunctionFromRegexp(new RegExp(value.slice(1, -1)));
702
598
  };
703
- const createTestFunctionFromValue = value => {
599
+ const createTestFunctionFromValue = (value) => {
704
600
  if (value.endsWith(":*")) {
705
601
  value = value.slice(0, -2);
706
- return string => string.startsWith(value);
602
+ return (string) => string.startsWith(value);
707
603
  }
708
- return string => string === value;
604
+ return (string) => string === value;
709
605
  };
710
606
  function createFindDebugLevel(debugValue) {
711
607
  let isWildcard = false;
@@ -714,21 +610,23 @@ function createFindDebugLevel(debugValue) {
714
610
  if (!Array.isArray(debugValue)) {
715
611
  if (debugValue instanceof RegExp) {
716
612
  debugValues.push(createTestFunctionFromRegexp(debugValue));
717
- debugValue = undefined;
613
+ debugValue = void 0;
718
614
  } else if (debugValue) {
719
615
  debugValue = debugValue.trim();
720
616
  if (debugValue.startsWith("/")) {
721
617
  debugValues.push(createTestFunctionFromRegexpString(debugValue));
722
- debugValue = undefined;
618
+ debugValue = void 0;
723
619
  } else {
724
620
  debugValue = debugValue.split(/[\s,]+/);
725
621
  }
726
622
  }
727
623
  }
728
624
  if (debugValue) {
729
- debugValue.forEach(value => {
625
+ debugValue.forEach((value) => {
730
626
  if (specialRegexpChars.test(value)) {
731
- throw new Error(`Invalid debug value: "${value}" (contains special chars)`);
627
+ throw new Error(
628
+ `Invalid debug value: "${value}" (contains special chars)`
629
+ );
732
630
  }
733
631
  if (!value) return;
734
632
  if (value === "*") {
@@ -746,18 +644,18 @@ function createFindDebugLevel(debugValue) {
746
644
  if (skips.length === 0) {
747
645
  return () => Level.ALL;
748
646
  } else {
749
- return (minLevel, key) => skips.some(skip => skip(key)) ? minLevel : Level.ALL;
647
+ return (minLevel, key) => skips.some((skip) => skip(key)) ? minLevel : Level.ALL;
750
648
  }
751
649
  }
752
650
  if (debugValues.length === 0) {
753
- return minLevel => minLevel;
651
+ return (minLevel) => minLevel;
754
652
  }
755
653
  return (minLevel, key) => {
756
654
  if (minLevel === Level.ALL || !key) {
757
655
  return minLevel;
758
656
  }
759
- if (debugValues.some(dv => dv(key))) {
760
- return skips.some(skip => skip(key)) ? minLevel : Level.ALL;
657
+ if (debugValues.some((dv) => dv(key))) {
658
+ return skips.some((skip) => skip(key)) ? minLevel : Level.ALL;
761
659
  }
762
660
  return minLevel;
763
661
  };
@@ -776,8 +674,6 @@ function style$3(styles, string) {
776
674
  if (!styles || styles.length === 0 || !string) {
777
675
  return string;
778
676
  }
779
-
780
- // eslint-disable-next-line unicorn/no-array-reduce
781
677
  return styles.reduce((part, styleName) => {
782
678
  switch (styleName) {
783
679
  case "bold":
@@ -786,8 +682,6 @@ function style$3(styles, string) {
786
682
  return `_${part}_`;
787
683
  case "strikethrough":
788
684
  return `~${part}~`;
789
-
790
- // no default
791
685
  }
792
686
  return part;
793
687
  }, string);
@@ -802,39 +696,42 @@ function map2object(map) {
802
696
  const object = {};
803
697
  map.forEach((value, key) => {
804
698
  if (typeof key === "object") {
805
- // ignore key
806
699
  return;
807
700
  }
808
-
809
- // eslint-disable-next-line @typescript-eslint/no-base-to-string
810
701
  object[String(key)] = value;
811
702
  });
812
703
  return object;
813
704
  }
814
705
  function stringify(value, space) {
815
- return JSON.stringify(value, (key, objectValue) => {
816
- if (objectValue instanceof Map) {
817
- return map2object(objectValue);
818
- }
819
- if (objectValue instanceof Error) {
820
- return {
821
- message: objectValue.message,
822
- stack: objectValue.stack
823
- };
824
- }
825
- return objectValue;
826
- }, space);
706
+ return JSON.stringify(
707
+ value,
708
+ (key, objectValue) => {
709
+ if (objectValue instanceof Map) {
710
+ return map2object(objectValue);
711
+ }
712
+ if (objectValue instanceof Error) {
713
+ return {
714
+ message: objectValue.message,
715
+ stack: objectValue.stack
716
+ };
717
+ }
718
+ return objectValue;
719
+ },
720
+ space
721
+ );
827
722
  }
828
723
  const JSONFormatter = {
829
724
  format(record) {
830
- return stringify({
831
- key: record.key,
832
- level: record.level,
833
- datetime: record.datetime,
834
- message: record.message,
835
- metadata: record.metadata,
836
- extra: record.extra
837
- });
725
+ return [
726
+ stringify({
727
+ key: record.key,
728
+ level: record.level,
729
+ datetime: record.datetime,
730
+ message: record.message,
731
+ metadata: record.metadata,
732
+ extra: record.extra
733
+ })
734
+ ];
838
735
  }
839
736
  };
840
737
 
@@ -869,8 +766,6 @@ function style$2(styles, string) {
869
766
  if (!styles || styles.length === 0 || !string) {
870
767
  return string;
871
768
  }
872
-
873
- // eslint-disable-next-line unicorn/no-array-reduce
874
769
  return styles.reduce((styledString, styleName) => {
875
770
  const codePair = ansiStyles[styleName];
876
771
  if (!codePair) {
@@ -880,14 +775,16 @@ function style$2(styles, string) {
880
775
  }, string);
881
776
  }
882
777
  const ANSIFormatter = {
883
- format: record => formatRecordToString(record, style$2)
778
+ format: (record) => formatRecordToString(record, style$2)
884
779
  };
885
780
 
886
781
  function style$1(styles, string) {
887
782
  if (!styles || styles.length === 0 || !string) {
888
783
  return string;
889
784
  }
890
- return `<span style="${styles.map(styleName => styleToHtmlStyleThemeLight[styleName].open).join("; ")}">${string}</span>`;
785
+ return `<span style="${styles.map(
786
+ (styleName) => styleToHtmlStyleThemeLight[styleName].open
787
+ ).join("; ")}">${string}</span>`;
891
788
  }
892
789
  const HTMLFormatter = {
893
790
  format(record) {
@@ -899,8 +796,13 @@ const style = (styleToHtmlStyle, args) => (styles, string) => {
899
796
  if (!styles || styles.length === 0 || !string) {
900
797
  return string;
901
798
  }
902
- const htmlStyles = styles.map(styleName => styleToHtmlStyle[styleName]);
903
- args.push(htmlStyles.map(s => s.open).join("; "), htmlStyles.map(s => s.close).join("; "));
799
+ const htmlStyles = styles.map(
800
+ (styleName) => styleToHtmlStyle[styleName]
801
+ );
802
+ args.push(
803
+ htmlStyles.map((s) => s.open).join("; "),
804
+ htmlStyles.map((s) => s.close).join("; ")
805
+ );
904
806
  return `%c${string}%c`;
905
807
  };
906
808
  class BrowserConsoleFormatter {
@@ -909,51 +811,51 @@ class BrowserConsoleFormatter {
909
811
  }
910
812
  format(record) {
911
813
  const args = [];
912
- const string = formatRecordToString(record, style(this.styleToHtmlStyle, args));
814
+ const string = formatRecordToString(
815
+ record,
816
+ style(this.styleToHtmlStyle, args)
817
+ )[0];
913
818
  return [string, ...args];
914
819
  }
915
820
  }
916
821
 
917
- /* eslint-disable no-console */
918
822
  function consoleOutput(param, record) {
919
- {
920
- const outKey = record.level >= Level.ERROR ? "stderr" : "stdout";
921
- process[outKey].write(`${param}\n`);
922
- }
823
+ const outKey = record.level >= Level.ERROR ? "stderr" : "stdout";
824
+ process[outKey].write(`${param[0]}
825
+ `);
923
826
  }
924
827
 
925
- /* eslint-disable prefer-template */
926
-
927
828
  class StringHandler {
928
- _buffer = "";
929
829
  constructor(minLevel) {
830
+ this._buffer = "";
930
831
  this.minLevel = minLevel;
931
832
  }
932
833
  get string() {
933
834
  return this._buffer;
934
835
  }
935
836
  handle(record) {
936
- this._buffer += RawFormatter.format(record) + "\n";
837
+ this._buffer += RawFormatter.format(record)[0] + "\n";
937
838
  }
938
839
  }
939
840
 
940
841
  function getDebugString() {
941
842
  const querystring = document.location.search;
942
- const debugFromLocalStorage =
943
- // eslint-disable-next-line unicorn/prefer-global-this, @typescript-eslint/no-unnecessary-condition
944
- window.localStorage?.getItem("debug") || "";
843
+ const debugFromLocalStorage = (
844
+ // eslint-disable-next-line unicorn/prefer-global-this, @typescript-eslint/no-unnecessary-condition
845
+ window.localStorage?.getItem("debug") || ""
846
+ );
945
847
  if (!querystring) {
946
848
  return debugFromLocalStorage;
947
849
  }
948
-
949
- // https://developer.mozilla.org/en-US/docs/Web/API/URLUtils/search#Get_the_value_of_a_single_search_param
950
- const debugFromQueryString = decodeURI(querystring.replace(
951
- // eslint-disable-next-line prefer-regex-literals, regexp/no-super-linear-backtracking
952
- new RegExp("^(?:.*[&?]DEBUG(?:=([^&]*))?)?.*$", "i"), "$1"));
850
+ const debugFromQueryString = decodeURI(
851
+ querystring.replace(
852
+ // eslint-disable-next-line prefer-regex-literals, regexp/no-super-linear-backtracking
853
+ new RegExp("^(?:.*[&?]DEBUG(?:=([^&]*))?)?.*$", "i"),
854
+ "$1"
855
+ )
856
+ );
953
857
  return (debugFromLocalStorage ? `${debugFromLocalStorage},` : "") + debugFromQueryString;
954
858
  }
955
-
956
- // debug string can change any time (localStorage), so we need a new object each time.
957
859
  const findDebugLevel$2 = (minLevel, key) => createFindDebugLevel(getDebugString())(minLevel, key);
958
860
  const getDefaultTheme = () => {
959
861
  try {
@@ -961,57 +863,63 @@ const getDefaultTheme = () => {
961
863
  if (configInLocalStorage && configInLocalStorage === "dark") {
962
864
  return configInLocalStorage;
963
865
  }
964
- } catch {}
866
+ } catch {
867
+ }
965
868
  return "light";
966
869
  };
967
870
  const createHandler = (theme = getDefaultTheme()) => {
968
871
  const browserConsoleFormatter = new BrowserConsoleFormatter(theme);
969
- return record => {
872
+ return (record) => {
970
873
  consoleOutput(browserConsoleFormatter.format(record), record);
971
874
  };
972
875
  };
973
876
  class BrowserConsoleHandler {
974
- minLevel = 0;
975
877
  constructor(minLevel, options = {}) {
878
+ this.minLevel = 0;
976
879
  this.isHandling = (level, key) => level >= findDebugLevel$2(minLevel, key);
977
880
  this.handle = createHandler(options.theme);
978
881
  }
979
882
  }
980
883
 
981
884
  const defaultFormatter = !process.stdout.isTTY && process.env.NIGHTINGALE_CONSOLE_FORMATTER !== "ansi" ? JSONFormatter.format : ANSIFormatter.format;
885
+
982
886
  const createHandle$1 = (formatter = defaultFormatter, output = consoleOutput) => {
983
- return record => {
887
+ return (record) => {
984
888
  output(formatter(record), record);
985
889
  };
986
890
  };
987
891
  const findDebugLevel$1 = createFindDebugLevel(process.env.DEBUG);
988
892
  class ConsoleHandler {
989
- minLevel = Level.ALL;
990
893
  constructor(minLevel, options = {}) {
894
+ this.minLevel = Level.ALL;
991
895
  this.minLevel = minLevel;
992
896
  this.isHandling = (level, key) => level >= findDebugLevel$1(minLevel, key);
993
897
  this.handle = createHandle$1(options.formatter, options.output);
994
898
  }
995
899
  }
996
900
 
997
- /* eslint-disable no-console */
998
901
  function cliConsoleOutput(param, record) {
999
- console[record.level >= Level.ERROR ? "error" : "log"](param);
902
+ console[record.level >= Level.ERROR ? "error" : "log"](...param);
1000
903
  }
1001
904
 
1002
905
  const createHandle = ({
1003
- json
906
+ json,
907
+ noColor = process.env.NO_COLOR === "1" || process.env.NO_COLOR === "true"
1004
908
  }) => {
1005
- const formatter = json ? JSONFormatter.format : ANSIFormatter.format;
909
+ const formatter = (() => {
910
+ if (json) return JSONFormatter.format;
911
+ if (noColor) return RawFormatter.format;
912
+ return ANSIFormatter.format;
913
+ })();
1006
914
  const output = json ? consoleOutput : cliConsoleOutput;
1007
- return record => {
915
+ return (record) => {
1008
916
  output(formatter(record), record);
1009
917
  };
1010
918
  };
1011
919
  const findDebugLevel = createFindDebugLevel(process.env.DEBUG);
1012
920
  class ConsoleCLIHandler {
1013
- minLevel = Level.ALL;
1014
921
  constructor(minLevel, options = {}) {
922
+ this.minLevel = Level.ALL;
1015
923
  this.minLevel = minLevel;
1016
924
  this.isHandling = (level, key) => level >= findDebugLevel(minLevel, key);
1017
925
  this.handle = createHandle(options);
@@ -1019,20 +927,14 @@ class ConsoleCLIHandler {
1019
927
  }
1020
928
 
1021
929
  class LoggerCLI extends Logger {
1022
- processors = [];
1023
- constructor(key, {
1024
- displayName,
1025
- processors,
1026
- json = false
1027
- } = {}) {
930
+ constructor(key, { displayName, processors, json = false, noColor } = {}) {
1028
931
  super(key, displayName);
1029
- this.handlers = [new ConsoleCLIHandler(Level$1.INFO, {
1030
- json
1031
- })];
932
+ this.processors = [];
933
+ this.handlers = [new ConsoleCLIHandler(Level$1.INFO, { json, noColor })];
1032
934
  this.processors = processors ?? [];
1033
935
  this.json = json;
1034
936
  }
1035
- getHandlersAndProcessors() {
937
+ getHandlersAndProcessors(recordLevel) {
1036
938
  return {
1037
939
  handlers: this.handlers,
1038
940
  processors: this.processors
@@ -1079,20 +981,22 @@ class LoggerCLI extends Logger {
1079
981
  }
1080
982
  }
1081
983
  }
984
+ separator() {
985
+ console.log();
986
+ }
1082
987
  }
1083
988
 
1084
- /**
1085
- * listen to uncaughtException and unhandledRejection
1086
- * @param {Logger} [logger]
1087
- */
1088
- function listenUnhandledErrors(logger = new Logger("nightingale:listenUnhandledErrors", "UnhandledErrors")) {
1089
- process.on("uncaughtException", error => {
989
+ function listenUnhandledErrors(logger = new Logger(
990
+ "nightingale:listenUnhandledErrors",
991
+ "UnhandledErrors"
992
+ )) {
993
+ process.on("uncaughtException", (error) => {
1090
994
  logger.error(error, {
1091
995
  unhandled: true,
1092
996
  type: "uncaughtException"
1093
997
  });
1094
998
  });
1095
- process.on("unhandledRejection", error => {
999
+ process.on("unhandledRejection", (error) => {
1096
1000
  logger.error(error, {
1097
1001
  unhandled: true,
1098
1002
  type: "unhandledRejection"