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