@visulima/pail 2.1.16 → 2.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/dist/index.browser.cjs +19 -1
- package/dist/index.browser.mjs +14 -1
- package/dist/index.server.cjs +442 -5
- package/dist/index.server.mjs +437 -5
- package/dist/packem_shared/CallerProcessor-CyJFdYGN.mjs +58 -0
- package/dist/packem_shared/CallerProcessor-DYrXv6Fp.cjs +60 -0
- package/dist/packem_shared/JsonFileReporter-BHaRQMnS.cjs +135 -0
- package/dist/packem_shared/JsonFileReporter-CdHau53i.mjs +133 -0
- package/dist/packem_shared/JsonReporter-C05lFJhj.mjs +20 -0
- package/dist/packem_shared/JsonReporter-DCd8dbfQ.mjs +32 -0
- package/dist/packem_shared/JsonReporter-DDubAhfJ.cjs +22 -0
- package/dist/packem_shared/JsonReporter-HXYHZuWz.cjs +34 -0
- package/dist/packem_shared/MessageFormatterProcessor-CFyi7GWt.mjs +53 -0
- package/dist/packem_shared/MessageFormatterProcessor-D_txQ9nO.cjs +55 -0
- package/dist/packem_shared/PrettyReporter-Bx3QLZrW.mjs +162 -0
- package/dist/packem_shared/PrettyReporter-LWDDriJ1.cjs +200 -0
- package/dist/packem_shared/PrettyReporter-XC0Ix5SW.mjs +192 -0
- package/dist/packem_shared/PrettyReporter-mFCjMb0i.cjs +168 -0
- package/dist/packem_shared/RedactProcessor-CfNkF2lC.mjs +26 -0
- package/dist/packem_shared/RedactProcessor-DWE5iqAQ.cjs +26 -0
- package/dist/packem_shared/SimpleReporter-CuNgsGVB.mjs +178 -0
- package/dist/packem_shared/SimpleReporter-DabZGkIs.cjs +186 -0
- package/dist/packem_shared/abstract-json-reporter-CG0EXqip.mjs +55 -0
- package/dist/packem_shared/abstract-json-reporter-D4MiU6B-.cjs +57 -0
- package/dist/packem_shared/abstract-pretty-reporter-BR_6_JVa.cjs +49 -0
- package/dist/packem_shared/abstract-pretty-reporter-izJgxoMv.mjs +46 -0
- package/dist/packem_shared/constants-BYYZ5WNW.mjs +114 -0
- package/dist/packem_shared/constants-DHfYGxxG.cjs +118 -0
- package/dist/packem_shared/format-label-CQCvMzlF.cjs +622 -0
- package/dist/packem_shared/format-label-DYMZf3Bg.mjs +610 -0
- package/dist/packem_shared/get-longest-label-CM8kLFWH.mjs +11 -0
- package/dist/packem_shared/get-longest-label-CQ7lRhgD.cjs +13 -0
- package/dist/packem_shared/pail.browser-B3Bi2uPA.cjs +387 -0
- package/dist/packem_shared/pail.browser-DZLrCtc5.mjs +384 -0
- package/dist/packem_shared/write-console-log-Cu0-IDN-.cjs +18 -0
- package/dist/packem_shared/write-console-log-Tptfzg9D.mjs +16 -0
- package/dist/packem_shared/write-stream-BBAF33Zm.mjs +8 -0
- package/dist/packem_shared/write-stream-CkNf2Ju8.cjs +10 -0
- package/dist/processor.browser.cjs +11 -1
- package/dist/processor.browser.mjs +2 -1
- package/dist/processor.server.cjs +13 -1
- package/dist/processor.server.mjs +3 -1
- package/dist/reporter.browser.cjs +11 -1
- package/dist/reporter.browser.mjs +2 -1
- package/dist/reporter.server.cjs +15 -1
- package/dist/reporter.server.mjs +4 -1
- package/package.json +14 -14
- package/dist/packem_shared/CallerProcessor-BBHkvRgS.mjs +0 -1
- package/dist/packem_shared/CallerProcessor-CLoY9R76.cjs +0 -1
- package/dist/packem_shared/JsonFileReporter-CLEMnuGI.cjs +0 -2
- package/dist/packem_shared/JsonFileReporter-lr0s7r9B.mjs +0 -4
- package/dist/packem_shared/JsonReporter-CiQkPCv4.cjs +0 -2
- package/dist/packem_shared/JsonReporter-CjvkrXUp.cjs +0 -1
- package/dist/packem_shared/JsonReporter-DInAbLuf.mjs +0 -1
- package/dist/packem_shared/JsonReporter-J50eZjl2.mjs +0 -2
- package/dist/packem_shared/MessageFormatterProcessor-CCRIUIdT.cjs +0 -1
- package/dist/packem_shared/MessageFormatterProcessor-D_XajTuK.mjs +0 -1
- package/dist/packem_shared/PrettyReporter-1SleqVaI.mjs +0 -13
- package/dist/packem_shared/PrettyReporter-C_AJrNOj.mjs +0 -5
- package/dist/packem_shared/PrettyReporter-CldK9UpN.cjs +0 -13
- package/dist/packem_shared/PrettyReporter-CuJWFD0k.cjs +0 -5
- package/dist/packem_shared/RedactProcessor-BVZtatWJ.cjs +0 -1
- package/dist/packem_shared/RedactProcessor-CxKTN42V.mjs +0 -3
- package/dist/packem_shared/SimpleReporter-Cy_0ZeXQ.cjs +0 -11
- package/dist/packem_shared/SimpleReporter-DzUWU5Gu.mjs +0 -11
- package/dist/packem_shared/abstract-json-reporter-29d4dwOH.mjs +0 -1
- package/dist/packem_shared/abstract-json-reporter-Z6bVrpPK.cjs +0 -1
- package/dist/packem_shared/abstract-pretty-reporter-CZb4ET-0.cjs +0 -1
- package/dist/packem_shared/abstract-pretty-reporter-DgXRHEj-.mjs +0 -1
- package/dist/packem_shared/constants-BFrKdBPm.cjs +0 -1
- package/dist/packem_shared/constants-BMS51p6Y.mjs +0 -1
- package/dist/packem_shared/format-label-B0BaeOry.cjs +0 -8
- package/dist/packem_shared/format-label-ECls2QEw.mjs +0 -8
- package/dist/packem_shared/get-longest-label-4ISUsE2q.mjs +0 -1
- package/dist/packem_shared/get-longest-label-DXpzhu5N.cjs +0 -1
- package/dist/packem_shared/pail.browser-D7k9K5zt.mjs +0 -1
- package/dist/packem_shared/pail.browser-tTEE0Aky.cjs +0 -1
- package/dist/packem_shared/write-console-log-3G15muTS.cjs +0 -1
- package/dist/packem_shared/write-console-log-BP95fgQZ.mjs +0 -1
- package/dist/packem_shared/write-stream-Bgxqp0HI.cjs +0 -1
- package/dist/packem_shared/write-stream-C17GXSxA.mjs +0 -1
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
4
|
+
|
|
5
|
+
const process = require('node:process');
|
|
6
|
+
const colorize = require('@visulima/colorize');
|
|
7
|
+
const error = require('@visulima/error/error');
|
|
8
|
+
const inspector = require('@visulima/inspector');
|
|
9
|
+
const formatLabel = require('./format-label-CQCvMzlF.cjs');
|
|
10
|
+
const constants = require('./constants-DHfYGxxG.cjs');
|
|
11
|
+
const abstractPrettyReporter = require('./abstract-pretty-reporter-BR_6_JVa.cjs');
|
|
12
|
+
const getLongestLabel = require('./get-longest-label-CQ7lRhgD.cjs');
|
|
13
|
+
const writeStream = require('./write-stream-CkNf2Ju8.cjs');
|
|
14
|
+
|
|
15
|
+
const _interopDefaultCompat = e => e && typeof e === 'object' && 'default' in e ? e.default : e;
|
|
16
|
+
|
|
17
|
+
const colorize__default = /*#__PURE__*/_interopDefaultCompat(colorize);
|
|
18
|
+
|
|
19
|
+
var __defProp = Object.defineProperty;
|
|
20
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
21
|
+
const pailFileFilter = /* @__PURE__ */ __name((line) => !/[\\/]pail[\\/]dist/.test(line), "pailFileFilter");
|
|
22
|
+
class PrettyReporter extends abstractPrettyReporter.AbstractPrettyReporter {
|
|
23
|
+
static {
|
|
24
|
+
__name(this, "PrettyReporter");
|
|
25
|
+
}
|
|
26
|
+
#stdout;
|
|
27
|
+
#stderr;
|
|
28
|
+
#interactiveManager;
|
|
29
|
+
#interactive = false;
|
|
30
|
+
#inspectOptions;
|
|
31
|
+
#errorOptions;
|
|
32
|
+
constructor(options = {}) {
|
|
33
|
+
const { error: errorOptions, inspect: inspectOptions, ...rest } = options;
|
|
34
|
+
super({
|
|
35
|
+
uppercase: {
|
|
36
|
+
label: true,
|
|
37
|
+
...rest.uppercase
|
|
38
|
+
},
|
|
39
|
+
...rest
|
|
40
|
+
});
|
|
41
|
+
this.#inspectOptions = { ...formatLabel.defaultInspectorConfig, ...inspectOptions };
|
|
42
|
+
this.#errorOptions = {
|
|
43
|
+
...errorOptions,
|
|
44
|
+
color: {
|
|
45
|
+
fileLine: colorize.green,
|
|
46
|
+
hint: colorize.cyan,
|
|
47
|
+
marker: colorize.red,
|
|
48
|
+
message: colorize.red,
|
|
49
|
+
method: colorize.greenBright,
|
|
50
|
+
title: colorize.red
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
this.#stdout = process.stdout;
|
|
54
|
+
this.#stderr = process.stderr;
|
|
55
|
+
}
|
|
56
|
+
setStdout(stdout_) {
|
|
57
|
+
this.#stdout = stdout_;
|
|
58
|
+
}
|
|
59
|
+
setStderr(stderr_) {
|
|
60
|
+
this.#stderr = stderr_;
|
|
61
|
+
}
|
|
62
|
+
setInteractiveManager(manager) {
|
|
63
|
+
this.#interactiveManager = manager;
|
|
64
|
+
}
|
|
65
|
+
setIsInteractive(interactive) {
|
|
66
|
+
this.#interactive = interactive;
|
|
67
|
+
}
|
|
68
|
+
log(meta) {
|
|
69
|
+
this._log(this._formatMessage(meta), meta.type.level);
|
|
70
|
+
}
|
|
71
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
72
|
+
_formatMessage(data) {
|
|
73
|
+
const { columns } = formatLabel.terminalSize();
|
|
74
|
+
let size = columns;
|
|
75
|
+
if (typeof this._styles.messageLength === "number") {
|
|
76
|
+
size = this._styles.messageLength;
|
|
77
|
+
}
|
|
78
|
+
const { badge, context, date, error: error$1, file, groups, label, message, prefix, repeated, scope, suffix, traceError, type } = data;
|
|
79
|
+
const { color } = this._loggerTypes[type.name];
|
|
80
|
+
const colorized = color ? colorize__default[color] : colorize.white;
|
|
81
|
+
const groupSpaces = groups.map(() => " ").join("");
|
|
82
|
+
const items = [];
|
|
83
|
+
if (groups.length > 0) {
|
|
84
|
+
items.push(groupSpaces + colorize.grey("[" + groups.at(-1) + "]") + " ");
|
|
85
|
+
}
|
|
86
|
+
if (date) {
|
|
87
|
+
items.push(colorize.grey(this._styles.dateFormatter(typeof date === "string" ? new Date(date) : date)) + " ");
|
|
88
|
+
}
|
|
89
|
+
if (badge) {
|
|
90
|
+
items.push(colorized(badge));
|
|
91
|
+
} else {
|
|
92
|
+
const longestBadge = abstractPrettyReporter.getLongestBadge(this._loggerTypes);
|
|
93
|
+
if (longestBadge.length > 0) {
|
|
94
|
+
items.push(colorize.grey(".".repeat(longestBadge.length)) + " ");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const longestLabel = getLongestLabel.getLongestLabel(this._loggerTypes);
|
|
98
|
+
if (label) {
|
|
99
|
+
items.push(colorized(formatLabel.formatLabel(label, this._styles)) + " ", colorize.grey(".".repeat(longestLabel.length - formatLabel.stringLength(label))));
|
|
100
|
+
} else {
|
|
101
|
+
items.push(colorize.grey(".".repeat(longestLabel.length + 2)));
|
|
102
|
+
}
|
|
103
|
+
if (repeated) {
|
|
104
|
+
items.push(colorize.bgGrey.white("[" + repeated + "x]") + " ");
|
|
105
|
+
}
|
|
106
|
+
if (Array.isArray(scope) && scope.length > 0) {
|
|
107
|
+
items.push(" " + colorize.grey("[" + scope.join(" > ") + "]") + " ");
|
|
108
|
+
}
|
|
109
|
+
if (prefix) {
|
|
110
|
+
items.push(
|
|
111
|
+
colorize.grey(
|
|
112
|
+
(Array.isArray(scope) && scope.length > 0 ? ". " : " ") + "[" + (this._styles.underline.prefix ? colorize.underline(prefix) : prefix) + "]"
|
|
113
|
+
) + " "
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
const titleSize = formatLabel.stringLength(items.join(" "));
|
|
117
|
+
if (file) {
|
|
118
|
+
const fileMessage = file.name + (file.line ? ":" + file.line : "");
|
|
119
|
+
const fileMessageSize = formatLabel.stringLength(fileMessage);
|
|
120
|
+
if (fileMessageSize + titleSize + 2 > size) {
|
|
121
|
+
items.push(colorize.grey(" " + fileMessage));
|
|
122
|
+
} else {
|
|
123
|
+
items.push(colorize.grey(".".repeat(size - titleSize - fileMessageSize - 2) + " " + fileMessage));
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
items.push(colorize.grey(".".repeat(size - titleSize - 1)));
|
|
127
|
+
}
|
|
128
|
+
if (items.length > 0) {
|
|
129
|
+
items.push("\n\n");
|
|
130
|
+
}
|
|
131
|
+
if (message !== constants.EMPTY_SYMBOL) {
|
|
132
|
+
const formattedMessage = typeof message === "string" ? message : inspector.inspect(message, this.#inspectOptions);
|
|
133
|
+
items.push(
|
|
134
|
+
groupSpaces + formatLabel.wrapAnsi(formattedMessage, size - 3, {
|
|
135
|
+
hard: true,
|
|
136
|
+
trim: false,
|
|
137
|
+
wordWrap: true
|
|
138
|
+
})
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
if (context) {
|
|
142
|
+
let hasError = false;
|
|
143
|
+
items.push(
|
|
144
|
+
...context.map((value) => {
|
|
145
|
+
if (value instanceof Error) {
|
|
146
|
+
hasError = true;
|
|
147
|
+
return "\n\n" + error.renderError(value, {
|
|
148
|
+
...this.#errorOptions,
|
|
149
|
+
filterStacktrace: pailFileFilter,
|
|
150
|
+
prefix: groupSpaces
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
if (typeof value === "object") {
|
|
154
|
+
return " " + inspector.inspect(value, this.#inspectOptions);
|
|
155
|
+
}
|
|
156
|
+
const newValue = (hasError ? "\n\n" : " ") + value;
|
|
157
|
+
hasError = false;
|
|
158
|
+
return newValue;
|
|
159
|
+
})
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
if (error$1) {
|
|
163
|
+
items.push(
|
|
164
|
+
error.renderError(error$1, {
|
|
165
|
+
...this.#errorOptions,
|
|
166
|
+
filterStacktrace: pailFileFilter,
|
|
167
|
+
prefix: groupSpaces
|
|
168
|
+
})
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
if (traceError) {
|
|
172
|
+
items.push(
|
|
173
|
+
"\n\n" + error.renderError(traceError, {
|
|
174
|
+
...this.#errorOptions,
|
|
175
|
+
filterStacktrace: pailFileFilter,
|
|
176
|
+
hideErrorCauseCodeView: true,
|
|
177
|
+
hideErrorCodeView: true,
|
|
178
|
+
hideErrorErrorsCodeView: true,
|
|
179
|
+
hideMessage: true,
|
|
180
|
+
prefix: groupSpaces
|
|
181
|
+
})
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
if (suffix) {
|
|
185
|
+
items.push("\n", groupSpaces + colorize.grey(this._styles.underline.suffix ? colorize.underline(suffix) : suffix));
|
|
186
|
+
}
|
|
187
|
+
return items.join("") + "\n";
|
|
188
|
+
}
|
|
189
|
+
_log(message, logLevel) {
|
|
190
|
+
const streamType = ["error", "trace", "warn"].includes(logLevel) ? "stderr" : "stdout";
|
|
191
|
+
const stream = streamType === "stderr" ? this.#stderr : this.#stdout;
|
|
192
|
+
if (this.#interactive && this.#interactiveManager !== undefined && stream.isTTY) {
|
|
193
|
+
this.#interactiveManager.update(streamType, message.split("\n"), 0);
|
|
194
|
+
} else {
|
|
195
|
+
writeStream.writeStream(message + "\n", stream);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
exports.PrettyReporter = PrettyReporter;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { stdout, stderr } from 'node:process';
|
|
2
|
+
import colorize, { green, cyan, red, greenBright, grey, bgGrey, underline, white } from '@visulima/colorize';
|
|
3
|
+
import { renderError } from '@visulima/error/error';
|
|
4
|
+
import { inspect } from '@visulima/inspector';
|
|
5
|
+
import { d as defaultInspectorConfig, t as terminalSize, f as formatLabel, s as stringLength, w as wrapAnsi } from './format-label-DYMZf3Bg.mjs';
|
|
6
|
+
import { E as EMPTY_SYMBOL } from './constants-BYYZ5WNW.mjs';
|
|
7
|
+
import { A as AbstractPrettyReporter, g as getLongestBadge } from './abstract-pretty-reporter-izJgxoMv.mjs';
|
|
8
|
+
import { g as getLongestLabel } from './get-longest-label-CM8kLFWH.mjs';
|
|
9
|
+
import { w as writeStream } from './write-stream-BBAF33Zm.mjs';
|
|
10
|
+
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
13
|
+
const pailFileFilter = /* @__PURE__ */ __name((line) => !/[\\/]pail[\\/]dist/.test(line), "pailFileFilter");
|
|
14
|
+
class PrettyReporter extends AbstractPrettyReporter {
|
|
15
|
+
static {
|
|
16
|
+
__name(this, "PrettyReporter");
|
|
17
|
+
}
|
|
18
|
+
#stdout;
|
|
19
|
+
#stderr;
|
|
20
|
+
#interactiveManager;
|
|
21
|
+
#interactive = false;
|
|
22
|
+
#inspectOptions;
|
|
23
|
+
#errorOptions;
|
|
24
|
+
constructor(options = {}) {
|
|
25
|
+
const { error: errorOptions, inspect: inspectOptions, ...rest } = options;
|
|
26
|
+
super({
|
|
27
|
+
uppercase: {
|
|
28
|
+
label: true,
|
|
29
|
+
...rest.uppercase
|
|
30
|
+
},
|
|
31
|
+
...rest
|
|
32
|
+
});
|
|
33
|
+
this.#inspectOptions = { ...defaultInspectorConfig, ...inspectOptions };
|
|
34
|
+
this.#errorOptions = {
|
|
35
|
+
...errorOptions,
|
|
36
|
+
color: {
|
|
37
|
+
fileLine: green,
|
|
38
|
+
hint: cyan,
|
|
39
|
+
marker: red,
|
|
40
|
+
message: red,
|
|
41
|
+
method: greenBright,
|
|
42
|
+
title: red
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
this.#stdout = stdout;
|
|
46
|
+
this.#stderr = stderr;
|
|
47
|
+
}
|
|
48
|
+
setStdout(stdout_) {
|
|
49
|
+
this.#stdout = stdout_;
|
|
50
|
+
}
|
|
51
|
+
setStderr(stderr_) {
|
|
52
|
+
this.#stderr = stderr_;
|
|
53
|
+
}
|
|
54
|
+
setInteractiveManager(manager) {
|
|
55
|
+
this.#interactiveManager = manager;
|
|
56
|
+
}
|
|
57
|
+
setIsInteractive(interactive) {
|
|
58
|
+
this.#interactive = interactive;
|
|
59
|
+
}
|
|
60
|
+
log(meta) {
|
|
61
|
+
this._log(this._formatMessage(meta), meta.type.level);
|
|
62
|
+
}
|
|
63
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
64
|
+
_formatMessage(data) {
|
|
65
|
+
const { columns } = terminalSize();
|
|
66
|
+
let size = columns;
|
|
67
|
+
if (typeof this._styles.messageLength === "number") {
|
|
68
|
+
size = this._styles.messageLength;
|
|
69
|
+
}
|
|
70
|
+
const { badge, context, date, error, file, groups, label, message, prefix, repeated, scope, suffix, traceError, type } = data;
|
|
71
|
+
const { color } = this._loggerTypes[type.name];
|
|
72
|
+
const colorized = color ? colorize[color] : white;
|
|
73
|
+
const groupSpaces = groups.map(() => " ").join("");
|
|
74
|
+
const items = [];
|
|
75
|
+
if (groups.length > 0) {
|
|
76
|
+
items.push(groupSpaces + grey("[" + groups.at(-1) + "]") + " ");
|
|
77
|
+
}
|
|
78
|
+
if (date) {
|
|
79
|
+
items.push(grey(this._styles.dateFormatter(typeof date === "string" ? new Date(date) : date)) + " ");
|
|
80
|
+
}
|
|
81
|
+
if (badge) {
|
|
82
|
+
items.push(colorized(badge));
|
|
83
|
+
} else {
|
|
84
|
+
const longestBadge = getLongestBadge(this._loggerTypes);
|
|
85
|
+
if (longestBadge.length > 0) {
|
|
86
|
+
items.push(grey(".".repeat(longestBadge.length)) + " ");
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const longestLabel = getLongestLabel(this._loggerTypes);
|
|
90
|
+
if (label) {
|
|
91
|
+
items.push(colorized(formatLabel(label, this._styles)) + " ", grey(".".repeat(longestLabel.length - stringLength(label))));
|
|
92
|
+
} else {
|
|
93
|
+
items.push(grey(".".repeat(longestLabel.length + 2)));
|
|
94
|
+
}
|
|
95
|
+
if (repeated) {
|
|
96
|
+
items.push(bgGrey.white("[" + repeated + "x]") + " ");
|
|
97
|
+
}
|
|
98
|
+
if (Array.isArray(scope) && scope.length > 0) {
|
|
99
|
+
items.push(" " + grey("[" + scope.join(" > ") + "]") + " ");
|
|
100
|
+
}
|
|
101
|
+
if (prefix) {
|
|
102
|
+
items.push(
|
|
103
|
+
grey(
|
|
104
|
+
(Array.isArray(scope) && scope.length > 0 ? ". " : " ") + "[" + (this._styles.underline.prefix ? underline(prefix) : prefix) + "]"
|
|
105
|
+
) + " "
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
const titleSize = stringLength(items.join(" "));
|
|
109
|
+
if (file) {
|
|
110
|
+
const fileMessage = file.name + (file.line ? ":" + file.line : "");
|
|
111
|
+
const fileMessageSize = stringLength(fileMessage);
|
|
112
|
+
if (fileMessageSize + titleSize + 2 > size) {
|
|
113
|
+
items.push(grey(" " + fileMessage));
|
|
114
|
+
} else {
|
|
115
|
+
items.push(grey(".".repeat(size - titleSize - fileMessageSize - 2) + " " + fileMessage));
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
items.push(grey(".".repeat(size - titleSize - 1)));
|
|
119
|
+
}
|
|
120
|
+
if (items.length > 0) {
|
|
121
|
+
items.push("\n\n");
|
|
122
|
+
}
|
|
123
|
+
if (message !== EMPTY_SYMBOL) {
|
|
124
|
+
const formattedMessage = typeof message === "string" ? message : inspect(message, this.#inspectOptions);
|
|
125
|
+
items.push(
|
|
126
|
+
groupSpaces + wrapAnsi(formattedMessage, size - 3, {
|
|
127
|
+
hard: true,
|
|
128
|
+
trim: false,
|
|
129
|
+
wordWrap: true
|
|
130
|
+
})
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
if (context) {
|
|
134
|
+
let hasError = false;
|
|
135
|
+
items.push(
|
|
136
|
+
...context.map((value) => {
|
|
137
|
+
if (value instanceof Error) {
|
|
138
|
+
hasError = true;
|
|
139
|
+
return "\n\n" + renderError(value, {
|
|
140
|
+
...this.#errorOptions,
|
|
141
|
+
filterStacktrace: pailFileFilter,
|
|
142
|
+
prefix: groupSpaces
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
if (typeof value === "object") {
|
|
146
|
+
return " " + inspect(value, this.#inspectOptions);
|
|
147
|
+
}
|
|
148
|
+
const newValue = (hasError ? "\n\n" : " ") + value;
|
|
149
|
+
hasError = false;
|
|
150
|
+
return newValue;
|
|
151
|
+
})
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
if (error) {
|
|
155
|
+
items.push(
|
|
156
|
+
renderError(error, {
|
|
157
|
+
...this.#errorOptions,
|
|
158
|
+
filterStacktrace: pailFileFilter,
|
|
159
|
+
prefix: groupSpaces
|
|
160
|
+
})
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
if (traceError) {
|
|
164
|
+
items.push(
|
|
165
|
+
"\n\n" + renderError(traceError, {
|
|
166
|
+
...this.#errorOptions,
|
|
167
|
+
filterStacktrace: pailFileFilter,
|
|
168
|
+
hideErrorCauseCodeView: true,
|
|
169
|
+
hideErrorCodeView: true,
|
|
170
|
+
hideErrorErrorsCodeView: true,
|
|
171
|
+
hideMessage: true,
|
|
172
|
+
prefix: groupSpaces
|
|
173
|
+
})
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
if (suffix) {
|
|
177
|
+
items.push("\n", groupSpaces + grey(this._styles.underline.suffix ? underline(suffix) : suffix));
|
|
178
|
+
}
|
|
179
|
+
return items.join("") + "\n";
|
|
180
|
+
}
|
|
181
|
+
_log(message, logLevel) {
|
|
182
|
+
const streamType = ["error", "trace", "warn"].includes(logLevel) ? "stderr" : "stdout";
|
|
183
|
+
const stream = streamType === "stderr" ? this.#stderr : this.#stdout;
|
|
184
|
+
if (this.#interactive && this.#interactiveManager !== undefined && stream.isTTY) {
|
|
185
|
+
this.#interactiveManager.update(streamType, message.split("\n"), 0);
|
|
186
|
+
} else {
|
|
187
|
+
writeStream(message + "\n", stream);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export { PrettyReporter };
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const colorize = require('@visulima/colorize/browser');
|
|
4
|
+
const fmt = require('@visulima/fmt');
|
|
5
|
+
const constants = require('./constants-DHfYGxxG.cjs');
|
|
6
|
+
const abstractPrettyReporter = require('./abstract-pretty-reporter-BR_6_JVa.cjs');
|
|
7
|
+
const getLongestLabel = require('./get-longest-label-CQ7lRhgD.cjs');
|
|
8
|
+
const writeConsoleLog = require('./write-console-log-Cu0-IDN-.cjs');
|
|
9
|
+
|
|
10
|
+
const _interopDefaultCompat = e => e && typeof e === 'object' && 'default' in e ? e.default : e;
|
|
11
|
+
|
|
12
|
+
const colorize__default = /*#__PURE__*/_interopDefaultCompat(colorize);
|
|
13
|
+
|
|
14
|
+
var __defProp = Object.defineProperty;
|
|
15
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
16
|
+
class PrettyReporter extends abstractPrettyReporter.AbstractPrettyReporter {
|
|
17
|
+
static {
|
|
18
|
+
__name(this, "PrettyReporter");
|
|
19
|
+
}
|
|
20
|
+
constructor(options = {}) {
|
|
21
|
+
super({
|
|
22
|
+
uppercase: {
|
|
23
|
+
label: true,
|
|
24
|
+
...options.uppercase
|
|
25
|
+
},
|
|
26
|
+
...options
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
30
|
+
log(meta) {
|
|
31
|
+
const isNotBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
32
|
+
const consoleLogFunction = writeConsoleLog.writeConsoleLogBasedOnLevel(meta.type.level);
|
|
33
|
+
const { badge, context, date, error, groups, label, message, prefix, repeated, scope, suffix, type } = meta;
|
|
34
|
+
const { color } = this._loggerTypes[type.name];
|
|
35
|
+
const colorized = color ? colorize__default[color] : colorize.white;
|
|
36
|
+
const items = [];
|
|
37
|
+
if (isNotBrowser && groups.length > 0) {
|
|
38
|
+
const groupSpaces = groups.map(() => " ").join("");
|
|
39
|
+
const cGroup = colorize.grey("[" + groups.at(-1) + "]");
|
|
40
|
+
items.push(fmt.format(groupSpaces + cGroup[0], cGroup.slice(1)));
|
|
41
|
+
}
|
|
42
|
+
if (date) {
|
|
43
|
+
const cDate = colorize.grey(this._styles.dateFormatter(typeof date === "string" ? new Date(date) : date));
|
|
44
|
+
if (isNotBrowser) {
|
|
45
|
+
items.push(fmt.format(cDate[0], cDate.slice(1)));
|
|
46
|
+
} else {
|
|
47
|
+
items.push([cDate[0] + " ", ...cDate.slice(1)]);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (badge) {
|
|
51
|
+
const cBadge = colorized(badge);
|
|
52
|
+
if (isNotBrowser) {
|
|
53
|
+
items.push(fmt.format(cBadge[0], cBadge.slice(1)));
|
|
54
|
+
} else {
|
|
55
|
+
items.push([cBadge[0] + " ", ...cBadge.slice(1)]);
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
const longestBadge = abstractPrettyReporter.getLongestBadge(this._loggerTypes);
|
|
59
|
+
if (longestBadge.length > 0) {
|
|
60
|
+
const cBadgePlaceholder = colorize.grey(".".repeat(longestBadge.length));
|
|
61
|
+
if (isNotBrowser) {
|
|
62
|
+
items.push(fmt.format(cBadgePlaceholder[0] + " ", cBadgePlaceholder.slice(1)));
|
|
63
|
+
} else {
|
|
64
|
+
items.push([cBadgePlaceholder[0] + " ", ...cBadgePlaceholder.slice(1)]);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const longestLabel = getLongestLabel.getLongestLabel(this._loggerTypes);
|
|
69
|
+
let repeatedMessage;
|
|
70
|
+
if (repeated) {
|
|
71
|
+
const cRepeated = colorize.white("[" + repeated + "x]");
|
|
72
|
+
repeatedMessage = isNotBrowser ? fmt.format(cRepeated[0], cRepeated.slice(1)) : [cRepeated[0], ...cRepeated.slice(1)];
|
|
73
|
+
}
|
|
74
|
+
if (label) {
|
|
75
|
+
const cLabel = colorized(this._formatLabel(label));
|
|
76
|
+
if (isNotBrowser) {
|
|
77
|
+
items.push(fmt.format(cLabel[0], cLabel.slice(1)));
|
|
78
|
+
} else {
|
|
79
|
+
items.push([cLabel[0], ...cLabel.slice(1)]);
|
|
80
|
+
}
|
|
81
|
+
if (repeatedMessage) {
|
|
82
|
+
items.push(repeatedMessage);
|
|
83
|
+
}
|
|
84
|
+
let lengthDiff = longestLabel.length - label.length;
|
|
85
|
+
if (repeated) {
|
|
86
|
+
lengthDiff -= String(repeated).length + 3;
|
|
87
|
+
} else {
|
|
88
|
+
lengthDiff += 1;
|
|
89
|
+
}
|
|
90
|
+
if (lengthDiff > 0) {
|
|
91
|
+
const cLabelSpacer = colorize.grey(".".repeat(lengthDiff));
|
|
92
|
+
if (isNotBrowser) {
|
|
93
|
+
items.push(fmt.format(cLabelSpacer[0], cLabelSpacer.slice(1)));
|
|
94
|
+
} else {
|
|
95
|
+
items.push([" " + cLabelSpacer[0], ...cLabelSpacer.slice(1)]);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
const cSpacer = colorize.grey(".".repeat(longestLabel.length + 1));
|
|
100
|
+
if (isNotBrowser) {
|
|
101
|
+
items.push(fmt.format(cSpacer[0], cSpacer.slice(1)));
|
|
102
|
+
} else {
|
|
103
|
+
items.push([cSpacer[0], ...cSpacer.slice(1)]);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (Array.isArray(scope) && scope.length > 0) {
|
|
107
|
+
const cScope = colorize.grey("[" + scope.join(" > ") + "]");
|
|
108
|
+
if (isNotBrowser) {
|
|
109
|
+
items.push(fmt.format(cScope[0], cScope.slice(1)));
|
|
110
|
+
} else {
|
|
111
|
+
items.push([cScope[0], ...cScope.slice(1)]);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (prefix) {
|
|
115
|
+
const cPrefix = colorize.grey(
|
|
116
|
+
(Array.isArray(scope) && scope.length > 0 ? ". " : " ") + "[" + (this._styles.underline.prefix ? colorize.underline(prefix) : prefix) + "] "
|
|
117
|
+
);
|
|
118
|
+
if (isNotBrowser) {
|
|
119
|
+
items.push(fmt.format(cPrefix[0], cPrefix.slice(1)));
|
|
120
|
+
} else {
|
|
121
|
+
items.push([cPrefix[0], ...cPrefix.slice(1)]);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (message !== constants.EMPTY_SYMBOL) {
|
|
125
|
+
items.push(message);
|
|
126
|
+
}
|
|
127
|
+
if (context) {
|
|
128
|
+
items.push(...context);
|
|
129
|
+
}
|
|
130
|
+
if (error) {
|
|
131
|
+
items.push(error, "\n\n");
|
|
132
|
+
}
|
|
133
|
+
if (suffix) {
|
|
134
|
+
const cSuffix = colorize.grey(this._styles.underline.suffix ? colorize.underline(suffix) : suffix);
|
|
135
|
+
if (isNotBrowser) {
|
|
136
|
+
items.push(fmt.format("\n" + cSuffix[0], cSuffix.slice(1)));
|
|
137
|
+
} else {
|
|
138
|
+
items.push(["\n" + cSuffix[0], ...cSuffix.slice(1)]);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (isNotBrowser) {
|
|
142
|
+
consoleLogFunction(...items);
|
|
143
|
+
} else {
|
|
144
|
+
let logMessage = "";
|
|
145
|
+
const css = [];
|
|
146
|
+
const arguments_ = [];
|
|
147
|
+
for (const value of items) {
|
|
148
|
+
if (Array.isArray(value) && value.length > 1 && value[0].includes("%c")) {
|
|
149
|
+
logMessage += value[0];
|
|
150
|
+
css.push(...value.slice(1));
|
|
151
|
+
} else {
|
|
152
|
+
arguments_.push(value);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
consoleLogFunction(logMessage + "%c", ...css, "", ...arguments_);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
_formatLabel(label) {
|
|
159
|
+
let formattedLabel = this._styles.uppercase.label ? label.toUpperCase() : label;
|
|
160
|
+
formattedLabel = this._styles.underline.label ? colorize.underline(formattedLabel) : formattedLabel;
|
|
161
|
+
if (this._styles.bold.label) {
|
|
162
|
+
formattedLabel = colorize.bold(formattedLabel);
|
|
163
|
+
}
|
|
164
|
+
return formattedLabel;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
module.exports = PrettyReporter;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import __cjs_mod__ from "node:module"; // -- packem CommonJS require shim --
|
|
2
|
+
const require = __cjs_mod__.createRequire(import.meta.url);
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
class RedactProcessor {
|
|
6
|
+
static {
|
|
7
|
+
__name(this, "RedactProcessor");
|
|
8
|
+
}
|
|
9
|
+
#redact;
|
|
10
|
+
constructor(rules, options) {
|
|
11
|
+
try {
|
|
12
|
+
const { redact, standardRules } = require("@visulima/redact");
|
|
13
|
+
this.#redact = (input) => redact(input, rules || standardRules, options);
|
|
14
|
+
} catch {
|
|
15
|
+
throw new Error("The '@visulima/redact' package is missing. Make sure to install the '@visulima/redact' package.");
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
process(meta) {
|
|
19
|
+
meta.message = this.#redact(meta.message);
|
|
20
|
+
meta.context = this.#redact(meta.context);
|
|
21
|
+
meta.error = this.#redact(meta.error);
|
|
22
|
+
return meta;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { RedactProcessor as default };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
class RedactProcessor {
|
|
6
|
+
static {
|
|
7
|
+
__name(this, "RedactProcessor");
|
|
8
|
+
}
|
|
9
|
+
#redact;
|
|
10
|
+
constructor(rules, options) {
|
|
11
|
+
try {
|
|
12
|
+
const { redact, standardRules } = require("@visulima/redact");
|
|
13
|
+
this.#redact = (input) => redact(input, rules || standardRules, options);
|
|
14
|
+
} catch {
|
|
15
|
+
throw new Error("The '@visulima/redact' package is missing. Make sure to install the '@visulima/redact' package.");
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
process(meta) {
|
|
19
|
+
meta.message = this.#redact(meta.message);
|
|
20
|
+
meta.context = this.#redact(meta.context);
|
|
21
|
+
meta.error = this.#redact(meta.error);
|
|
22
|
+
return meta;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = RedactProcessor;
|