@andrew_l/pino-pretty 0.2.17
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/LICENSE +21 -0
- package/README.md +106 -0
- package/dist/index.cjs +596 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +181 -0
- package/dist/index.d.mts +181 -0
- package/dist/index.d.ts +181 -0
- package/dist/index.mjs +571 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +47 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,596 @@
|
|
|
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 inspectString(str, opts) {
|
|
224
|
+
var processedStr = str;
|
|
225
|
+
if (str.length > opts.maxStringLength) {
|
|
226
|
+
var remaining = str.length - opts.maxStringLength;
|
|
227
|
+
var trailer = `... ${remaining} more character${remaining > 1 ? "s" : ""}`;
|
|
228
|
+
processedStr = str.slice(0, opts.maxStringLength);
|
|
229
|
+
return inspectString(processedStr, opts) + trailer;
|
|
230
|
+
}
|
|
231
|
+
var quoteRegex = QUOTE_REGEX[opts.quoteStyle];
|
|
232
|
+
var escaped = processedStr.replace(quoteRegex, "\\$1").replace(/[\x00-\x1f]/g, (char) => {
|
|
233
|
+
var code = char.charCodeAt(0);
|
|
234
|
+
var escapeChar = ESCAPE_CHARS[code];
|
|
235
|
+
return escapeChar ? `\\${escapeChar}` : `\\x${code.toString(16).padStart(2, "0").toUpperCase()}`;
|
|
236
|
+
});
|
|
237
|
+
var quote = QUOTES[opts.quoteStyle];
|
|
238
|
+
var result = `${quote}${escaped}${quote}`;
|
|
239
|
+
return opts.customStringify.string?.(result) ?? result;
|
|
240
|
+
}
|
|
241
|
+
function getIndentStrings(opts, depth) {
|
|
242
|
+
if (depth === 0) return { base: " ".repeat(opts.indent), prev: "" };
|
|
243
|
+
return {
|
|
244
|
+
base: " ".repeat(opts.indent),
|
|
245
|
+
prev: " ".repeat(opts.indent * depth)
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
function isSingleLine(values) {
|
|
249
|
+
return values.every((value) => !value.includes("\n"));
|
|
250
|
+
}
|
|
251
|
+
function formatMultiline(values, indent) {
|
|
252
|
+
if (values.length === 0) return "";
|
|
253
|
+
var lineJoiner = `
|
|
254
|
+
${indent.prev}${indent.base}`;
|
|
255
|
+
return `${lineJoiner}${values.join(`,${lineJoiner}`)}
|
|
256
|
+
${indent.prev}`;
|
|
257
|
+
}
|
|
258
|
+
function getObjectEntries(obj, inspectFn) {
|
|
259
|
+
var isArray = Array.isArray(obj);
|
|
260
|
+
var entries = [];
|
|
261
|
+
if (isArray) {
|
|
262
|
+
for (var i = 0; i < obj.length; i++) {
|
|
263
|
+
entries[i] = Object.hasOwn(obj, i) ? inspectFn(obj[i], obj) : "";
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
for (var key in obj) {
|
|
267
|
+
if (!Object.hasOwn(obj, key)) continue;
|
|
268
|
+
if (isArray && /^\d+$/.test(key) && Number(key) < obj.length) continue;
|
|
269
|
+
var needsQuotes = /[^\w$]/.test(key);
|
|
270
|
+
var keyStr = needsQuotes ? inspectFn(key, obj) : key;
|
|
271
|
+
entries.push(`${keyStr}: ${inspectFn(obj[key], obj)}`);
|
|
272
|
+
}
|
|
273
|
+
return entries;
|
|
274
|
+
}
|
|
275
|
+
function inspectValue(obj, opts, depth, seen) {
|
|
276
|
+
if (obj === void 0)
|
|
277
|
+
return opts.customStringify.undefined?.(obj) ?? "undefined";
|
|
278
|
+
if (obj === null) return opts.customStringify.null?.(obj) ?? "null";
|
|
279
|
+
if (typeof obj === "boolean")
|
|
280
|
+
return opts.customStringify.boolean?.(obj) ?? String(obj);
|
|
281
|
+
if (typeof obj === "string") return inspectString(obj, opts);
|
|
282
|
+
if (typeof obj === "number") {
|
|
283
|
+
if (obj === 0) return Object.is(obj, -0) ? "-0" : "0";
|
|
284
|
+
var str = String(obj);
|
|
285
|
+
var result = opts.numericSeparator ? addNumericSeparator(obj, str) : str;
|
|
286
|
+
return opts.customStringify.number?.(result) ?? result;
|
|
287
|
+
}
|
|
288
|
+
if (typeof obj === "bigint") {
|
|
289
|
+
var str = `${obj}n`;
|
|
290
|
+
var result = opts.numericSeparator ? addNumericSeparator(obj, str) : str;
|
|
291
|
+
return opts.customStringify.number?.(result) ?? result;
|
|
292
|
+
}
|
|
293
|
+
if (depth >= opts.depth && opts.depth > 0 && typeof obj === "object") {
|
|
294
|
+
return Array.isArray(obj) ? "[Array]" : "[Object]";
|
|
295
|
+
}
|
|
296
|
+
if (seen.has(obj)) return "[Circular]";
|
|
297
|
+
seen.add(obj);
|
|
298
|
+
var indent = getIndentStrings(opts, depth);
|
|
299
|
+
var inspectChild = (value) => inspectValue(value, opts, depth + 1, seen);
|
|
300
|
+
if (Array.isArray(obj)) {
|
|
301
|
+
if (obj.length === 0) return "[]";
|
|
302
|
+
var entries = getObjectEntries(obj, inspectChild);
|
|
303
|
+
if (indent.base && !isSingleLine(entries)) {
|
|
304
|
+
return `[${formatMultiline(entries, indent)}]`;
|
|
305
|
+
}
|
|
306
|
+
return `[ ${entries.join(", ")} ]`;
|
|
307
|
+
}
|
|
308
|
+
if (toolkit.isObject(obj)) {
|
|
309
|
+
if (toolkit.isFunction(obj[node_util.inspect.custom])) {
|
|
310
|
+
var lineJoiner = `
|
|
311
|
+
${indent.prev}`;
|
|
312
|
+
return node_util.inspect(obj, { depth: opts.depth - depth }).split("\n").join(lineJoiner);
|
|
313
|
+
}
|
|
314
|
+
var entries = getObjectEntries(obj, inspectChild);
|
|
315
|
+
if (entries.length === 0) return "{}";
|
|
316
|
+
if (indent.base) {
|
|
317
|
+
return `{${formatMultiline(entries, indent)}}`;
|
|
318
|
+
}
|
|
319
|
+
return `{ ${entries.join(", ")} }`;
|
|
320
|
+
}
|
|
321
|
+
seen.delete(obj);
|
|
322
|
+
return String(obj);
|
|
323
|
+
}
|
|
324
|
+
function inspect(obj, options) {
|
|
325
|
+
return inspectValue(obj, options, 0, /* @__PURE__ */ new WeakSet());
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function parseOptions(value) {
|
|
329
|
+
const defOptions = {
|
|
330
|
+
columns: 80,
|
|
331
|
+
indent: 2,
|
|
332
|
+
depth: 5,
|
|
333
|
+
messageKey: "msg",
|
|
334
|
+
quoteStyle: "single",
|
|
335
|
+
badgeMinLevel: 40,
|
|
336
|
+
maxStringLength: 400,
|
|
337
|
+
numericSeparator: false,
|
|
338
|
+
ignore: "hostname,pid",
|
|
339
|
+
colorize: true,
|
|
340
|
+
types: {
|
|
341
|
+
number: { color: "green" },
|
|
342
|
+
boolean: { color: "redBright" },
|
|
343
|
+
string: { color: "yellow" },
|
|
344
|
+
object: { color: "gray" },
|
|
345
|
+
error: { color: "gray" },
|
|
346
|
+
errorStack: { color: "cyan" },
|
|
347
|
+
time: { color: "gray" },
|
|
348
|
+
name: { color: "rand" }
|
|
349
|
+
},
|
|
350
|
+
levels: {
|
|
351
|
+
10: { badge: "TRACE", color: "gray", icon: "\u2192" },
|
|
352
|
+
20: { badge: "DEBUG", color: "blue", icon: "\u2699" },
|
|
353
|
+
30: { badge: "INFO", color: "cyan", icon: "\u2139" },
|
|
354
|
+
40: { badge: "WARN", color: "yellow", icon: "\u26A0" },
|
|
355
|
+
50: { badge: "ERROR", color: "red", icon: "\u2716" },
|
|
356
|
+
60: { badge: "FATAL", color: "red", icon: "\u2716" }
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
const opts = toolkit.deepDefaults({}, value, defOptions);
|
|
360
|
+
const sw = new stringWidth.StringWidth({
|
|
361
|
+
extraWidths: new Map(
|
|
362
|
+
Object.values(opts.levels).map((v) => [v.icon.charCodeAt(0), 1])
|
|
363
|
+
)
|
|
364
|
+
});
|
|
365
|
+
const result = {
|
|
366
|
+
...opts,
|
|
367
|
+
sw,
|
|
368
|
+
colorFallback: createColorizeFn(opts.colorize, "gray"),
|
|
369
|
+
inspect: {
|
|
370
|
+
depth: opts.depth,
|
|
371
|
+
quoteStyle: opts.quoteStyle,
|
|
372
|
+
indent: opts.indent,
|
|
373
|
+
maxStringLength: opts.maxStringLength,
|
|
374
|
+
numericSeparator: opts.numericSeparator,
|
|
375
|
+
customStringify: {}
|
|
376
|
+
},
|
|
377
|
+
levels: Object.fromEntries(
|
|
378
|
+
Object.entries(opts.levels).map(([key, value2]) => [
|
|
379
|
+
key,
|
|
380
|
+
{
|
|
381
|
+
...value2,
|
|
382
|
+
color: createColorizeFn(opts.colorize, value2.color),
|
|
383
|
+
colorBadge: createColorizeBadgeFn(opts.colorize, value2.color)
|
|
384
|
+
}
|
|
385
|
+
])
|
|
386
|
+
),
|
|
387
|
+
types: Object.fromEntries(
|
|
388
|
+
Object.entries(opts.types).map(([key, value2]) => [
|
|
389
|
+
key,
|
|
390
|
+
{
|
|
391
|
+
...value2,
|
|
392
|
+
color: createColorizeFn(opts.colorize, value2.color)
|
|
393
|
+
}
|
|
394
|
+
])
|
|
395
|
+
),
|
|
396
|
+
ignoreAdditional: /* @__PURE__ */ new Set([
|
|
397
|
+
"level",
|
|
398
|
+
"time",
|
|
399
|
+
"pid",
|
|
400
|
+
"hostname",
|
|
401
|
+
opts.messageKey,
|
|
402
|
+
opts.nestedKey ?? "",
|
|
403
|
+
"name"
|
|
404
|
+
]),
|
|
405
|
+
ignore: new Set(
|
|
406
|
+
opts.ignore.split(",").map((v) => v.trim()).filter(Boolean)
|
|
407
|
+
)
|
|
408
|
+
};
|
|
409
|
+
result.inspect.customStringify = {
|
|
410
|
+
number: result.types.number.color,
|
|
411
|
+
boolean: result.types.boolean.color,
|
|
412
|
+
string: result.types.string.color
|
|
413
|
+
};
|
|
414
|
+
return result;
|
|
415
|
+
}
|
|
416
|
+
const randColor = toolkit.withCache((str) => {
|
|
417
|
+
var hash = toolkit.crc32(str) >>> 0;
|
|
418
|
+
var index = hash % RAND_COLOR_LIST.length;
|
|
419
|
+
return RAND_COLOR_LIST[index];
|
|
420
|
+
});
|
|
421
|
+
function createColorizeFn(colorize, value) {
|
|
422
|
+
if (!colorize) {
|
|
423
|
+
return String;
|
|
424
|
+
}
|
|
425
|
+
if (value === "rand") {
|
|
426
|
+
return (v) => getColor(randColor(v))(v);
|
|
427
|
+
}
|
|
428
|
+
var colors = toolkit.arrayable(value);
|
|
429
|
+
if (!colors.length) return String;
|
|
430
|
+
return (v) => {
|
|
431
|
+
var result = v;
|
|
432
|
+
for (var color of colors) {
|
|
433
|
+
result = getColor(color)(result);
|
|
434
|
+
}
|
|
435
|
+
return result;
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
function createColorizeBadgeFn(colorize, value) {
|
|
439
|
+
if (!colorize) {
|
|
440
|
+
return String;
|
|
441
|
+
}
|
|
442
|
+
if (value === "rand") {
|
|
443
|
+
return (v) => getColor(randColor(v))(v);
|
|
444
|
+
}
|
|
445
|
+
var colors = toolkit.arrayable(value).map((v) => {
|
|
446
|
+
if (v.startsWith("bg")) {
|
|
447
|
+
v = v.slice(2);
|
|
448
|
+
}
|
|
449
|
+
return `bg${toolkit.capitalize(v)}`;
|
|
450
|
+
});
|
|
451
|
+
if (!colors.length) return String;
|
|
452
|
+
colors.push("black");
|
|
453
|
+
return (v) => {
|
|
454
|
+
var result = v;
|
|
455
|
+
for (var color of colors) {
|
|
456
|
+
result = getColor(color)(result);
|
|
457
|
+
}
|
|
458
|
+
return result;
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
function isSerializedError(value) {
|
|
463
|
+
return toolkit.has(value, ["type", "message", "stack"]);
|
|
464
|
+
}
|
|
465
|
+
function parseStack(stack, message) {
|
|
466
|
+
const cwd = process.cwd() + path__default.sep;
|
|
467
|
+
const lines = stack.split("\n").splice(message.split("\n").length).map((l) => l.trim().replace("file://", "").replace(cwd, ""));
|
|
468
|
+
return lines;
|
|
469
|
+
}
|
|
470
|
+
function characterFormat(str) {
|
|
471
|
+
return str.replace(/`([^`]+)`/gm, (_, m) => getColor("cyan")(m)).replace(/\s+_([^_]+)_\s+/gm, (_, m) => ` ${getColor("underline")(m)} `);
|
|
472
|
+
}
|
|
473
|
+
function formatStack(stack, message, errorLevel, opts) {
|
|
474
|
+
const indent = " ".repeat(opts.indent * errorLevel);
|
|
475
|
+
const colorizeStack = opts.types.errorStack?.color || opts.colorFallback;
|
|
476
|
+
return `
|
|
477
|
+
${indent}` + parseStack(stack, message).map(
|
|
478
|
+
(line) => " " + line.replace(/\((.+)\)/, (_, m) => `(${colorizeStack(m)})`)
|
|
479
|
+
).join(`
|
|
480
|
+
${indent}`);
|
|
481
|
+
}
|
|
482
|
+
function formatDate(date, opts) {
|
|
483
|
+
return opts.ignore.has("time") ? "" : date.toLocaleTimeString();
|
|
484
|
+
}
|
|
485
|
+
function formatType(logObj, badge, opts) {
|
|
486
|
+
const levelBadge = opts.levels[logObj.level].badge || `LEVEL:${logObj.level}`;
|
|
487
|
+
if (badge) {
|
|
488
|
+
const colorize = opts.levels[logObj.level]?.colorBadge || opts.colorFallback;
|
|
489
|
+
return colorize(` ${levelBadge} `);
|
|
490
|
+
}
|
|
491
|
+
const type = opts.levels[logObj.level].icon || levelBadge;
|
|
492
|
+
const typeColor = opts.levels[logObj.level].color || opts.colorFallback;
|
|
493
|
+
return type ? typeColor(type) : "";
|
|
494
|
+
}
|
|
495
|
+
function filterAndJoin(arr) {
|
|
496
|
+
return arr.filter(Boolean).join(" ");
|
|
497
|
+
}
|
|
498
|
+
function formatError(err, errorLevel, opts) {
|
|
499
|
+
const message = (err.type ? `${err.type}: ` : "") + (err.message ?? node_util.formatWithOptions({ depth: opts.depth, colors: opts.colorize }, err));
|
|
500
|
+
const colorizeError = opts.types.error?.color || opts.colorFallback;
|
|
501
|
+
const stack = err.stack ? formatStack(err.stack, message, errorLevel, opts) : "";
|
|
502
|
+
const causedPrefix = errorLevel > 0 ? `${" ".repeat(opts.indent * errorLevel)}[cause]: ` : "";
|
|
503
|
+
const causedError = err.cause ? "\n\n" + formatError(err.cause, errorLevel + 1, opts) : "";
|
|
504
|
+
return colorizeError(causedPrefix + message + stack + causedError);
|
|
505
|
+
}
|
|
506
|
+
function formatAdditional(obj, opts) {
|
|
507
|
+
const additional = {};
|
|
508
|
+
let empty = true;
|
|
509
|
+
if (isSerializedError(obj)) {
|
|
510
|
+
return formatError(obj, 0, opts);
|
|
511
|
+
} else {
|
|
512
|
+
for (const key in obj) {
|
|
513
|
+
empty = false;
|
|
514
|
+
if (isSerializedError(obj[key])) {
|
|
515
|
+
additional[key] = {
|
|
516
|
+
...obj[key],
|
|
517
|
+
[node_util.inspect.custom]: () => formatError(obj[key], 0, opts)
|
|
518
|
+
};
|
|
519
|
+
} else {
|
|
520
|
+
additional[key] = obj[key];
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
if (empty) {
|
|
525
|
+
return "";
|
|
526
|
+
}
|
|
527
|
+
const colorizeObject = opts.types.object?.color || opts.colorFallback;
|
|
528
|
+
return colorizeObject(inspect(additional, opts.inspect).slice(2, -2));
|
|
529
|
+
}
|
|
530
|
+
function pretty(logObj) {
|
|
531
|
+
const opts = this;
|
|
532
|
+
const message = toolkit.isString(logObj[opts.messageKey]) ? logObj[opts.messageKey] : "";
|
|
533
|
+
const additional = opts.nestedKey ? formatAdditional(logObj[opts.nestedKey], opts) : formatAdditional(toolkit.omit(logObj, opts.ignoreAdditional), opts);
|
|
534
|
+
const date = formatDate(new Date(logObj.time), opts);
|
|
535
|
+
const coloredDate = date ? opts.types.time.color(date) : "";
|
|
536
|
+
const isBadge = logObj.level >= opts.badgeMinLevel;
|
|
537
|
+
const type = formatType(logObj, isBadge, opts);
|
|
538
|
+
const name = logObj.name ? opts.types.name.color(logObj.name) : "";
|
|
539
|
+
let line;
|
|
540
|
+
const left = filterAndJoin([type, characterFormat(message)]);
|
|
541
|
+
const right = filterAndJoin([name, coloredDate]);
|
|
542
|
+
const space = opts.columns - opts.sw.width(left) - opts.sw.width(right) - 2;
|
|
543
|
+
line = space > 0 && opts.columns >= 80 ? left + " ".repeat(space) + right : (right ? `[${right}] ` : "") + left;
|
|
544
|
+
if (additional) {
|
|
545
|
+
line += "\n" + additional;
|
|
546
|
+
}
|
|
547
|
+
return isBadge ? "\n" + line + "\n" : line;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function prettyFactory(options) {
|
|
551
|
+
const opts = parseOptions(options);
|
|
552
|
+
return pretty.bind(opts);
|
|
553
|
+
}
|
|
554
|
+
function build(opts = {}) {
|
|
555
|
+
var destination;
|
|
556
|
+
return abstractTransport__default(
|
|
557
|
+
function(source) {
|
|
558
|
+
var pretty2 = prettyFactory({
|
|
559
|
+
messageKey: source.messageKey || "msg",
|
|
560
|
+
...opts
|
|
561
|
+
});
|
|
562
|
+
const stream = new node_stream.Transform({
|
|
563
|
+
objectMode: true,
|
|
564
|
+
autoDestroy: true,
|
|
565
|
+
transform(chunk, enc, cb) {
|
|
566
|
+
const line = pretty2(chunk);
|
|
567
|
+
cb(null, line + "\n");
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
destination = buildSafeSonicBoom({
|
|
571
|
+
dest: 1,
|
|
572
|
+
append: true,
|
|
573
|
+
mkdir: true,
|
|
574
|
+
sync: false
|
|
575
|
+
});
|
|
576
|
+
source.on("unknown", function(line) {
|
|
577
|
+
destination.write(line + "\n");
|
|
578
|
+
});
|
|
579
|
+
pump__default(source, stream, destination);
|
|
580
|
+
return stream;
|
|
581
|
+
},
|
|
582
|
+
{
|
|
583
|
+
expectPinoConfig: true,
|
|
584
|
+
enablePipelining: false,
|
|
585
|
+
close(err, cb) {
|
|
586
|
+
destination.on("close", () => {
|
|
587
|
+
cb(err);
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
);
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
exports.build = build;
|
|
595
|
+
exports.default = build;
|
|
596
|
+
//# sourceMappingURL=index.cjs.map
|