nightingale 16.2.0 → 17.0.1
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.
- package/CHANGELOG.md +23 -0
- package/README.md +1 -1
- package/dist/definitions/debug/getDebugString.d.ts +2 -0
- package/dist/definitions/debug/getDebugString.d.ts.map +1 -0
- package/dist/definitions/debug/getDebugString.web.d.ts +2 -0
- package/dist/definitions/debug/getDebugString.web.d.ts.map +1 -0
- package/dist/definitions/formatter-utils/formatRecordToString.d.ts +1 -1
- package/dist/definitions/formatter-utils/formatRecordToString.d.ts.map +1 -1
- package/dist/definitions/formatter-utils/index.d.ts +1 -4
- package/dist/definitions/formatter-utils/index.d.ts.map +1 -1
- package/dist/definitions/formatters/BrowserConsoleFormatter.d.ts +3 -3
- package/dist/definitions/formatters/BrowserConsoleFormatter.d.ts.map +1 -1
- package/dist/definitions/formatters/JSONFormatter.d.ts.map +1 -1
- package/dist/definitions/handlers/BrowserConsoleHandler.d.ts +0 -1
- package/dist/definitions/handlers/BrowserConsoleHandler.d.ts.map +1 -1
- package/dist/definitions/handlers/ConsoleCLIHandler.d.ts +1 -0
- package/dist/definitions/handlers/ConsoleCLIHandler.d.ts.map +1 -1
- package/dist/definitions/handlers/ConsoleHandler.d.ts +2 -1
- package/dist/definitions/handlers/ConsoleHandler.d.ts.map +1 -1
- package/dist/definitions/handlers/defaultFormatter.d.ts +2 -0
- package/dist/definitions/handlers/defaultFormatter.d.ts.map +1 -0
- package/dist/definitions/handlers/defaultFormatter.target-node.d.ts +2 -0
- package/dist/definitions/handlers/defaultFormatter.target-node.d.ts.map +1 -0
- package/dist/definitions/loggers/LoggerCLI.d.ts +6 -1
- package/dist/definitions/loggers/LoggerCLI.d.ts.map +1 -1
- package/dist/definitions/loggers/LoggerCLI.test.d.ts +2 -0
- package/dist/definitions/loggers/LoggerCLI.test.d.ts.map +1 -0
- package/dist/definitions/outputs/cliConsoleOutput.d.ts +1 -1
- package/dist/definitions/outputs/cliConsoleOutput.d.ts.map +1 -1
- package/dist/definitions/outputs/consoleOutput.d.ts +1 -1
- package/dist/definitions/outputs/consoleOutput.d.ts.map +1 -1
- package/dist/definitions/outputs/consoleOutput.target-node.d.ts +3 -0
- package/dist/definitions/outputs/consoleOutput.target-node.d.ts.map +1 -0
- package/dist/index-browser.es.js +262 -356
- package/dist/index-browser.es.js.map +1 -1
- package/dist/index-node20.mjs +256 -366
- package/dist/index-node20.mjs.map +1 -1
- package/dist/index-react-native.es.js +992 -0
- package/dist/index-react-native.es.js.map +1 -0
- package/package.json +17 -12
- package/src/debug/getDebugString.ts +3 -0
- package/src/debug/getDebugString.web.ts +24 -0
- package/src/formatter-utils/formatObject.test.ts +1 -3
- package/src/formatter-utils/formatRecordToString.ts +2 -2
- package/src/formatter-utils/index.ts +1 -5
- package/src/formatters/ANSIFormatter.test.ts +1 -1
- package/src/formatters/BrowserConsoleFormatter.ts +4 -6
- package/src/formatters/HTMLFormatter.test.ts +2 -2
- package/src/formatters/JSONFormatter.test.ts +5 -5
- package/src/formatters/JSONFormatter.ts +19 -15
- package/src/formatters/MarkdownFormatter.test.ts +3 -1
- package/src/formatters/RawFormatter.test.ts +2 -2
- package/src/handlers/BrowserConsoleHandler.ts +1 -25
- package/src/handlers/ConsoleCLIHandler.ts +11 -2
- package/src/handlers/ConsoleHandler.ts +3 -11
- package/src/handlers/StringHandler.ts +1 -1
- package/src/handlers/defaultFormatter.target-node.ts +7 -0
- package/src/handlers/defaultFormatter.ts +3 -0
- package/src/loggers/LoggerCLI.test.ts +19 -0
- package/src/loggers/LoggerCLI.ts +22 -2
- package/src/outputs/cliConsoleOutput.ts +2 -9
- package/src/outputs/consoleOutput.target-node.ts +10 -0
- package/src/outputs/consoleOutput.ts +2 -10
package/dist/index-node20.mjs
CHANGED
|
@@ -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(
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
152
|
-
|
|
153
|
-
},
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
},
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
},
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
},
|
|
166
|
-
|
|
167
|
-
|
|
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 ===
|
|
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(
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
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}
|
|
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
|
-
|
|
459
|
-
|
|
460
|
-
|
|
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
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
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
|
-
|
|
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(
|
|
513
|
-
|
|
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(
|
|
531
|
-
key,
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
padding,
|
|
535
|
-
|
|
536
|
-
|
|
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(
|
|
561
|
-
key,
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
padding,
|
|
565
|
-
|
|
566
|
-
|
|
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(
|
|
590
|
-
key:
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
padding,
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
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(
|
|
621
|
-
key:
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
padding,
|
|
625
|
-
|
|
626
|
-
|
|
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
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
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(
|
|
663
|
-
|
|
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,
|
|
692
|
-
formatRecordObject("context", record.context,
|
|
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 =
|
|
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 =
|
|
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(
|
|
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(
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
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
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
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(
|
|
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(
|
|
903
|
-
|
|
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,37 @@ class BrowserConsoleFormatter {
|
|
|
909
811
|
}
|
|
910
812
|
format(record) {
|
|
911
813
|
const args = [];
|
|
912
|
-
const string = formatRecordToString(
|
|
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
|
-
|
|
921
|
-
|
|
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
|
-
|
|
942
|
-
const debugFromLocalStorage =
|
|
943
|
-
// eslint-disable-next-line unicorn/prefer-global-this, @typescript-eslint/no-unnecessary-condition
|
|
944
|
-
window.localStorage?.getItem("debug") || "";
|
|
945
|
-
if (!querystring) {
|
|
946
|
-
return debugFromLocalStorage;
|
|
947
|
-
}
|
|
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"));
|
|
953
|
-
return (debugFromLocalStorage ? `${debugFromLocalStorage},` : "") + debugFromQueryString;
|
|
842
|
+
return "";
|
|
954
843
|
}
|
|
955
844
|
|
|
956
|
-
// debug string can change any time (localStorage), so we need a new object each time.
|
|
957
845
|
const findDebugLevel$2 = (minLevel, key) => createFindDebugLevel(getDebugString())(minLevel, key);
|
|
958
846
|
const getDefaultTheme = () => {
|
|
959
847
|
try {
|
|
@@ -961,57 +849,63 @@ const getDefaultTheme = () => {
|
|
|
961
849
|
if (configInLocalStorage && configInLocalStorage === "dark") {
|
|
962
850
|
return configInLocalStorage;
|
|
963
851
|
}
|
|
964
|
-
} catch {
|
|
852
|
+
} catch {
|
|
853
|
+
}
|
|
965
854
|
return "light";
|
|
966
855
|
};
|
|
967
856
|
const createHandler = (theme = getDefaultTheme()) => {
|
|
968
857
|
const browserConsoleFormatter = new BrowserConsoleFormatter(theme);
|
|
969
|
-
return record => {
|
|
858
|
+
return (record) => {
|
|
970
859
|
consoleOutput(browserConsoleFormatter.format(record), record);
|
|
971
860
|
};
|
|
972
861
|
};
|
|
973
862
|
class BrowserConsoleHandler {
|
|
974
|
-
minLevel = 0;
|
|
975
863
|
constructor(minLevel, options = {}) {
|
|
864
|
+
this.minLevel = 0;
|
|
976
865
|
this.isHandling = (level, key) => level >= findDebugLevel$2(minLevel, key);
|
|
977
866
|
this.handle = createHandler(options.theme);
|
|
978
867
|
}
|
|
979
868
|
}
|
|
980
869
|
|
|
981
870
|
const defaultFormatter = !process.stdout.isTTY && process.env.NIGHTINGALE_CONSOLE_FORMATTER !== "ansi" ? JSONFormatter.format : ANSIFormatter.format;
|
|
871
|
+
|
|
982
872
|
const createHandle$1 = (formatter = defaultFormatter, output = consoleOutput) => {
|
|
983
|
-
return record => {
|
|
873
|
+
return (record) => {
|
|
984
874
|
output(formatter(record), record);
|
|
985
875
|
};
|
|
986
876
|
};
|
|
987
877
|
const findDebugLevel$1 = createFindDebugLevel(process.env.DEBUG);
|
|
988
878
|
class ConsoleHandler {
|
|
989
|
-
minLevel = Level.ALL;
|
|
990
879
|
constructor(minLevel, options = {}) {
|
|
880
|
+
this.minLevel = Level.ALL;
|
|
991
881
|
this.minLevel = minLevel;
|
|
992
882
|
this.isHandling = (level, key) => level >= findDebugLevel$1(minLevel, key);
|
|
993
883
|
this.handle = createHandle$1(options.formatter, options.output);
|
|
994
884
|
}
|
|
995
885
|
}
|
|
996
886
|
|
|
997
|
-
/* eslint-disable no-console */
|
|
998
887
|
function cliConsoleOutput(param, record) {
|
|
999
|
-
console[record.level >= Level.ERROR ? "error" : "log"](param);
|
|
888
|
+
console[record.level >= Level.ERROR ? "error" : "log"](...param);
|
|
1000
889
|
}
|
|
1001
890
|
|
|
1002
891
|
const createHandle = ({
|
|
1003
|
-
json
|
|
892
|
+
json,
|
|
893
|
+
noColor = process.env.NO_COLOR === "1" || process.env.NO_COLOR === "true"
|
|
1004
894
|
}) => {
|
|
1005
|
-
const formatter =
|
|
895
|
+
const formatter = (() => {
|
|
896
|
+
if (json) return JSONFormatter.format;
|
|
897
|
+
if (noColor) return RawFormatter.format;
|
|
898
|
+
return ANSIFormatter.format;
|
|
899
|
+
})();
|
|
1006
900
|
const output = json ? consoleOutput : cliConsoleOutput;
|
|
1007
|
-
return record => {
|
|
901
|
+
return (record) => {
|
|
1008
902
|
output(formatter(record), record);
|
|
1009
903
|
};
|
|
1010
904
|
};
|
|
1011
905
|
const findDebugLevel = createFindDebugLevel(process.env.DEBUG);
|
|
1012
906
|
class ConsoleCLIHandler {
|
|
1013
|
-
minLevel = Level.ALL;
|
|
1014
907
|
constructor(minLevel, options = {}) {
|
|
908
|
+
this.minLevel = Level.ALL;
|
|
1015
909
|
this.minLevel = minLevel;
|
|
1016
910
|
this.isHandling = (level, key) => level >= findDebugLevel(minLevel, key);
|
|
1017
911
|
this.handle = createHandle(options);
|
|
@@ -1019,20 +913,14 @@ class ConsoleCLIHandler {
|
|
|
1019
913
|
}
|
|
1020
914
|
|
|
1021
915
|
class LoggerCLI extends Logger {
|
|
1022
|
-
processors =
|
|
1023
|
-
constructor(key, {
|
|
1024
|
-
displayName,
|
|
1025
|
-
processors,
|
|
1026
|
-
json = false
|
|
1027
|
-
} = {}) {
|
|
916
|
+
constructor(key, { displayName, processors, json = false, noColor } = {}) {
|
|
1028
917
|
super(key, displayName);
|
|
1029
|
-
this.
|
|
1030
|
-
|
|
1031
|
-
})];
|
|
918
|
+
this.processors = [];
|
|
919
|
+
this.handlers = [new ConsoleCLIHandler(Level$1.INFO, { json, noColor })];
|
|
1032
920
|
this.processors = processors ?? [];
|
|
1033
921
|
this.json = json;
|
|
1034
922
|
}
|
|
1035
|
-
getHandlersAndProcessors() {
|
|
923
|
+
getHandlersAndProcessors(recordLevel) {
|
|
1036
924
|
return {
|
|
1037
925
|
handlers: this.handlers,
|
|
1038
926
|
processors: this.processors
|
|
@@ -1079,20 +967,22 @@ class LoggerCLI extends Logger {
|
|
|
1079
967
|
}
|
|
1080
968
|
}
|
|
1081
969
|
}
|
|
970
|
+
separator() {
|
|
971
|
+
console.log();
|
|
972
|
+
}
|
|
1082
973
|
}
|
|
1083
974
|
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
process.on("uncaughtException", error => {
|
|
975
|
+
function listenUnhandledErrors(logger = new Logger(
|
|
976
|
+
"nightingale:listenUnhandledErrors",
|
|
977
|
+
"UnhandledErrors"
|
|
978
|
+
)) {
|
|
979
|
+
process.on("uncaughtException", (error) => {
|
|
1090
980
|
logger.error(error, {
|
|
1091
981
|
unhandled: true,
|
|
1092
982
|
type: "uncaughtException"
|
|
1093
983
|
});
|
|
1094
984
|
});
|
|
1095
|
-
process.on("unhandledRejection", error => {
|
|
985
|
+
process.on("unhandledRejection", (error) => {
|
|
1096
986
|
logger.error(error, {
|
|
1097
987
|
unhandled: true,
|
|
1098
988
|
type: "unhandledRejection"
|