nightingale 16.1.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.
- package/CHANGELOG.md +23 -0
- package/README.md +10 -1
- package/dist/definitions/formatter-utils/formatObject.d.ts.map +1 -1
- 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/formatStyles.d.ts +14 -0
- package/dist/definitions/formatter-utils/formatStyles.d.ts.map +1 -0
- package/dist/definitions/formatter-utils/index.d.ts +1 -4
- package/dist/definitions/formatter-utils/index.d.ts.map +1 -1
- package/dist/definitions/formatter-utils/styleToHexColor.d.ts +0 -2
- package/dist/definitions/formatter-utils/styleToHexColor.d.ts.map +1 -1
- package/dist/definitions/formatter-utils/styleToHtmlStyle.d.ts +4 -8
- package/dist/definitions/formatter-utils/styleToHtmlStyle.d.ts.map +1 -1
- package/dist/definitions/formatters/ANSIFormatter.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/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/index.d.ts +1 -0
- package/dist/definitions/index.d.ts.map +1 -1
- 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 +358 -379
- package/dist/index-browser.es.js.map +1 -1
- package/dist/index-node20.mjs +362 -384
- package/dist/index-node20.mjs.map +1 -1
- package/package.json +14 -12
- package/src/formatter-utils/formatObject.test.ts +67 -6
- package/src/formatter-utils/formatObject.ts +86 -14
- package/src/formatter-utils/formatRecordToString.ts +4 -4
- package/src/formatter-utils/formatStyles.ts +15 -0
- package/src/formatter-utils/index.ts +1 -5
- package/src/formatter-utils/styleToHexColor.ts +0 -2
- package/src/formatter-utils/styleToHtmlStyle.ts +1 -8
- package/src/formatters/ANSIFormatter.test.ts +2 -2
- package/src/formatters/ANSIFormatter.ts +1 -4
- 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/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/index.ts +1 -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-browser.es.js
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,32 +111,24 @@ 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 = {
|
|
125
|
-
orange: "ff5f00"
|
|
126
|
-
grayLight: "808080",
|
|
127
|
-
"gray-light": "808080"
|
|
125
|
+
orange: "ff5f00"
|
|
128
126
|
};
|
|
129
127
|
|
|
130
128
|
const styleToHtmlStyleThemeLight = {
|
|
131
129
|
// text style
|
|
132
|
-
bold: {
|
|
133
|
-
|
|
134
|
-
close: "font-weight: normal"
|
|
135
|
-
},
|
|
136
|
-
italic: {
|
|
137
|
-
open: "font-style: italic",
|
|
138
|
-
close: "font-style: normal"
|
|
139
|
-
},
|
|
130
|
+
bold: { open: "font-weight: bold", close: "font-weight: normal" },
|
|
131
|
+
italic: { open: "font-style: italic", close: "font-style: normal" },
|
|
140
132
|
underline: {
|
|
141
133
|
open: "text-decoration: underline",
|
|
142
134
|
close: "text-decoration: none"
|
|
@@ -149,85 +141,27 @@ const styleToHtmlStyleThemeLight = {
|
|
|
149
141
|
open: "text-decoration: line-through",
|
|
150
142
|
close: "text-decoration: none"
|
|
151
143
|
},
|
|
152
|
-
black: {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
},
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
},
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
},
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
},
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
close: "color: currentcolor"
|
|
171
|
-
},
|
|
172
|
-
magenta: {
|
|
173
|
-
open: "color: #ff00a0",
|
|
174
|
-
close: "color: currentcolor"
|
|
175
|
-
},
|
|
176
|
-
cyan: {
|
|
177
|
-
open: "color: #00cfd8",
|
|
178
|
-
close: "color: currentcolor"
|
|
179
|
-
},
|
|
180
|
-
white: {
|
|
181
|
-
open: "color: white",
|
|
182
|
-
close: "color: currentcolor"
|
|
183
|
-
},
|
|
184
|
-
gray: {
|
|
185
|
-
open: "color: gray",
|
|
186
|
-
close: "color: currentcolor"
|
|
187
|
-
},
|
|
188
|
-
bgBlack: {
|
|
189
|
-
open: "background: black",
|
|
190
|
-
close: "background: initial"
|
|
191
|
-
},
|
|
192
|
-
bgRed: {
|
|
193
|
-
open: "background: #ff0020",
|
|
194
|
-
close: "background: initial"
|
|
195
|
-
},
|
|
196
|
-
bgGreen: {
|
|
197
|
-
open: "background: #00b317",
|
|
198
|
-
close: "background: initial"
|
|
199
|
-
},
|
|
200
|
-
bgYellow: {
|
|
201
|
-
open: "background: #ffcc00",
|
|
202
|
-
close: "background: initial"
|
|
203
|
-
},
|
|
204
|
-
bgBlue: {
|
|
205
|
-
open: "background: #00a0ff",
|
|
206
|
-
close: "background: initial"
|
|
207
|
-
},
|
|
208
|
-
bgMagenta: {
|
|
209
|
-
open: "background: #ff00a0",
|
|
210
|
-
close: "background: initial"
|
|
211
|
-
},
|
|
212
|
-
bgCyan: {
|
|
213
|
-
open: "background: #00cfd8",
|
|
214
|
-
close: "background: initial"
|
|
215
|
-
},
|
|
216
|
-
bgWhite: {
|
|
217
|
-
open: "background: white",
|
|
218
|
-
close: "background: initial"
|
|
219
|
-
},
|
|
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" },
|
|
220
162
|
orange: {
|
|
221
163
|
open: `color: #${styleToHexColor.orange}`,
|
|
222
164
|
close: "color: currentcolor"
|
|
223
|
-
},
|
|
224
|
-
grayLight: {
|
|
225
|
-
open: `color: #${styleToHexColor.grayLight}`,
|
|
226
|
-
close: "color: currentcolor"
|
|
227
|
-
},
|
|
228
|
-
"gray-light": {
|
|
229
|
-
open: `color: #${styleToHexColor.grayLight}`,
|
|
230
|
-
close: "color: currentcolor"
|
|
231
165
|
}
|
|
232
166
|
};
|
|
233
167
|
const styleToHtmlStyleThemeDark = {
|
|
@@ -236,13 +170,22 @@ const styleToHtmlStyleThemeDark = {
|
|
|
236
170
|
bgBlack: styleToHtmlStyleThemeLight.bgWhite,
|
|
237
171
|
white: styleToHtmlStyleThemeLight.black,
|
|
238
172
|
bgWhite: styleToHtmlStyleThemeLight.bgBlack,
|
|
239
|
-
gray: {
|
|
240
|
-
open: "color: lightgray",
|
|
241
|
-
close: "color: currentcolor"
|
|
242
|
-
}
|
|
173
|
+
gray: { open: "color: lightgray", close: "color: currentcolor" }
|
|
243
174
|
};
|
|
244
175
|
|
|
245
|
-
|
|
176
|
+
const formatStyles = {
|
|
177
|
+
bigint: ["yellow", "bold"],
|
|
178
|
+
boolean: ["green"],
|
|
179
|
+
date: ["magenta"],
|
|
180
|
+
error: ["red"],
|
|
181
|
+
function: ["blue"],
|
|
182
|
+
null: ["bold"],
|
|
183
|
+
number: ["yellow"],
|
|
184
|
+
regexp: ["magenta"],
|
|
185
|
+
string: ["orange"],
|
|
186
|
+
symbol: ["magenta"],
|
|
187
|
+
undefined: ["dim"]
|
|
188
|
+
};
|
|
246
189
|
|
|
247
190
|
const noStyleFn = (styles, value) => value;
|
|
248
191
|
function tryStringify(arg) {
|
|
@@ -252,39 +195,93 @@ function tryStringify(arg) {
|
|
|
252
195
|
return "[Circular]";
|
|
253
196
|
}
|
|
254
197
|
}
|
|
255
|
-
const sameRawFormattedValue = value => ({
|
|
198
|
+
const sameRawFormattedValue = (value) => ({
|
|
256
199
|
stringValue: value,
|
|
257
200
|
formattedValue: value
|
|
258
201
|
});
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
202
|
+
const numericSeparator = "_";
|
|
203
|
+
const formatIntegerValue = (integerAsString) => {
|
|
204
|
+
let result = "";
|
|
205
|
+
let i = integerAsString.length;
|
|
206
|
+
const start = integerAsString.startsWith("-") ? 1 : 0;
|
|
207
|
+
for (; i >= start + 4; i -= 3) {
|
|
208
|
+
result = `${numericSeparator}${integerAsString.slice(i - 3, i)}${result}`;
|
|
209
|
+
}
|
|
210
|
+
return i === integerAsString.length ? integerAsString : `${integerAsString.slice(0, i)}${result}`;
|
|
211
|
+
};
|
|
212
|
+
const formatDecimalIntegerValue = (integerAsString) => {
|
|
213
|
+
let result = "";
|
|
214
|
+
let i = 0;
|
|
215
|
+
for (; i < integerAsString.length - 3; i += 3) {
|
|
216
|
+
result += `${integerAsString.slice(i, i + 3)}${numericSeparator}`;
|
|
217
|
+
}
|
|
218
|
+
return i === 0 ? integerAsString : `${result}${integerAsString.slice(i)}`;
|
|
219
|
+
};
|
|
220
|
+
const formatNumberValue = (value) => {
|
|
221
|
+
if (Number.isNaN(value)) {
|
|
222
|
+
return "NaN";
|
|
223
|
+
}
|
|
224
|
+
if (value === Number.POSITIVE_INFINITY) {
|
|
225
|
+
return "+Infinity";
|
|
226
|
+
}
|
|
227
|
+
if (value === Number.NEGATIVE_INFINITY) {
|
|
228
|
+
return "-Infinity";
|
|
229
|
+
}
|
|
230
|
+
if (value === Number.EPSILON) {
|
|
231
|
+
return "Epsilon";
|
|
232
|
+
}
|
|
233
|
+
if (Object.is(value, -0)) {
|
|
234
|
+
return "-0";
|
|
235
|
+
}
|
|
236
|
+
const integer = Math.trunc(value);
|
|
237
|
+
const integerAsString = integer.toString();
|
|
238
|
+
if (integer === value) {
|
|
239
|
+
if (integerAsString.includes("e")) {
|
|
240
|
+
return integerAsString;
|
|
241
|
+
}
|
|
242
|
+
return formatIntegerValue(integerAsString);
|
|
243
|
+
} else {
|
|
244
|
+
return `${formatIntegerValue(integerAsString)}.${formatDecimalIntegerValue(String(value).slice(integerAsString.length + 1))}`;
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
function internalFormatValue(value, styleFn, styles, { padding, depth, maxDepth, objects }) {
|
|
265
248
|
const typeofValue = typeof value;
|
|
266
249
|
if (!styles) {
|
|
267
|
-
if (value
|
|
268
|
-
styles = ["
|
|
250
|
+
if (value === null) {
|
|
251
|
+
styles = ["bold"];
|
|
269
252
|
} else {
|
|
270
253
|
switch (typeofValue) {
|
|
271
|
-
case "
|
|
272
|
-
styles =
|
|
254
|
+
case "bigint":
|
|
255
|
+
styles = formatStyles.bigint;
|
|
273
256
|
break;
|
|
274
257
|
case "boolean":
|
|
275
|
-
styles =
|
|
258
|
+
styles = formatStyles.boolean;
|
|
276
259
|
break;
|
|
277
|
-
case "
|
|
278
|
-
styles =
|
|
260
|
+
case "undefined":
|
|
261
|
+
styles = formatStyles.undefined;
|
|
279
262
|
break;
|
|
280
|
-
case "
|
|
281
|
-
styles =
|
|
263
|
+
case "number":
|
|
264
|
+
styles = formatStyles.number;
|
|
282
265
|
break;
|
|
283
266
|
case "string":
|
|
284
|
-
styles =
|
|
267
|
+
styles = formatStyles.string;
|
|
285
268
|
break;
|
|
286
269
|
case "symbol":
|
|
287
|
-
styles =
|
|
270
|
+
styles = formatStyles.symbol;
|
|
271
|
+
break;
|
|
272
|
+
case "object":
|
|
273
|
+
if (value instanceof Date) {
|
|
274
|
+
styles = formatStyles.date;
|
|
275
|
+
}
|
|
276
|
+
if (value instanceof RegExp) {
|
|
277
|
+
styles = formatStyles.regexp;
|
|
278
|
+
}
|
|
279
|
+
if (value instanceof Error) {
|
|
280
|
+
styles = formatStyles.error;
|
|
281
|
+
}
|
|
282
|
+
break;
|
|
283
|
+
case "function":
|
|
284
|
+
styles = formatStyles.function;
|
|
288
285
|
break;
|
|
289
286
|
}
|
|
290
287
|
}
|
|
@@ -292,21 +289,27 @@ function internalFormatValue(value, styleFn, styles, {
|
|
|
292
289
|
let stringValue;
|
|
293
290
|
if (value === null) {
|
|
294
291
|
stringValue = "null";
|
|
295
|
-
} else if (value ===
|
|
292
|
+
} else if (value === void 0) {
|
|
296
293
|
stringValue = "undefined";
|
|
294
|
+
} else if (typeofValue === "number") {
|
|
295
|
+
stringValue = formatNumberValue(value);
|
|
297
296
|
} else if (typeofValue === "boolean") {
|
|
298
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
299
297
|
stringValue = value.toString();
|
|
300
298
|
} else if (value.constructor === Object) {
|
|
301
299
|
if (depth >= maxDepth) {
|
|
302
300
|
stringValue = "{Object...}";
|
|
303
301
|
} else {
|
|
304
|
-
return internalFormatObject(
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
302
|
+
return internalFormatObject(
|
|
303
|
+
value,
|
|
304
|
+
styleFn,
|
|
305
|
+
void 0,
|
|
306
|
+
{
|
|
307
|
+
padding,
|
|
308
|
+
depth: depth + 1,
|
|
309
|
+
maxDepth,
|
|
310
|
+
objects
|
|
311
|
+
}
|
|
312
|
+
);
|
|
310
313
|
}
|
|
311
314
|
} else if (Array.isArray(value)) {
|
|
312
315
|
if (depth >= maxDepth) {
|
|
@@ -321,7 +324,8 @@ function internalFormatValue(value, styleFn, styles, {
|
|
|
321
324
|
}
|
|
322
325
|
} else if (value instanceof Error) {
|
|
323
326
|
const stack = value.stack;
|
|
324
|
-
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 || ""}`;
|
|
325
329
|
} else if (value instanceof Map) {
|
|
326
330
|
const name = value.constructor.name;
|
|
327
331
|
if (depth >= maxDepth) {
|
|
@@ -335,7 +339,7 @@ function internalFormatValue(value, styleFn, styles, {
|
|
|
335
339
|
});
|
|
336
340
|
}
|
|
337
341
|
} else if (typeofValue === "bigint") {
|
|
338
|
-
stringValue = value.toString()
|
|
342
|
+
stringValue = `[BigInt: ${value.toString()}]`;
|
|
339
343
|
} else if (typeofValue === "symbol") {
|
|
340
344
|
stringValue = value.toString();
|
|
341
345
|
} else if (value instanceof Set) {
|
|
@@ -354,6 +358,12 @@ function internalFormatValue(value, styleFn, styles, {
|
|
|
354
358
|
stringValue = "{WeakMap...}";
|
|
355
359
|
} else if (value instanceof WeakSet) {
|
|
356
360
|
stringValue = "{WeakSet...}";
|
|
361
|
+
} else if (value instanceof Date) {
|
|
362
|
+
stringValue = `[Date: ${value.toISOString()}]`;
|
|
363
|
+
} else if (value instanceof RegExp) {
|
|
364
|
+
stringValue = `[RegExp: ${value.toString()}]`;
|
|
365
|
+
} else if (typeof value === "function") {
|
|
366
|
+
stringValue = `[Function: ${value.name}]`;
|
|
357
367
|
} else {
|
|
358
368
|
stringValue = tryStringify(value);
|
|
359
369
|
}
|
|
@@ -364,34 +374,28 @@ function internalFormatValue(value, styleFn, styles, {
|
|
|
364
374
|
};
|
|
365
375
|
}
|
|
366
376
|
const separator = ",";
|
|
367
|
-
const internalFormatKey = (key, styleFn) => {
|
|
377
|
+
const internalFormatKey = (key, styleFn, internalFormatParams) => {
|
|
368
378
|
return {
|
|
369
379
|
stringKey: `${key}: `,
|
|
370
|
-
formattedKey: `${styleFn(["
|
|
380
|
+
formattedKey: `${styleFn(["dim", "bold"], `${key}:`)} `
|
|
371
381
|
};
|
|
372
382
|
};
|
|
373
|
-
const internalNoKey = () => {
|
|
374
|
-
return {
|
|
375
|
-
stringKey: "",
|
|
376
|
-
formattedKey: ""
|
|
377
|
-
};
|
|
383
|
+
const internalNoKey = (key, styleFn, internalFormatParams) => {
|
|
384
|
+
return { stringKey: "", formattedKey: "" };
|
|
378
385
|
};
|
|
379
386
|
const internalFormatMapKey = (key, styleFn, internalFormatParams) => {
|
|
380
|
-
const {
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
387
|
+
const { stringValue, formattedValue } = internalFormatValue(
|
|
388
|
+
key,
|
|
389
|
+
noStyleFn,
|
|
390
|
+
void 0,
|
|
391
|
+
internalFormatParams
|
|
392
|
+
);
|
|
384
393
|
return {
|
|
385
394
|
stringKey: `${stringValue} => `,
|
|
386
|
-
formattedKey: `${styleFn(["
|
|
395
|
+
formattedKey: `${styleFn(["dim", "bold"], `${formattedValue}:`)} `
|
|
387
396
|
};
|
|
388
397
|
};
|
|
389
|
-
const internalFormatIterator = (values, styleFn, objectStyles, {
|
|
390
|
-
padding,
|
|
391
|
-
depth,
|
|
392
|
-
maxDepth,
|
|
393
|
-
objects
|
|
394
|
-
}, {
|
|
398
|
+
const internalFormatIterator = (values, styleFn, objectStyles, { padding, depth, maxDepth, objects }, {
|
|
395
399
|
prefix,
|
|
396
400
|
suffix,
|
|
397
401
|
prefixSuffixSpace = " ",
|
|
@@ -400,48 +404,52 @@ const internalFormatIterator = (values, styleFn, objectStyles, {
|
|
|
400
404
|
let breakLine = false;
|
|
401
405
|
const formattedSeparator = () => styleFn(["gray"], separator);
|
|
402
406
|
const valuesMaxIndex = values.length - 1;
|
|
403
|
-
const formattedValues = values.map(
|
|
404
|
-
key,
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
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
|
+
};
|
|
427
439
|
}
|
|
428
|
-
|
|
429
|
-
stringValue: stringKey + stringValue + (index === valuesMaxIndex ? "" : separator),
|
|
430
|
-
formattedValue: formattedKey + formattedValue + (index === valuesMaxIndex ? "" : formattedSeparator())
|
|
431
|
-
// note: we need to format the separator for each values for browser-formatter
|
|
432
|
-
};
|
|
433
|
-
});
|
|
440
|
+
);
|
|
434
441
|
return {
|
|
435
|
-
stringValue: prefix + formattedValues.map(
|
|
436
|
-
|
|
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}`
|
|
437
450
|
};
|
|
438
451
|
};
|
|
439
|
-
function internalFormatObject(object, styleFn, objectStyles, {
|
|
440
|
-
padding,
|
|
441
|
-
depth,
|
|
442
|
-
maxDepth,
|
|
443
|
-
objects
|
|
444
|
-
}) {
|
|
452
|
+
function internalFormatObject(object, styleFn, objectStyles, { padding, depth, maxDepth, objects }) {
|
|
445
453
|
if (objects.has(object)) {
|
|
446
454
|
return sameRawFormattedValue("{Circular Object}");
|
|
447
455
|
}
|
|
@@ -450,28 +458,17 @@ function internalFormatObject(object, styleFn, objectStyles, {
|
|
|
450
458
|
return sameRawFormattedValue("{}");
|
|
451
459
|
}
|
|
452
460
|
objects.add(object);
|
|
453
|
-
const result = internalFormatIterator(
|
|
454
|
-
key,
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
padding,
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
objects
|
|
461
|
-
}, {
|
|
462
|
-
prefix: "{",
|
|
463
|
-
suffix: "}",
|
|
464
|
-
formatKey: internalFormatKey
|
|
465
|
-
});
|
|
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
|
+
);
|
|
466
468
|
objects.delete(object);
|
|
467
469
|
return result;
|
|
468
470
|
}
|
|
469
|
-
function internalFormatMap(name, map, styleFn, {
|
|
470
|
-
padding,
|
|
471
|
-
depth,
|
|
472
|
-
maxDepth,
|
|
473
|
-
objects
|
|
474
|
-
}) {
|
|
471
|
+
function internalFormatMap(name, map, styleFn, { padding, depth, maxDepth, objects }) {
|
|
475
472
|
if (objects.has(map)) {
|
|
476
473
|
return sameRawFormattedValue(`{Circular ${name}}`);
|
|
477
474
|
}
|
|
@@ -480,28 +477,17 @@ function internalFormatMap(name, map, styleFn, {
|
|
|
480
477
|
return sameRawFormattedValue(`${name} {}`);
|
|
481
478
|
}
|
|
482
479
|
objects.add(map);
|
|
483
|
-
const result = internalFormatIterator(
|
|
484
|
-
key,
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
padding,
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
objects
|
|
491
|
-
}, {
|
|
492
|
-
prefix: `${name} {`,
|
|
493
|
-
suffix: "}",
|
|
494
|
-
formatKey: internalFormatMapKey
|
|
495
|
-
});
|
|
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
|
+
);
|
|
496
487
|
objects.delete(map);
|
|
497
488
|
return result;
|
|
498
489
|
}
|
|
499
|
-
function internalFormatArray(array, styleFn, {
|
|
500
|
-
padding,
|
|
501
|
-
depth,
|
|
502
|
-
maxDepth,
|
|
503
|
-
objects
|
|
504
|
-
}) {
|
|
490
|
+
function internalFormatArray(array, styleFn, { padding, depth, maxDepth, objects }) {
|
|
505
491
|
if (objects.has(array)) {
|
|
506
492
|
return sameRawFormattedValue("{Circular Array}");
|
|
507
493
|
}
|
|
@@ -509,29 +495,22 @@ function internalFormatArray(array, styleFn, {
|
|
|
509
495
|
return sameRawFormattedValue("[]");
|
|
510
496
|
}
|
|
511
497
|
objects.add(array);
|
|
512
|
-
const result = internalFormatIterator(
|
|
513
|
-
key:
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
padding,
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
formatKey: internalNoKey
|
|
525
|
-
});
|
|
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
|
+
);
|
|
526
510
|
objects.delete(array);
|
|
527
511
|
return result;
|
|
528
512
|
}
|
|
529
|
-
function internalFormatSet(name, set, styleFn, {
|
|
530
|
-
padding,
|
|
531
|
-
depth,
|
|
532
|
-
maxDepth,
|
|
533
|
-
objects
|
|
534
|
-
}) {
|
|
513
|
+
function internalFormatSet(name, set, styleFn, { padding, depth, maxDepth, objects }) {
|
|
535
514
|
if (objects.has(set)) {
|
|
536
515
|
return sameRawFormattedValue(`{Circular ${name}}`);
|
|
537
516
|
}
|
|
@@ -540,34 +519,28 @@ function internalFormatSet(name, set, styleFn, {
|
|
|
540
519
|
return sameRawFormattedValue(`${name} []`);
|
|
541
520
|
}
|
|
542
521
|
objects.add(set);
|
|
543
|
-
const result = internalFormatIterator(
|
|
544
|
-
key:
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
padding,
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
objects
|
|
551
|
-
}, {
|
|
552
|
-
prefix: `${name} [`,
|
|
553
|
-
suffix: "]",
|
|
554
|
-
formatKey: internalNoKey
|
|
555
|
-
});
|
|
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
|
+
);
|
|
556
529
|
objects.delete(set);
|
|
557
530
|
return result;
|
|
558
531
|
}
|
|
559
|
-
function formatObject(object, styleFn = noStyleFn, objectStyles, {
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
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
|
+
);
|
|
571
544
|
if (result === "{}") {
|
|
572
545
|
return "";
|
|
573
546
|
}
|
|
@@ -577,13 +550,14 @@ function formatObject(object, styleFn = noStyleFn, objectStyles, {
|
|
|
577
550
|
function formatRecordToString(record, style) {
|
|
578
551
|
const parts = [];
|
|
579
552
|
if (record.displayName) {
|
|
580
|
-
parts.push(style(["
|
|
553
|
+
parts.push(style(["dim"], record.displayName));
|
|
581
554
|
} else if (record.key) {
|
|
582
|
-
parts.push(style(["
|
|
555
|
+
parts.push(style(["dim"], record.key));
|
|
583
556
|
}
|
|
584
557
|
if (record.datetime) {
|
|
585
|
-
parts.push(
|
|
586
|
-
|
|
558
|
+
parts.push(
|
|
559
|
+
style(["gray", "bold"], record.datetime.toTimeString().split(" ", 2)[0])
|
|
560
|
+
);
|
|
587
561
|
}
|
|
588
562
|
let message = record.symbol || levelToSymbol[record.level] || "";
|
|
589
563
|
const styles = record.styles || levelToStyles[record.level];
|
|
@@ -611,24 +585,23 @@ function formatRecordToString(record, style) {
|
|
|
611
585
|
parts.push(stringObject);
|
|
612
586
|
};
|
|
613
587
|
formatRecordObject("metadata", record.metadata, record.metadataStyles);
|
|
614
|
-
formatRecordObject("extra", record.extra,
|
|
615
|
-
formatRecordObject("context", record.context,
|
|
616
|
-
return parts.join(" ");
|
|
588
|
+
formatRecordObject("extra", record.extra, void 0);
|
|
589
|
+
formatRecordObject("context", record.context, void 0);
|
|
590
|
+
return [parts.join(" ")];
|
|
617
591
|
}
|
|
618
592
|
|
|
619
|
-
/* eslint-disable complexity */
|
|
620
593
|
const specialRegexpChars = /[$()+.?[\\\]^{|}]/;
|
|
621
|
-
const createTestFunctionFromRegexp = regexp => string => regexp.test(string);
|
|
622
|
-
const createTestFunctionFromRegexpString = value => {
|
|
594
|
+
const createTestFunctionFromRegexp = (regexp) => (string) => regexp.test(string);
|
|
595
|
+
const createTestFunctionFromRegexpString = (value) => {
|
|
623
596
|
if (!value.endsWith("/")) throw new Error("Invalid RegExp DEBUG value");
|
|
624
597
|
return createTestFunctionFromRegexp(new RegExp(value.slice(1, -1)));
|
|
625
598
|
};
|
|
626
|
-
const createTestFunctionFromValue = value => {
|
|
599
|
+
const createTestFunctionFromValue = (value) => {
|
|
627
600
|
if (value.endsWith(":*")) {
|
|
628
601
|
value = value.slice(0, -2);
|
|
629
|
-
return string => string.startsWith(value);
|
|
602
|
+
return (string) => string.startsWith(value);
|
|
630
603
|
}
|
|
631
|
-
return string => string === value;
|
|
604
|
+
return (string) => string === value;
|
|
632
605
|
};
|
|
633
606
|
function createFindDebugLevel(debugValue) {
|
|
634
607
|
let isWildcard = false;
|
|
@@ -637,21 +610,23 @@ function createFindDebugLevel(debugValue) {
|
|
|
637
610
|
if (!Array.isArray(debugValue)) {
|
|
638
611
|
if (debugValue instanceof RegExp) {
|
|
639
612
|
debugValues.push(createTestFunctionFromRegexp(debugValue));
|
|
640
|
-
debugValue =
|
|
613
|
+
debugValue = void 0;
|
|
641
614
|
} else if (debugValue) {
|
|
642
615
|
debugValue = debugValue.trim();
|
|
643
616
|
if (debugValue.startsWith("/")) {
|
|
644
617
|
debugValues.push(createTestFunctionFromRegexpString(debugValue));
|
|
645
|
-
debugValue =
|
|
618
|
+
debugValue = void 0;
|
|
646
619
|
} else {
|
|
647
620
|
debugValue = debugValue.split(/[\s,]+/);
|
|
648
621
|
}
|
|
649
622
|
}
|
|
650
623
|
}
|
|
651
624
|
if (debugValue) {
|
|
652
|
-
debugValue.forEach(value => {
|
|
625
|
+
debugValue.forEach((value) => {
|
|
653
626
|
if (specialRegexpChars.test(value)) {
|
|
654
|
-
throw new Error(
|
|
627
|
+
throw new Error(
|
|
628
|
+
`Invalid debug value: "${value}" (contains special chars)`
|
|
629
|
+
);
|
|
655
630
|
}
|
|
656
631
|
if (!value) return;
|
|
657
632
|
if (value === "*") {
|
|
@@ -669,18 +644,18 @@ function createFindDebugLevel(debugValue) {
|
|
|
669
644
|
if (skips.length === 0) {
|
|
670
645
|
return () => Level.ALL;
|
|
671
646
|
} else {
|
|
672
|
-
return (minLevel, key) => skips.some(skip => skip(key)) ? minLevel : Level.ALL;
|
|
647
|
+
return (minLevel, key) => skips.some((skip) => skip(key)) ? minLevel : Level.ALL;
|
|
673
648
|
}
|
|
674
649
|
}
|
|
675
650
|
if (debugValues.length === 0) {
|
|
676
|
-
return minLevel => minLevel;
|
|
651
|
+
return (minLevel) => minLevel;
|
|
677
652
|
}
|
|
678
653
|
return (minLevel, key) => {
|
|
679
654
|
if (minLevel === Level.ALL || !key) {
|
|
680
655
|
return minLevel;
|
|
681
656
|
}
|
|
682
|
-
if (debugValues.some(dv => dv(key))) {
|
|
683
|
-
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;
|
|
684
659
|
}
|
|
685
660
|
return minLevel;
|
|
686
661
|
};
|
|
@@ -699,8 +674,6 @@ function style$3(styles, string) {
|
|
|
699
674
|
if (!styles || styles.length === 0 || !string) {
|
|
700
675
|
return string;
|
|
701
676
|
}
|
|
702
|
-
|
|
703
|
-
// eslint-disable-next-line unicorn/no-array-reduce
|
|
704
677
|
return styles.reduce((part, styleName) => {
|
|
705
678
|
switch (styleName) {
|
|
706
679
|
case "bold":
|
|
@@ -709,8 +682,6 @@ function style$3(styles, string) {
|
|
|
709
682
|
return `_${part}_`;
|
|
710
683
|
case "strikethrough":
|
|
711
684
|
return `~${part}~`;
|
|
712
|
-
|
|
713
|
-
// no default
|
|
714
685
|
}
|
|
715
686
|
return part;
|
|
716
687
|
}, string);
|
|
@@ -725,39 +696,42 @@ function map2object(map) {
|
|
|
725
696
|
const object = {};
|
|
726
697
|
map.forEach((value, key) => {
|
|
727
698
|
if (typeof key === "object") {
|
|
728
|
-
// ignore key
|
|
729
699
|
return;
|
|
730
700
|
}
|
|
731
|
-
|
|
732
|
-
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
733
701
|
object[String(key)] = value;
|
|
734
702
|
});
|
|
735
703
|
return object;
|
|
736
704
|
}
|
|
737
705
|
function stringify(value, space) {
|
|
738
|
-
return JSON.stringify(
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
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
|
+
);
|
|
750
722
|
}
|
|
751
723
|
const JSONFormatter = {
|
|
752
724
|
format(record) {
|
|
753
|
-
return
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
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
|
+
];
|
|
761
735
|
}
|
|
762
736
|
};
|
|
763
737
|
|
|
@@ -771,6 +745,7 @@ const ansiStyles = {
|
|
|
771
745
|
cyan: ansi.cyan,
|
|
772
746
|
white: ansi.white,
|
|
773
747
|
gray: ansi.gray,
|
|
748
|
+
dim: ansi.dim,
|
|
774
749
|
bgBlack: ansi.bgBlack,
|
|
775
750
|
bgRed: ansi.bgRed,
|
|
776
751
|
bgGreen: ansi.bgGreen,
|
|
@@ -785,18 +760,12 @@ const ansiStyles = {
|
|
|
785
760
|
orange: {
|
|
786
761
|
open: ansi.color.ansi256(ansi.hexToAnsi256(styleToHexColor.orange)),
|
|
787
762
|
close: ansi.color.close
|
|
788
|
-
},
|
|
789
|
-
"gray-light": {
|
|
790
|
-
open: ansi.color.ansi256(ansi.hexToAnsi256(styleToHexColor["gray-light"])),
|
|
791
|
-
close: ansi.color.close
|
|
792
763
|
}
|
|
793
764
|
};
|
|
794
765
|
function style$2(styles, string) {
|
|
795
766
|
if (!styles || styles.length === 0 || !string) {
|
|
796
767
|
return string;
|
|
797
768
|
}
|
|
798
|
-
|
|
799
|
-
// eslint-disable-next-line unicorn/no-array-reduce
|
|
800
769
|
return styles.reduce((styledString, styleName) => {
|
|
801
770
|
const codePair = ansiStyles[styleName];
|
|
802
771
|
if (!codePair) {
|
|
@@ -806,14 +775,16 @@ function style$2(styles, string) {
|
|
|
806
775
|
}, string);
|
|
807
776
|
}
|
|
808
777
|
const ANSIFormatter = {
|
|
809
|
-
format: record => formatRecordToString(record, style$2)
|
|
778
|
+
format: (record) => formatRecordToString(record, style$2)
|
|
810
779
|
};
|
|
811
780
|
|
|
812
781
|
function style$1(styles, string) {
|
|
813
782
|
if (!styles || styles.length === 0 || !string) {
|
|
814
783
|
return string;
|
|
815
784
|
}
|
|
816
|
-
return `<span style="${styles.map(
|
|
785
|
+
return `<span style="${styles.map(
|
|
786
|
+
(styleName) => styleToHtmlStyleThemeLight[styleName].open
|
|
787
|
+
).join("; ")}">${string}</span>`;
|
|
817
788
|
}
|
|
818
789
|
const HTMLFormatter = {
|
|
819
790
|
format(record) {
|
|
@@ -825,8 +796,13 @@ const style = (styleToHtmlStyle, args) => (styles, string) => {
|
|
|
825
796
|
if (!styles || styles.length === 0 || !string) {
|
|
826
797
|
return string;
|
|
827
798
|
}
|
|
828
|
-
const htmlStyles = styles.map(
|
|
829
|
-
|
|
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
|
+
);
|
|
830
806
|
return `%c${string}%c`;
|
|
831
807
|
};
|
|
832
808
|
class BrowserConsoleFormatter {
|
|
@@ -835,48 +811,49 @@ class BrowserConsoleFormatter {
|
|
|
835
811
|
}
|
|
836
812
|
format(record) {
|
|
837
813
|
const args = [];
|
|
838
|
-
const string = formatRecordToString(
|
|
814
|
+
const string = formatRecordToString(
|
|
815
|
+
record,
|
|
816
|
+
style(this.styleToHtmlStyle, args)
|
|
817
|
+
)[0];
|
|
839
818
|
return [string, ...args];
|
|
840
819
|
}
|
|
841
820
|
}
|
|
842
821
|
|
|
843
|
-
/* eslint-disable no-console */
|
|
844
822
|
function consoleOutput(param, record) {
|
|
845
823
|
console[record.level >= Level.ERROR ? "error" : "log"](...param);
|
|
846
824
|
}
|
|
847
825
|
|
|
848
|
-
/* eslint-disable prefer-template */
|
|
849
|
-
|
|
850
826
|
class StringHandler {
|
|
851
|
-
_buffer = "";
|
|
852
827
|
constructor(minLevel) {
|
|
828
|
+
this._buffer = "";
|
|
853
829
|
this.minLevel = minLevel;
|
|
854
830
|
}
|
|
855
831
|
get string() {
|
|
856
832
|
return this._buffer;
|
|
857
833
|
}
|
|
858
834
|
handle(record) {
|
|
859
|
-
this._buffer += RawFormatter.format(record) + "\n";
|
|
835
|
+
this._buffer += RawFormatter.format(record)[0] + "\n";
|
|
860
836
|
}
|
|
861
837
|
}
|
|
862
838
|
|
|
863
839
|
function getDebugString() {
|
|
864
840
|
const querystring = document.location.search;
|
|
865
|
-
const debugFromLocalStorage =
|
|
866
|
-
|
|
867
|
-
|
|
841
|
+
const debugFromLocalStorage = (
|
|
842
|
+
// eslint-disable-next-line unicorn/prefer-global-this, @typescript-eslint/no-unnecessary-condition
|
|
843
|
+
window.localStorage?.getItem("debug") || ""
|
|
844
|
+
);
|
|
868
845
|
if (!querystring) {
|
|
869
846
|
return debugFromLocalStorage;
|
|
870
847
|
}
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
848
|
+
const debugFromQueryString = decodeURI(
|
|
849
|
+
querystring.replace(
|
|
850
|
+
// eslint-disable-next-line prefer-regex-literals, regexp/no-super-linear-backtracking
|
|
851
|
+
new RegExp("^(?:.*[&?]DEBUG(?:=([^&]*))?)?.*$", "i"),
|
|
852
|
+
"$1"
|
|
853
|
+
)
|
|
854
|
+
);
|
|
876
855
|
return (debugFromLocalStorage ? `${debugFromLocalStorage},` : "") + debugFromQueryString;
|
|
877
856
|
}
|
|
878
|
-
|
|
879
|
-
// debug string can change any time (localStorage), so we need a new object each time.
|
|
880
857
|
const findDebugLevel$2 = (minLevel, key) => createFindDebugLevel(getDebugString())(minLevel, key);
|
|
881
858
|
const getDefaultTheme = () => {
|
|
882
859
|
try {
|
|
@@ -884,57 +861,63 @@ const getDefaultTheme = () => {
|
|
|
884
861
|
if (configInLocalStorage && configInLocalStorage === "dark") {
|
|
885
862
|
return configInLocalStorage;
|
|
886
863
|
}
|
|
887
|
-
} catch {
|
|
864
|
+
} catch {
|
|
865
|
+
}
|
|
888
866
|
return "light";
|
|
889
867
|
};
|
|
890
868
|
const createHandler = (theme = getDefaultTheme()) => {
|
|
891
869
|
const browserConsoleFormatter = new BrowserConsoleFormatter(theme);
|
|
892
|
-
return record => {
|
|
870
|
+
return (record) => {
|
|
893
871
|
consoleOutput(browserConsoleFormatter.format(record), record);
|
|
894
872
|
};
|
|
895
873
|
};
|
|
896
874
|
class BrowserConsoleHandler {
|
|
897
|
-
minLevel = 0;
|
|
898
875
|
constructor(minLevel, options = {}) {
|
|
876
|
+
this.minLevel = 0;
|
|
899
877
|
this.isHandling = (level, key) => level >= findDebugLevel$2(minLevel, key);
|
|
900
878
|
this.handle = createHandler(options.theme);
|
|
901
879
|
}
|
|
902
880
|
}
|
|
903
881
|
|
|
904
882
|
const defaultFormatter = ANSIFormatter.format;
|
|
883
|
+
|
|
905
884
|
const createHandle$1 = (formatter = defaultFormatter, output = consoleOutput) => {
|
|
906
|
-
return record => {
|
|
885
|
+
return (record) => {
|
|
907
886
|
output(formatter(record), record);
|
|
908
887
|
};
|
|
909
888
|
};
|
|
910
889
|
const findDebugLevel$1 = createFindDebugLevel(process.env.DEBUG);
|
|
911
890
|
class ConsoleHandler {
|
|
912
|
-
minLevel = (() => Level.ALL)();
|
|
913
891
|
constructor(minLevel, options = {}) {
|
|
892
|
+
this.minLevel = Level.ALL;
|
|
914
893
|
this.minLevel = minLevel;
|
|
915
894
|
this.isHandling = (level, key) => level >= findDebugLevel$1(minLevel, key);
|
|
916
895
|
this.handle = createHandle$1(options.formatter, options.output);
|
|
917
896
|
}
|
|
918
897
|
}
|
|
919
898
|
|
|
920
|
-
/* eslint-disable no-console */
|
|
921
899
|
function cliConsoleOutput(param, record) {
|
|
922
900
|
console[record.level >= Level.ERROR ? "error" : "log"](...param);
|
|
923
901
|
}
|
|
924
902
|
|
|
925
903
|
const createHandle = ({
|
|
926
|
-
json
|
|
904
|
+
json,
|
|
905
|
+
noColor = process.env.NO_COLOR === "1" || process.env.NO_COLOR === "true"
|
|
927
906
|
}) => {
|
|
928
|
-
const formatter =
|
|
907
|
+
const formatter = (() => {
|
|
908
|
+
if (json) return JSONFormatter.format;
|
|
909
|
+
if (noColor) return RawFormatter.format;
|
|
910
|
+
return ANSIFormatter.format;
|
|
911
|
+
})();
|
|
929
912
|
const output = json ? consoleOutput : cliConsoleOutput;
|
|
930
|
-
return record => {
|
|
913
|
+
return (record) => {
|
|
931
914
|
output(formatter(record), record);
|
|
932
915
|
};
|
|
933
916
|
};
|
|
934
917
|
const findDebugLevel = createFindDebugLevel(process.env.DEBUG);
|
|
935
918
|
class ConsoleCLIHandler {
|
|
936
|
-
minLevel = (() => Level.ALL)();
|
|
937
919
|
constructor(minLevel, options = {}) {
|
|
920
|
+
this.minLevel = Level.ALL;
|
|
938
921
|
this.minLevel = minLevel;
|
|
939
922
|
this.isHandling = (level, key) => level >= findDebugLevel(minLevel, key);
|
|
940
923
|
this.handle = createHandle(options);
|
|
@@ -942,20 +925,14 @@ class ConsoleCLIHandler {
|
|
|
942
925
|
}
|
|
943
926
|
|
|
944
927
|
class LoggerCLI extends Logger {
|
|
945
|
-
processors =
|
|
946
|
-
constructor(key, {
|
|
947
|
-
displayName,
|
|
948
|
-
processors,
|
|
949
|
-
json = false
|
|
950
|
-
} = {}) {
|
|
928
|
+
constructor(key, { displayName, processors, json = false, noColor } = {}) {
|
|
951
929
|
super(key, displayName);
|
|
952
|
-
this.
|
|
953
|
-
|
|
954
|
-
})];
|
|
930
|
+
this.processors = [];
|
|
931
|
+
this.handlers = [new ConsoleCLIHandler(Level$1.INFO, { json, noColor })];
|
|
955
932
|
this.processors = processors ?? [];
|
|
956
933
|
this.json = json;
|
|
957
934
|
}
|
|
958
|
-
getHandlersAndProcessors() {
|
|
935
|
+
getHandlersAndProcessors(recordLevel) {
|
|
959
936
|
return {
|
|
960
937
|
handlers: this.handlers,
|
|
961
938
|
processors: this.processors
|
|
@@ -1002,20 +979,22 @@ class LoggerCLI extends Logger {
|
|
|
1002
979
|
}
|
|
1003
980
|
}
|
|
1004
981
|
}
|
|
982
|
+
separator() {
|
|
983
|
+
console.log();
|
|
984
|
+
}
|
|
1005
985
|
}
|
|
1006
986
|
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
process.on("uncaughtException", error => {
|
|
987
|
+
function listenUnhandledErrors(logger = new Logger(
|
|
988
|
+
"nightingale:listenUnhandledErrors",
|
|
989
|
+
"UnhandledErrors"
|
|
990
|
+
)) {
|
|
991
|
+
process.on("uncaughtException", (error) => {
|
|
1013
992
|
logger.error(error, {
|
|
1014
993
|
unhandled: true,
|
|
1015
994
|
type: "uncaughtException"
|
|
1016
995
|
});
|
|
1017
996
|
});
|
|
1018
|
-
process.on("unhandledRejection", error => {
|
|
997
|
+
process.on("unhandledRejection", (error) => {
|
|
1019
998
|
logger.error(error, {
|
|
1020
999
|
unhandled: true,
|
|
1021
1000
|
type: "unhandledRejection"
|
|
@@ -1023,5 +1002,5 @@ function listenUnhandledErrors(logger = new Logger("nightingale:listenUnhandledE
|
|
|
1023
1002
|
});
|
|
1024
1003
|
}
|
|
1025
1004
|
|
|
1026
|
-
export { ANSIFormatter, BrowserConsoleFormatter, BrowserConsoleHandler, ConsoleCLIHandler, ConsoleHandler, HTMLFormatter, JSONFormatter, LoggerCLI, MarkdownFormatter, RawFormatter, StringHandler, addConfig, configure, consoleOutput, createFindDebugLevel, formatObject, formatRecordToString, levelToStyles, levelToSymbol, listenUnhandledErrors, styleToHexColor, styleToHtmlStyleThemeDark, styleToHtmlStyleThemeLight };
|
|
1005
|
+
export { ANSIFormatter, BrowserConsoleFormatter, BrowserConsoleHandler, ConsoleCLIHandler, ConsoleHandler, HTMLFormatter, JSONFormatter, LoggerCLI, MarkdownFormatter, RawFormatter, StringHandler, addConfig, configure, consoleOutput, createFindDebugLevel, formatObject, formatRecordToString, formatStyles, levelToStyles, levelToSymbol, listenUnhandledErrors, styleToHexColor, styleToHtmlStyleThemeDark, styleToHtmlStyleThemeLight };
|
|
1027
1006
|
//# sourceMappingURL=index-browser.es.js.map
|