@andrew_l/pino-pretty 0.3.22 → 0.4.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/dist/index.d.mts +177 -179
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +527 -614
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -8
- package/dist/index.cjs +0 -740
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -208
- package/dist/index.d.ts +0 -208
package/dist/index.mjs
CHANGED
|
@@ -1,61 +1,47 @@
|
|
|
1
|
-
import { Transform } from
|
|
2
|
-
import abstractTransport from
|
|
3
|
-
import pump from
|
|
4
|
-
import {
|
|
5
|
-
import path from
|
|
6
|
-
import {
|
|
7
|
-
import _SonicBoom from
|
|
8
|
-
import { isMainThread } from
|
|
9
|
-
import * as tty from
|
|
10
|
-
import { StringWidth } from
|
|
11
|
-
|
|
1
|
+
import { Transform } from "node:stream";
|
|
2
|
+
import abstractTransport from "pino-abstract-transport";
|
|
3
|
+
import pump from "pump";
|
|
4
|
+
import { arrayable, capitalize, crc32, deepDefaults, def, has, isFunction, isObject, isPrimitive, isString, noop, omit, typeOf, withCache } from "@andrew_l/toolkit";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { formatWithOptions, inspect } from "node:util";
|
|
7
|
+
import _SonicBoom from "sonic-boom";
|
|
8
|
+
import { isMainThread } from "node:worker_threads";
|
|
9
|
+
import * as tty from "node:tty";
|
|
10
|
+
import { StringWidth } from "@cto.af/string-width";
|
|
12
11
|
function buildSafeSonicBoom(opts) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
stream.removeListener("error", filterBrokenPipe);
|
|
28
|
-
}
|
|
12
|
+
const stream = new _SonicBoom(opts);
|
|
13
|
+
stream.on("error", filterBrokenPipe);
|
|
14
|
+
if (!process.env.NODE_V8_COVERAGE && !opts.sync && isMainThread) setupOnExit(stream);
|
|
15
|
+
return stream;
|
|
16
|
+
function filterBrokenPipe(err) {
|
|
17
|
+
if (err.code === "EPIPE") {
|
|
18
|
+
stream.write = noop;
|
|
19
|
+
stream.end = noop;
|
|
20
|
+
stream.flushSync = noop;
|
|
21
|
+
stream.destroy = noop;
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
stream.removeListener("error", filterBrokenPipe);
|
|
25
|
+
}
|
|
29
26
|
}
|
|
30
27
|
function setupOnExit(stream) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
});
|
|
38
|
-
}
|
|
28
|
+
if (global.WeakRef && global.WeakMap && global.FinalizationRegistry) import("on-exit-leak-free").then((onExit) => {
|
|
29
|
+
onExit.register(stream, autoEnd);
|
|
30
|
+
stream.on("close", function() {
|
|
31
|
+
onExit.unregister(stream);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
39
34
|
}
|
|
40
35
|
function autoEnd(stream, eventName) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
stream.flushSync();
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const {
|
|
55
|
-
env = {},
|
|
56
|
-
argv = [],
|
|
57
|
-
platform = ""
|
|
58
|
-
} = typeof process === "undefined" ? {} : process;
|
|
36
|
+
if (stream.destroyed) return;
|
|
37
|
+
if (eventName === "beforeExit") {
|
|
38
|
+
stream.flush();
|
|
39
|
+
stream.on("drain", function() {
|
|
40
|
+
stream.end();
|
|
41
|
+
});
|
|
42
|
+
} else stream.flushSync();
|
|
43
|
+
}
|
|
44
|
+
const { env = {}, argv = [], platform = "" } = typeof process === "undefined" ? {} : process;
|
|
59
45
|
const isDisabled = "NO_COLOR" in env || argv.includes("--no-color");
|
|
60
46
|
const isForced = "FORCE_COLOR" in env || argv.includes("--color");
|
|
61
47
|
const isWindows = platform === "win32";
|
|
@@ -64,652 +50,579 @@ const isCompatibleTerminal = tty && tty.isatty && tty.isatty(1) && env.TERM && !
|
|
|
64
50
|
const isCI = "CI" in env && ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env);
|
|
65
51
|
const isColorSupported = !isDisabled && (isForced || isWindows && !isDumbTerminal || isCompatibleTerminal || isCI);
|
|
66
52
|
function replaceClose(index, string, close, replace, head = string.slice(0, Math.max(0, index)) + replace, tail = string.slice(Math.max(0, index + close.length)), next = tail.indexOf(close)) {
|
|
67
|
-
|
|
53
|
+
return head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
|
|
68
54
|
}
|
|
69
55
|
function clearBleed(index, string, open, close, replace) {
|
|
70
|
-
|
|
56
|
+
return index < 0 ? open + string + close : open + replaceClose(index, string, close, replace) + close;
|
|
71
57
|
}
|
|
72
58
|
function filterEmpty(open, close, replace = open, at = open.length + 1) {
|
|
73
|
-
|
|
74
|
-
("" + string).indexOf(close, at),
|
|
75
|
-
string,
|
|
76
|
-
open,
|
|
77
|
-
close,
|
|
78
|
-
replace
|
|
79
|
-
) : "";
|
|
59
|
+
return (string) => string || !(string === "" || string === void 0) ? clearBleed(("" + string).indexOf(close, at), string, open, close, replace) : "";
|
|
80
60
|
}
|
|
81
61
|
function init(open, close, replace) {
|
|
82
|
-
|
|
62
|
+
return filterEmpty(`\u001B[${open}m`, `\u001B[${close}m`, replace);
|
|
83
63
|
}
|
|
84
64
|
function init256Color(code, isBg = false) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
65
|
+
const prefix = isBg ? "48;5;" : "38;5;";
|
|
66
|
+
const closeCode = isBg ? 49 : 39;
|
|
67
|
+
return filterEmpty(`\u001B[${prefix}${code}m`, `\u001B[${closeCode}m`);
|
|
88
68
|
}
|
|
89
69
|
const colorDefs = {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
bgGold: init256Color(220, true)
|
|
70
|
+
reset: init(0, 0),
|
|
71
|
+
bold: init(1, 22, "\x1B[22m\x1B[1m"),
|
|
72
|
+
dim: init(2, 22, "\x1B[22m\x1B[2m"),
|
|
73
|
+
italic: init(3, 23),
|
|
74
|
+
underline: init(4, 24),
|
|
75
|
+
inverse: init(7, 27),
|
|
76
|
+
hidden: init(8, 28),
|
|
77
|
+
strikethrough: init(9, 29),
|
|
78
|
+
black: init(30, 39),
|
|
79
|
+
red: init(31, 39),
|
|
80
|
+
green: init(32, 39),
|
|
81
|
+
yellow: init(33, 39),
|
|
82
|
+
blue: init(34, 39),
|
|
83
|
+
magenta: init(35, 39),
|
|
84
|
+
cyan: init(36, 39),
|
|
85
|
+
white: init(37, 39),
|
|
86
|
+
gray: init(90, 39),
|
|
87
|
+
bgBlack: init(40, 49),
|
|
88
|
+
bgRed: init(41, 49),
|
|
89
|
+
bgGreen: init(42, 49),
|
|
90
|
+
bgYellow: init(43, 49),
|
|
91
|
+
bgBlue: init(44, 49),
|
|
92
|
+
bgMagenta: init(45, 49),
|
|
93
|
+
bgCyan: init(46, 49),
|
|
94
|
+
bgWhite: init(47, 49),
|
|
95
|
+
blackBright: init(90, 39),
|
|
96
|
+
redBright: init(91, 39),
|
|
97
|
+
greenBright: init(92, 39),
|
|
98
|
+
yellowBright: init(93, 39),
|
|
99
|
+
blueBright: init(94, 39),
|
|
100
|
+
magentaBright: init(95, 39),
|
|
101
|
+
cyanBright: init(96, 39),
|
|
102
|
+
whiteBright: init(97, 39),
|
|
103
|
+
bgBlackBright: init(100, 49),
|
|
104
|
+
bgRedBright: init(101, 49),
|
|
105
|
+
bgGreenBright: init(102, 49),
|
|
106
|
+
bgYellowBright: init(103, 49),
|
|
107
|
+
bgBlueBright: init(104, 49),
|
|
108
|
+
bgMagentaBright: init(105, 49),
|
|
109
|
+
bgCyanBright: init(106, 49),
|
|
110
|
+
bgWhiteBright: init(107, 49),
|
|
111
|
+
orange: init256Color(208),
|
|
112
|
+
purple: init256Color(129),
|
|
113
|
+
pink: init256Color(207),
|
|
114
|
+
lime: init256Color(154),
|
|
115
|
+
teal: init256Color(37),
|
|
116
|
+
indigo: init256Color(54),
|
|
117
|
+
brown: init256Color(130),
|
|
118
|
+
olive: init256Color(142),
|
|
119
|
+
navy: init256Color(17),
|
|
120
|
+
maroon: init256Color(52),
|
|
121
|
+
silver: init256Color(248),
|
|
122
|
+
gold: init256Color(220),
|
|
123
|
+
bgOrange: init256Color(208, true),
|
|
124
|
+
bgPurple: init256Color(129, true),
|
|
125
|
+
bgPink: init256Color(207, true),
|
|
126
|
+
bgLime: init256Color(154, true),
|
|
127
|
+
bgTeal: init256Color(37, true),
|
|
128
|
+
bgIndigo: init256Color(54, true),
|
|
129
|
+
bgBrown: init256Color(130, true),
|
|
130
|
+
bgOlive: init256Color(142, true),
|
|
131
|
+
bgNavy: init256Color(17, true),
|
|
132
|
+
bgMaroon: init256Color(52, true),
|
|
133
|
+
bgSilver: init256Color(248, true),
|
|
134
|
+
bgGold: init256Color(220, true)
|
|
156
135
|
};
|
|
157
136
|
const RAND_COLOR_LIST = Object.keys(colorDefs).filter((v) => {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
return true;
|
|
137
|
+
if (v.startsWith("bg")) return false;
|
|
138
|
+
if ([
|
|
139
|
+
"reset",
|
|
140
|
+
"bold",
|
|
141
|
+
"dim",
|
|
142
|
+
"italic",
|
|
143
|
+
"underline",
|
|
144
|
+
"inverse",
|
|
145
|
+
"hidden",
|
|
146
|
+
"strikethrough",
|
|
147
|
+
"black",
|
|
148
|
+
"white",
|
|
149
|
+
"gray"
|
|
150
|
+
].includes(v)) return false;
|
|
151
|
+
return true;
|
|
174
152
|
});
|
|
175
153
|
function createColors(useColor = isColorSupported) {
|
|
176
|
-
|
|
154
|
+
return useColor ? colorDefs : Object.fromEntries(Object.keys(colorDefs).map((key) => [key, String]));
|
|
177
155
|
}
|
|
178
156
|
const colors = createColors();
|
|
179
157
|
function getColor(color, fallback = "reset") {
|
|
180
|
-
|
|
158
|
+
return colors[color] || colors[fallback];
|
|
181
159
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
160
|
+
var QUOTES = {
|
|
161
|
+
double: "\"",
|
|
162
|
+
single: "'"
|
|
163
|
+
};
|
|
164
|
+
var QUOTE_REGEX = {
|
|
165
|
+
double: /(["\\])/g,
|
|
166
|
+
single: /(['\\])/g
|
|
167
|
+
};
|
|
168
|
+
var ESCAPE_CHARS = {
|
|
169
|
+
8: "b",
|
|
170
|
+
9: "t",
|
|
171
|
+
10: "n",
|
|
172
|
+
12: "f",
|
|
173
|
+
13: "r"
|
|
174
|
+
};
|
|
186
175
|
var SEP_REGEX = /\d(?=(?:\d{3})+(?!\d))/g;
|
|
187
176
|
function addNumericSeparator(num, str) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
return intStr.replace(SEP_REGEX, "$&_") + "." + decPart.replace(/(\d{3})/g, "$&_").replace(/_$/, "");
|
|
196
|
-
}
|
|
197
|
-
return str.replace(SEP_REGEX, "$&_");
|
|
177
|
+
if (num === Infinity || num === -Infinity || Number.isNaN(num) || typeof num === "number" && Math.abs(num) < 1e3 || str.includes("e")) return str;
|
|
178
|
+
if (typeof num === "number" && !Number.isInteger(num)) {
|
|
179
|
+
var intStr = String(Math.trunc(num));
|
|
180
|
+
var decPart = str.slice(intStr.length + 1);
|
|
181
|
+
return intStr.replace(SEP_REGEX, "$&_") + "." + decPart.replace(/(\d{3})/g, "$&_").replace(/_$/, "");
|
|
182
|
+
}
|
|
183
|
+
return str.replace(SEP_REGEX, "$&_");
|
|
198
184
|
}
|
|
199
185
|
function escapeString(str, opts) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
186
|
+
var quoteRegex = QUOTE_REGEX[opts.quoteStyle];
|
|
187
|
+
return str.replace(quoteRegex, "\\$1").replace(/[\x00-\x1f]/g, (char) => {
|
|
188
|
+
var code = char.charCodeAt(0);
|
|
189
|
+
var escapeChar = ESCAPE_CHARS[code];
|
|
190
|
+
return escapeChar ? `\\${escapeChar}` : `\\x${code.toString(16).padStart(2, "0").toUpperCase()}`;
|
|
191
|
+
});
|
|
206
192
|
}
|
|
207
193
|
function inspectString$1(str, opts) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
194
|
+
if (str.length > opts.maxStringLength) {
|
|
195
|
+
var remaining = str.length - opts.maxStringLength;
|
|
196
|
+
var trailer = `... ${remaining} more character${remaining > 1 ? "s" : ""}`;
|
|
197
|
+
str = str.slice(0, opts.maxStringLength);
|
|
198
|
+
return inspectString$1(str, opts) + trailer;
|
|
199
|
+
}
|
|
200
|
+
var escaped = escapeString(str, opts);
|
|
201
|
+
var quote = QUOTES[opts.quoteStyle];
|
|
202
|
+
var result = `${quote}${escaped}${quote}`;
|
|
203
|
+
return opts.customStringify.string?.(result) ?? result;
|
|
218
204
|
}
|
|
219
205
|
function inspectNumber(num, opts) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
206
|
+
if (typeof num === "bigint") {
|
|
207
|
+
var str = `${num}n`;
|
|
208
|
+
var result = opts.numericSeparator ? addNumericSeparator(num, str) : str;
|
|
209
|
+
return opts.customStringify.number?.(result) ?? result;
|
|
210
|
+
}
|
|
211
|
+
var str = Object.is(num, -0) ? "-0" : String(num);
|
|
212
|
+
var result = opts.numericSeparator ? addNumericSeparator(num, str) : str;
|
|
213
|
+
return opts.customStringify.number?.(result) ?? result;
|
|
228
214
|
}
|
|
229
215
|
function getIndentStrings(opts, depth) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
216
|
+
if (depth === 0) return {
|
|
217
|
+
base: " ".repeat(opts.indent),
|
|
218
|
+
prev: ""
|
|
219
|
+
};
|
|
220
|
+
return {
|
|
221
|
+
base: " ".repeat(opts.indent),
|
|
222
|
+
prev: " ".repeat(opts.indent * depth)
|
|
223
|
+
};
|
|
235
224
|
}
|
|
236
225
|
function isSingleLine(values) {
|
|
237
|
-
|
|
226
|
+
return values.every((value) => !value.includes("\n"));
|
|
238
227
|
}
|
|
239
228
|
function formatMultiline(values, indent) {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
${
|
|
243
|
-
return `${lineJoiner}${values.join(`,${lineJoiner}`)}
|
|
244
|
-
${indent.prev}`;
|
|
229
|
+
if (values.length === 0) return "";
|
|
230
|
+
var lineJoiner = `\n${indent.prev}${indent.base}`;
|
|
231
|
+
return `${lineJoiner}${values.join(`,${lineJoiner}`)}\n${indent.prev}`;
|
|
245
232
|
}
|
|
246
233
|
function getObjectEntries(obj, inspectFn) {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
var needsQuotes = /[^\w$]/.test(key);
|
|
258
|
-
var keyStr = needsQuotes ? inspectFn(key, obj) : key;
|
|
259
|
-
entries.push(`${keyStr}: ${inspectFn(obj[key], obj)}`);
|
|
260
|
-
}
|
|
261
|
-
return entries;
|
|
234
|
+
var isArray = Array.isArray(obj);
|
|
235
|
+
var entries = [];
|
|
236
|
+
if (isArray) for (var i = 0; i < obj.length; i++) entries[i] = Object.hasOwn(obj, i) ? inspectFn(obj[i], obj) : "";
|
|
237
|
+
for (var key in obj) {
|
|
238
|
+
if (!Object.hasOwn(obj, key)) continue;
|
|
239
|
+
if (isArray && /^\d+$/.test(key) && Number(key) < obj.length) continue;
|
|
240
|
+
var keyStr = /[^\w$]/.test(key) ? inspectFn(key, obj) : key;
|
|
241
|
+
entries.push(`${keyStr}: ${inspectFn(obj[key], obj)}`);
|
|
242
|
+
}
|
|
243
|
+
return entries;
|
|
262
244
|
}
|
|
263
245
|
function inspectValue$1(obj, opts, depth, seen) {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
${indent.prev}`;
|
|
294
|
-
return inspect(obj, { depth: opts.depth - depth }).split("\n").join(lineJoiner);
|
|
295
|
-
}
|
|
296
|
-
var entries = getObjectEntries(obj, inspectChild);
|
|
297
|
-
if (entries.length === 0) return "{}";
|
|
298
|
-
if (indent.base) {
|
|
299
|
-
return `{${formatMultiline(entries, indent)}}`;
|
|
300
|
-
}
|
|
301
|
-
return `{ ${entries.join(", ")} }`;
|
|
302
|
-
}
|
|
303
|
-
seen.delete(obj);
|
|
304
|
-
return String(obj);
|
|
246
|
+
if (obj === void 0) return opts.customStringify.undefined?.(obj) ?? "undefined";
|
|
247
|
+
if (obj === null) return opts.customStringify.null?.(obj) ?? "null";
|
|
248
|
+
if (typeof obj === "boolean") return opts.customStringify.boolean?.(obj) ?? String(obj);
|
|
249
|
+
if (typeof obj === "string") return inspectString$1(obj, opts);
|
|
250
|
+
if (typeof obj === "number") return inspectNumber(obj, opts);
|
|
251
|
+
else if (typeof obj === "bigint") return inspectNumber(obj, opts);
|
|
252
|
+
if (depth >= opts.depth && opts.depth > 0 && typeof obj === "object") return Array.isArray(obj) ? "[Array]" : "[Object]";
|
|
253
|
+
if (seen.has(obj)) return "[Circular]";
|
|
254
|
+
seen.add(obj);
|
|
255
|
+
var indent = getIndentStrings(opts, depth);
|
|
256
|
+
var inspectChild = (value) => inspectValue$1(value, opts, depth + 1, seen);
|
|
257
|
+
if (Array.isArray(obj)) {
|
|
258
|
+
if (obj.length === 0) return "[]";
|
|
259
|
+
var entries = getObjectEntries(obj, inspectChild);
|
|
260
|
+
if (indent.base && !isSingleLine(entries)) return `[${formatMultiline(entries, indent)}]`;
|
|
261
|
+
return `[ ${entries.join(", ")} ]`;
|
|
262
|
+
}
|
|
263
|
+
if (isObject(obj)) {
|
|
264
|
+
if (isFunction(obj[inspect.custom])) {
|
|
265
|
+
var lineJoiner = `\n${indent.prev}`;
|
|
266
|
+
return inspect(obj, { depth: opts.depth - depth }).split("\n").join(lineJoiner);
|
|
267
|
+
}
|
|
268
|
+
var entries = getObjectEntries(obj, inspectChild);
|
|
269
|
+
if (entries.length === 0) return "{}";
|
|
270
|
+
if (indent.base) return `{${formatMultiline(entries, indent)}}`;
|
|
271
|
+
return `{ ${entries.join(", ")} }`;
|
|
272
|
+
}
|
|
273
|
+
seen.delete(obj);
|
|
274
|
+
return String(obj);
|
|
305
275
|
}
|
|
306
276
|
function inspectRegular(obj, options) {
|
|
307
|
-
|
|
277
|
+
return inspectValue$1(obj, options, 0, /* @__PURE__ */ new WeakSet());
|
|
308
278
|
}
|
|
309
|
-
|
|
310
279
|
var INSPECT_MAP = {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
280
|
+
boolean: (obj, opts) => opts.customStringify.boolean?.(obj) ?? String(obj),
|
|
281
|
+
string: inspectString,
|
|
282
|
+
number: inspectNumber,
|
|
283
|
+
bigint: inspectNumber,
|
|
284
|
+
undefined: (obj, opts) => opts.customStringify.undefined?.(obj) ?? "undefined",
|
|
285
|
+
null: () => "null",
|
|
286
|
+
array: formatArray,
|
|
287
|
+
object: formatObject
|
|
319
288
|
};
|
|
320
289
|
function inspectCompact(obj, options) {
|
|
321
|
-
|
|
290
|
+
return inspectValue(obj, options, 0, /* @__PURE__ */ new WeakSet());
|
|
322
291
|
}
|
|
323
292
|
function inspectValue(obj, opts, depth = 0, seen) {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
}
|
|
332
|
-
return inspectFn(obj, opts, depth, spaces, seen);
|
|
293
|
+
var spaces = depth > 0 ? " ".repeat(opts.indent * depth) : "";
|
|
294
|
+
var inspectFn = INSPECT_MAP[typeOf(obj)] || String;
|
|
295
|
+
if (obj && isFunction(obj[inspect.custom])) {
|
|
296
|
+
var lineJoiner = `\n${spaces}`;
|
|
297
|
+
return spaces + inspect(obj, { depth: opts.depth - depth }).split("\n").join(lineJoiner);
|
|
298
|
+
}
|
|
299
|
+
return inspectFn(obj, opts, depth, spaces, seen);
|
|
333
300
|
}
|
|
334
301
|
function inspectString(str, opts) {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
302
|
+
if (str.length > opts.maxStringLength) {
|
|
303
|
+
var remaining = str.length - opts.maxStringLength;
|
|
304
|
+
str = str.slice(0, opts.maxStringLength);
|
|
305
|
+
return formatString(str, remaining, opts);
|
|
306
|
+
}
|
|
307
|
+
return formatString(str, 0, opts);
|
|
341
308
|
}
|
|
342
309
|
function formatString(str, remaining, opts) {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
result = `${quote}${escaped}${trailer ?? ""}${quote}`;
|
|
353
|
-
}
|
|
354
|
-
return opts.customStringify.string?.(result) ?? result;
|
|
310
|
+
var escaped = escapeString(str, opts);
|
|
311
|
+
var quote = QUOTES[opts.quoteStyle];
|
|
312
|
+
var result;
|
|
313
|
+
var trailer = remaining > 0 ? opts.customStringify.stringRemaining(`... ${remaining} more characters`) : "";
|
|
314
|
+
if (escaped.length > opts.columns && escaped.includes("\\n")) {
|
|
315
|
+
escaped = escaped.replaceAll("\\n", "\n");
|
|
316
|
+
result = "\n```\n" + (trailer ? `${escaped}\n${trailer}` : escaped) + "\n```";
|
|
317
|
+
} else result = `${quote}${escaped}${trailer ?? ""}${quote}`;
|
|
318
|
+
return opts.customStringify.string?.(result) ?? result;
|
|
355
319
|
}
|
|
356
320
|
function formatArray(arr, opts, depth, spaces, seen) {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
var multiline = [];
|
|
373
|
-
for (var i = 0; i < len; i++) {
|
|
374
|
-
var strValue = inspectValue(arr[i], opts, depth + 1, seen);
|
|
375
|
-
multiline.push(
|
|
376
|
-
`${spaces}- ${strValue.trimStart ? strValue.trimStart() : strValue}`
|
|
377
|
-
);
|
|
378
|
-
}
|
|
379
|
-
return multiline.join("\n");
|
|
321
|
+
if (opts.depth > 0 && depth >= opts.depth) return "[Array]";
|
|
322
|
+
if (seen.has(arr)) return "[Circular]";
|
|
323
|
+
seen.add(arr);
|
|
324
|
+
var len = arr.length;
|
|
325
|
+
if (isCompactFormat(arr, depth, spaces.length, opts)) {
|
|
326
|
+
var compact = [];
|
|
327
|
+
for (var i = 0; i < len; i++) compact.push(inspectValue(arr[i], opts, 0, seen));
|
|
328
|
+
return `[${compact.join(", ")}]`;
|
|
329
|
+
}
|
|
330
|
+
var multiline = [];
|
|
331
|
+
for (var i = 0; i < len; i++) {
|
|
332
|
+
var strValue = inspectValue(arr[i], opts, depth + 1, seen);
|
|
333
|
+
multiline.push(`${spaces}- ${strValue.trimStart ? strValue.trimStart() : strValue}`);
|
|
334
|
+
}
|
|
335
|
+
return multiline.join("\n");
|
|
380
336
|
}
|
|
381
337
|
function isCompactFormat(value, depth, spaces, opts) {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
338
|
+
var availableLength = opts.columns - spaces - depth * opts.indent;
|
|
339
|
+
var totalLength = 0;
|
|
340
|
+
if (availableLength <= 0) return false;
|
|
341
|
+
for (var item of value.flat()) {
|
|
342
|
+
totalLength += String(item).length + 2;
|
|
343
|
+
if (totalLength > availableLength || !isPrimitive(item)) return false;
|
|
344
|
+
}
|
|
345
|
+
return true;
|
|
390
346
|
}
|
|
391
347
|
function formatObject(obj, opts, depth, spaces, seen) {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
if (Array.isArray(value) && value.length > 0 && strValue[0] !== "[") {
|
|
423
|
-
multiline.push(`${spaces}${key}:
|
|
424
|
-
${strValue}`);
|
|
425
|
-
} else if (!Array.isArray(value)) {
|
|
426
|
-
multiline.push(`${spaces}${key}:
|
|
427
|
-
${strValue}`);
|
|
428
|
-
} else {
|
|
429
|
-
multiline.push(`${spaces}${key}: ${strValue}`);
|
|
430
|
-
}
|
|
431
|
-
} else {
|
|
432
|
-
multiline.push(`${spaces}${key}: ${strValue}`);
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
return multiline.join("\n");
|
|
348
|
+
if (opts.depth > 0 && depth >= opts.depth) return "[Array]";
|
|
349
|
+
if (seen.has(obj)) return "[Circular]";
|
|
350
|
+
seen.add(obj);
|
|
351
|
+
var entries = Object.entries(obj);
|
|
352
|
+
var len = entries.length;
|
|
353
|
+
if (len === 0) return "{}";
|
|
354
|
+
if (isCompactFormat(entries, depth, spaces.length, opts)) {
|
|
355
|
+
var compact = [];
|
|
356
|
+
var key, value;
|
|
357
|
+
for (var i = 0; i < len; i++) {
|
|
358
|
+
key = entries[i][0];
|
|
359
|
+
value = entries[i][1];
|
|
360
|
+
compact.push(`${key}: ${inspectValue(value, opts, 0, seen)}`);
|
|
361
|
+
}
|
|
362
|
+
return `{ ${compact.join(", ")} }`;
|
|
363
|
+
}
|
|
364
|
+
var multiline = [];
|
|
365
|
+
var key, value, strValue, compactMode;
|
|
366
|
+
for (var i = 0; i < len; i++) {
|
|
367
|
+
key = entries[i][0];
|
|
368
|
+
value = entries[i][1];
|
|
369
|
+
strValue = inspectValue(value, opts, depth + 1, seen);
|
|
370
|
+
compactMode = strValue[0] === "{" || strValue[0] === "[";
|
|
371
|
+
if (compactMode) multiline.push(`${spaces}${key}: ${strValue}`);
|
|
372
|
+
else if (value && typeof value === "object") if (Array.isArray(value) && value.length > 0 && strValue[0] !== "[") multiline.push(`${spaces}${key}:\n${strValue}`);
|
|
373
|
+
else if (!Array.isArray(value)) multiline.push(`${spaces}${key}:\n${strValue}`);
|
|
374
|
+
else multiline.push(`${spaces}${key}: ${strValue}`);
|
|
375
|
+
else multiline.push(`${spaces}${key}: ${strValue}`);
|
|
376
|
+
}
|
|
377
|
+
return multiline.join("\n");
|
|
436
378
|
}
|
|
437
|
-
|
|
438
379
|
function parseOptions(value) {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
380
|
+
const opts = deepDefaults({}, value, {
|
|
381
|
+
columns: 80,
|
|
382
|
+
indent: 2,
|
|
383
|
+
depth: 5,
|
|
384
|
+
messageKey: "msg",
|
|
385
|
+
quoteStyle: "single",
|
|
386
|
+
badgeMinLevel: 40,
|
|
387
|
+
maxStringLength: 400,
|
|
388
|
+
numericSeparator: false,
|
|
389
|
+
ignore: "hostname,pid",
|
|
390
|
+
colorize: true,
|
|
391
|
+
inspect: "compact",
|
|
392
|
+
types: {
|
|
393
|
+
number: { color: "green" },
|
|
394
|
+
boolean: { color: "redBright" },
|
|
395
|
+
string: { color: "yellow" },
|
|
396
|
+
object: { color: "gray" },
|
|
397
|
+
error: { color: "gray" },
|
|
398
|
+
errorStack: { color: "cyan" },
|
|
399
|
+
time: { color: "gray" },
|
|
400
|
+
name: { color: "rand" }
|
|
401
|
+
},
|
|
402
|
+
levels: {
|
|
403
|
+
10: {
|
|
404
|
+
badge: "TRACE",
|
|
405
|
+
color: "gray",
|
|
406
|
+
icon: "→"
|
|
407
|
+
},
|
|
408
|
+
20: {
|
|
409
|
+
badge: "DEBUG",
|
|
410
|
+
color: "blue",
|
|
411
|
+
icon: "⚙"
|
|
412
|
+
},
|
|
413
|
+
30: {
|
|
414
|
+
badge: "INFO",
|
|
415
|
+
color: "cyan",
|
|
416
|
+
icon: "ℹ"
|
|
417
|
+
},
|
|
418
|
+
40: {
|
|
419
|
+
badge: "WARN",
|
|
420
|
+
color: "yellow",
|
|
421
|
+
icon: "⚠"
|
|
422
|
+
},
|
|
423
|
+
50: {
|
|
424
|
+
badge: "ERROR",
|
|
425
|
+
color: "red",
|
|
426
|
+
icon: "✖"
|
|
427
|
+
},
|
|
428
|
+
60: {
|
|
429
|
+
badge: "FATAL",
|
|
430
|
+
color: "red",
|
|
431
|
+
icon: "✖"
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
const sw = new StringWidth({ extraWidths: new Map(Object.values(opts.levels).map((v) => [v.icon.charCodeAt(0), 1])) });
|
|
436
|
+
const result = {
|
|
437
|
+
...opts,
|
|
438
|
+
sw,
|
|
439
|
+
colorFallback: createColorizeFn(opts.colorize, "gray"),
|
|
440
|
+
inspectFn: opts.inspect === "regular" ? inspectRegular : opts.inspect === "compact" ? inspectCompact : isFunction(opts.inspect) ? opts.inspect : inspectRegular,
|
|
441
|
+
inspectOptions: {
|
|
442
|
+
depth: opts.depth,
|
|
443
|
+
quoteStyle: opts.quoteStyle,
|
|
444
|
+
indent: opts.indent,
|
|
445
|
+
maxStringLength: opts.maxStringLength,
|
|
446
|
+
numericSeparator: opts.numericSeparator,
|
|
447
|
+
customStringify: {},
|
|
448
|
+
columns: opts.columns
|
|
449
|
+
},
|
|
450
|
+
levels: Object.fromEntries(Object.entries(opts.levels).map(([key, value]) => [key, {
|
|
451
|
+
...value,
|
|
452
|
+
color: createColorizeFn(opts.colorize, value.color),
|
|
453
|
+
colorBadge: createColorizeBadgeFn(opts.colorize, value.color)
|
|
454
|
+
}])),
|
|
455
|
+
types: Object.fromEntries(Object.entries(opts.types).map(([key, value]) => [key, {
|
|
456
|
+
...value,
|
|
457
|
+
color: createColorizeFn(opts.colorize, value.color)
|
|
458
|
+
}])),
|
|
459
|
+
ignoreAdditional: /* @__PURE__ */ new Set([
|
|
460
|
+
"level",
|
|
461
|
+
"time",
|
|
462
|
+
"pid",
|
|
463
|
+
"hostname",
|
|
464
|
+
opts.messageKey,
|
|
465
|
+
opts.nestedKey ?? "",
|
|
466
|
+
"name"
|
|
467
|
+
]),
|
|
468
|
+
ignore: new Set(opts.ignore.split(",").map((v) => v.trim()).filter(Boolean))
|
|
469
|
+
};
|
|
470
|
+
result.inspectOptions.customStringify = {
|
|
471
|
+
number: result.types.number.color,
|
|
472
|
+
boolean: result.types.boolean.color,
|
|
473
|
+
string: result.types.string.color,
|
|
474
|
+
stringRemaining: result.colorFallback
|
|
475
|
+
};
|
|
476
|
+
return result;
|
|
529
477
|
}
|
|
530
478
|
const randColor = withCache((str) => {
|
|
531
|
-
|
|
532
|
-
var index = hash % RAND_COLOR_LIST.length;
|
|
533
|
-
return RAND_COLOR_LIST[index];
|
|
479
|
+
return RAND_COLOR_LIST[(crc32(str) >>> 0) % RAND_COLOR_LIST.length];
|
|
534
480
|
});
|
|
535
481
|
function createColorizeFn(colorize, value) {
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
var result = v;
|
|
546
|
-
for (var color of colors) {
|
|
547
|
-
result = getColor(color)(result);
|
|
548
|
-
}
|
|
549
|
-
return result;
|
|
550
|
-
};
|
|
482
|
+
if (!colorize) return String;
|
|
483
|
+
if (value === "rand") return (v) => getColor(randColor(v))(v);
|
|
484
|
+
var colors = arrayable(value);
|
|
485
|
+
if (!colors.length) return String;
|
|
486
|
+
return (v) => {
|
|
487
|
+
var result = v;
|
|
488
|
+
for (var color of colors) result = getColor(color)(result);
|
|
489
|
+
return result;
|
|
490
|
+
};
|
|
551
491
|
}
|
|
552
492
|
function createColorizeBadgeFn(colorize, value) {
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
colors.push("black");
|
|
567
|
-
return (v) => {
|
|
568
|
-
var result = v;
|
|
569
|
-
for (var color of colors) {
|
|
570
|
-
result = getColor(color)(result);
|
|
571
|
-
}
|
|
572
|
-
return result;
|
|
573
|
-
};
|
|
493
|
+
if (!colorize) return String;
|
|
494
|
+
if (value === "rand") return (v) => getColor(randColor(v))(v);
|
|
495
|
+
var colors = arrayable(value).map((v) => {
|
|
496
|
+
if (v.startsWith("bg")) v = v.slice(2);
|
|
497
|
+
return `bg${capitalize(v)}`;
|
|
498
|
+
});
|
|
499
|
+
if (!colors.length) return String;
|
|
500
|
+
colors.push("black");
|
|
501
|
+
return (v) => {
|
|
502
|
+
var result = v;
|
|
503
|
+
for (var color of colors) result = getColor(color)(result);
|
|
504
|
+
return result;
|
|
505
|
+
};
|
|
574
506
|
}
|
|
575
|
-
|
|
576
507
|
function isSerializedError(value) {
|
|
577
|
-
|
|
508
|
+
return has(value, [
|
|
509
|
+
"type",
|
|
510
|
+
"message",
|
|
511
|
+
"stack"
|
|
512
|
+
]);
|
|
578
513
|
}
|
|
579
514
|
function parseStack(stack, message) {
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
return lines;
|
|
515
|
+
const cwd = process.cwd() + path.sep;
|
|
516
|
+
return stack.split("\n").splice(message.split("\n").length).map((l) => l.trim().replace("file://", "").replace(cwd, ""));
|
|
583
517
|
}
|
|
584
518
|
function characterFormat(str) {
|
|
585
|
-
|
|
519
|
+
return str.replace(/`([^`]+)`/gm, (_, m) => getColor("cyan")(m)).replace(/\s+_([^_]+)_\s+/gm, (_, m) => ` ${getColor("underline")(m)} `);
|
|
586
520
|
}
|
|
587
521
|
function formatStack(stack, message, errorLevel, opts) {
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
${indent}` + parseStack(stack, message).map(
|
|
592
|
-
(line) => " " + line.replace(/\((.+)\)/, (_, m) => `(${colorizeStack(m)})`)
|
|
593
|
-
).join(`
|
|
594
|
-
${indent}`);
|
|
522
|
+
const indent = " ".repeat(opts.indent * errorLevel);
|
|
523
|
+
const colorizeStack = opts.types.errorStack?.color || opts.colorFallback;
|
|
524
|
+
return `\n${indent}` + parseStack(stack, message).map((line) => " " + line.replace(/\((.+)\)/, (_, m) => `(${colorizeStack(m)})`)).join(`\n${indent}`);
|
|
595
525
|
}
|
|
596
526
|
function formatDate(date, opts) {
|
|
597
|
-
|
|
527
|
+
return opts.ignore.has("time") ? "" : date.toLocaleTimeString();
|
|
598
528
|
}
|
|
599
529
|
function formatType(logObj, badge, opts) {
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
const type = opts.levels[logObj.level].icon || levelBadge;
|
|
606
|
-
const typeColor = opts.levels[logObj.level].color || opts.colorFallback;
|
|
607
|
-
return type ? typeColor(type) : "";
|
|
530
|
+
const levelBadge = opts.levels[logObj.level].badge || `LEVEL:${logObj.level}`;
|
|
531
|
+
if (badge) return (opts.levels[logObj.level]?.colorBadge || opts.colorFallback)(` ${levelBadge} `);
|
|
532
|
+
const type = opts.levels[logObj.level].icon || levelBadge;
|
|
533
|
+
const typeColor = opts.levels[logObj.level].color || opts.colorFallback;
|
|
534
|
+
return type ? typeColor(type) : "";
|
|
608
535
|
}
|
|
609
536
|
function filterAndJoin(arr) {
|
|
610
|
-
|
|
537
|
+
return arr.filter(Boolean).join(" ");
|
|
611
538
|
}
|
|
612
539
|
function formatError(err, errorLevel, opts) {
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
540
|
+
const message = (err.type ? `${err.type}: ` : "") + (err.message ?? formatWithOptions({
|
|
541
|
+
depth: opts.depth,
|
|
542
|
+
colors: opts.colorize
|
|
543
|
+
}, err));
|
|
544
|
+
const colorizeError = opts.types.error?.color || opts.colorFallback;
|
|
545
|
+
const stack = err.stack ? formatStack(err.stack, message, errorLevel, opts) : "";
|
|
546
|
+
const causedPrefix = errorLevel > 0 ? `${" ".repeat(opts.indent * errorLevel)}[cause]: ` : "";
|
|
547
|
+
const causedError = err.cause ? "\n\n" + formatError(err.cause, errorLevel + 1, opts) : "";
|
|
548
|
+
return colorizeError(causedPrefix + message + stack + causedError);
|
|
619
549
|
}
|
|
620
550
|
function formatAdditional(obj, opts) {
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
additional[key] = obj[key];
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
if (empty) {
|
|
635
|
-
return "";
|
|
636
|
-
}
|
|
637
|
-
const colorizeObject = opts.types.object?.color || opts.colorFallback;
|
|
638
|
-
return colorizeObject(opts.inspectFn(additional, opts.inspectOptions));
|
|
551
|
+
const additional = {};
|
|
552
|
+
let empty = true;
|
|
553
|
+
if (isSerializedError(obj)) return formatError(obj, 0, opts);
|
|
554
|
+
else for (const key in obj) {
|
|
555
|
+
empty = false;
|
|
556
|
+
if (isSerializedError(obj[key])) def(obj[key], inspect.custom, () => formatError(obj[key], 0, opts));
|
|
557
|
+
additional[key] = obj[key];
|
|
558
|
+
}
|
|
559
|
+
if (empty) return "";
|
|
560
|
+
return (opts.types.object?.color || opts.colorFallback)(opts.inspectFn(additional, opts.inspectOptions));
|
|
639
561
|
}
|
|
640
562
|
function pretty(logObj) {
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
}
|
|
657
|
-
return isBadge ? "\n" + line + "\n" : line;
|
|
563
|
+
const opts = this;
|
|
564
|
+
const message = isString(logObj[opts.messageKey]) ? logObj[opts.messageKey] : "";
|
|
565
|
+
const additional = opts.nestedKey ? formatAdditional(logObj[opts.nestedKey], opts) : formatAdditional(omit(logObj, opts.ignoreAdditional), opts);
|
|
566
|
+
const date = formatDate(new Date(logObj.time), opts);
|
|
567
|
+
const coloredDate = date ? opts.types.time.color(date) : "";
|
|
568
|
+
const isBadge = logObj.level >= opts.badgeMinLevel;
|
|
569
|
+
const type = formatType(logObj, isBadge, opts);
|
|
570
|
+
const name = logObj.name ? opts.types.name.color(logObj.name) : "";
|
|
571
|
+
let line;
|
|
572
|
+
const left = filterAndJoin([type, characterFormat(message)]);
|
|
573
|
+
const right = filterAndJoin([name, coloredDate]);
|
|
574
|
+
const space = opts.columns - opts.sw.width(left) - opts.sw.width(right) - 2;
|
|
575
|
+
line = space > 0 && opts.columns >= 80 ? left + " ".repeat(space) + right : (right ? `[${right}] ` : "") + left;
|
|
576
|
+
if (additional) line += "\n" + additional;
|
|
577
|
+
return isBadge ? "\n" + line + "\n" : line;
|
|
658
578
|
}
|
|
659
|
-
|
|
660
579
|
function prettyFactory(options) {
|
|
661
|
-
|
|
662
|
-
|
|
580
|
+
const opts = parseOptions(options);
|
|
581
|
+
return pretty.bind(opts);
|
|
663
582
|
}
|
|
664
583
|
function build(opts = {}) {
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
destination.on("close", () => {
|
|
707
|
-
cb(err);
|
|
708
|
-
});
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
);
|
|
584
|
+
var destination;
|
|
585
|
+
return abstractTransport(function(source) {
|
|
586
|
+
var pretty = prettyFactory({
|
|
587
|
+
messageKey: source.messageKey || "msg",
|
|
588
|
+
...opts
|
|
589
|
+
});
|
|
590
|
+
var extraLine = false;
|
|
591
|
+
var line;
|
|
592
|
+
const stream = new Transform({
|
|
593
|
+
objectMode: true,
|
|
594
|
+
autoDestroy: true,
|
|
595
|
+
transform(chunk, enc, cb) {
|
|
596
|
+
line = pretty(chunk);
|
|
597
|
+
if (line.endsWith("\n")) extraLine = true;
|
|
598
|
+
else if (extraLine) {
|
|
599
|
+
line = "\n" + line + "\n";
|
|
600
|
+
extraLine = false;
|
|
601
|
+
} else line = line + "\n";
|
|
602
|
+
cb(null, line);
|
|
603
|
+
}
|
|
604
|
+
});
|
|
605
|
+
destination = buildSafeSonicBoom({
|
|
606
|
+
dest: 1,
|
|
607
|
+
append: true,
|
|
608
|
+
mkdir: true,
|
|
609
|
+
sync: false
|
|
610
|
+
});
|
|
611
|
+
source.on("unknown", function(line) {
|
|
612
|
+
destination.write(line + "\n");
|
|
613
|
+
});
|
|
614
|
+
pump(source, stream, destination);
|
|
615
|
+
return stream;
|
|
616
|
+
}, {
|
|
617
|
+
expectPinoConfig: true,
|
|
618
|
+
enablePipelining: false,
|
|
619
|
+
close(err, cb) {
|
|
620
|
+
destination.on("close", () => {
|
|
621
|
+
cb(err);
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
});
|
|
712
625
|
}
|
|
713
|
-
|
|
714
626
|
export { build, build as default };
|
|
715
|
-
|
|
627
|
+
|
|
628
|
+
//# sourceMappingURL=index.mjs.map
|