@visulima/pail 3.0.3 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +47 -0
- package/LICENSE.md +18 -391
- package/README.md +578 -0
- package/dist/index.browser.d.ts +4 -3
- package/dist/index.browser.js +12 -1
- package/dist/index.server.d.ts +19 -74
- package/dist/index.server.js +535 -5
- package/dist/interactive/index.d.ts +28 -0
- package/dist/interactive/index.js +2 -0
- package/dist/object-tree.d.ts +17 -0
- package/dist/object-tree.js +89 -0
- package/dist/packem_shared/AbstractJsonReporter-intFdT_A.js +204 -0
- package/dist/packem_shared/InteractiveManager-CZ85hGNW.js +172 -0
- package/dist/packem_shared/InteractiveStreamHook-DiSubbJ1.js +21 -0
- package/dist/packem_shared/JsonReporter-BqWsVkHP.js +60 -0
- package/dist/packem_shared/JsonReporter-DcM2LBX9.js +28 -0
- package/dist/packem_shared/PrettyReporter-BFWaYP_J.js +222 -0
- package/dist/packem_shared/PrettyReporter-CuLLKr6-.js +169 -0
- package/dist/packem_shared/{abstract-json-reporter-wUti0B3k.d.ts → abstract-json-reporter-DiyVyU0j.d.ts} +3 -3
- package/dist/packem_shared/{abstract-pretty-reporter-MOYolfGR.d.ts → abstract-pretty-reporter-BbOWXMCs.d.ts} +1 -1
- package/dist/packem_shared/abstract-pretty-reporter-DMPDCslJ.js +50 -0
- package/dist/packem_shared/constants-DfDr4MHC.js +119 -0
- package/dist/packem_shared/format-label-Btft2KGP.js +1194 -0
- package/dist/packem_shared/get-longest-label-C9PWeyKq.js +9 -0
- package/dist/packem_shared/index-BomQ3E6J.js +650 -0
- package/dist/packem_shared/index-DqKWykfa.js +1146 -0
- package/dist/packem_shared/interactive-stream-hook-DG4BtN12.js +141 -0
- package/dist/packem_shared/{pail.browser-Bs2ng_Qj.d.ts → pail.browser-By9KjOH7.d.ts} +8 -3
- package/dist/packem_shared/pail.browser-CPDOE_d1.js +1427 -0
- package/dist/packem_shared/{types-RidvA4RN.d.ts → types-D3ycu8-x.d.ts} +2 -29
- package/dist/packem_shared/write-console-log-based-on-level-DBmRYXpj.js +14 -0
- package/dist/packem_shared/write-stream-BG8fhcs3.js +6 -0
- package/dist/processor/caller/caller-processor.d.ts +2 -1
- package/dist/processor/caller/caller-processor.js +59 -1
- package/dist/processor/message-formatter-processor.d.ts +2 -1
- package/dist/processor/message-formatter-processor.js +67 -1
- package/dist/processor/opentelemetry-processor.d.ts +19 -0
- package/dist/processor/opentelemetry-processor.js +52 -0
- package/dist/processor/redact-processor.d.ts +2 -1
- package/dist/processor/redact-processor.js +30 -1
- package/dist/progress-bar.d.ts +76 -0
- package/dist/progress-bar.js +404 -0
- package/dist/reporter/file/json-file-reporter.d.ts +3 -2
- package/dist/reporter/file/json-file-reporter.js +136 -4
- package/dist/reporter/http/abstract-http-reporter.d.ts +102 -0
- package/dist/reporter/http/abstract-http-reporter.js +435 -0
- package/dist/reporter/http/http-reporter.d.ts +13 -0
- package/dist/reporter/http/http-reporter.edge-light.d.ts +168 -0
- package/dist/reporter/http/http-reporter.edge-light.js +651 -0
- package/dist/reporter/http/http-reporter.js +13 -0
- package/dist/reporter/json/index.browser.d.ts +3 -2
- package/dist/reporter/json/index.browser.js +2 -1
- package/dist/reporter/json/index.d.ts +3 -2
- package/dist/reporter/json/index.js +2 -1
- package/dist/reporter/pretty/index.browser.d.ts +3 -2
- package/dist/reporter/pretty/index.browser.js +1 -1
- package/dist/reporter/pretty/index.d.ts +3 -2
- package/dist/reporter/pretty/index.js +1 -1
- package/dist/reporter/simple/simple-reporter.server.d.ts +3 -2
- package/dist/reporter/simple/simple-reporter.server.js +186 -8
- package/dist/spinner.d.ts +154 -0
- package/dist/spinner.js +2150 -0
- package/package.json +69 -3
- package/dist/packem_shared/AbstractJsonReporter-UftN6CIL.js +0 -1
- package/dist/packem_shared/JsonReporter-DTBtHNaD.js +0 -2
- package/dist/packem_shared/JsonReporter-Dl4m0xZe.js +0 -1
- package/dist/packem_shared/PrettyReporter-APmxUrnh.js +0 -12
- package/dist/packem_shared/PrettyReporter-CGKSTI7X.js +0 -5
- package/dist/packem_shared/abstract-pretty-reporter-CUtSm20r.js +0 -1
- package/dist/packem_shared/constants-DKfCaSUR.js +0 -1
- package/dist/packem_shared/format-label-DqvZRRR6.js +0 -33
- package/dist/packem_shared/get-longest-label-B0NrI-o2.js +0 -1
- package/dist/packem_shared/getBarChar-mKDZW32R.js +0 -1
- package/dist/packem_shared/index-D9hWq9ka.js +0 -1
- package/dist/packem_shared/pail.browser-BmHoDvEA.js +0 -19
- package/dist/packem_shared/write-console-log-based-on-level-BP95fgQZ.js +0 -1
- package/dist/packem_shared/write-stream-CD8XFv1L.js +0 -1
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { createRequire as __cjs_createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
stdout,
|
|
9
|
+
stderr
|
|
10
|
+
} = __cjs_getProcess;
|
|
11
|
+
import colorize, { red, greenBright, cyan, green, grey, white, bgGrey, underline } from '@visulima/colorize';
|
|
12
|
+
import { d as defaultInspectorConfig, f as formatLabel, i as inspect, r as renderError } from './format-label-Btft2KGP.js';
|
|
13
|
+
import { t as terminalSize, g as getStringWidth, w as wordWrap, W as WrapMode } from './index-DqKWykfa.js';
|
|
14
|
+
import { E as EMPTY_SYMBOL } from './constants-DfDr4MHC.js';
|
|
15
|
+
import { A as AbstractPrettyReporter, g as getLongestBadge } from './abstract-pretty-reporter-DMPDCslJ.js';
|
|
16
|
+
import { g as getLongestLabel } from './get-longest-label-C9PWeyKq.js';
|
|
17
|
+
import { w as writeStream } from './write-stream-BG8fhcs3.js';
|
|
18
|
+
|
|
19
|
+
const pailFileFilter = (line) => !/[\\/]pail[\\/]dist/.test(line);
|
|
20
|
+
class PrettyReporter extends AbstractPrettyReporter {
|
|
21
|
+
#stdout;
|
|
22
|
+
#stderr;
|
|
23
|
+
#interactiveManager;
|
|
24
|
+
#interactive = false;
|
|
25
|
+
#inspectOptions;
|
|
26
|
+
#errorOptions;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new Server Pretty Reporter instance.
|
|
29
|
+
* @param options Configuration options for styling, error rendering, and object inspection
|
|
30
|
+
*/
|
|
31
|
+
constructor(options = {}) {
|
|
32
|
+
const { error: errorOptions, inspect: inspectOptions, ...rest } = options;
|
|
33
|
+
super({
|
|
34
|
+
uppercase: {
|
|
35
|
+
label: true,
|
|
36
|
+
...rest.uppercase
|
|
37
|
+
},
|
|
38
|
+
...rest
|
|
39
|
+
});
|
|
40
|
+
this.#inspectOptions = { ...defaultInspectorConfig, ...inspectOptions };
|
|
41
|
+
this.#errorOptions = {
|
|
42
|
+
...errorOptions,
|
|
43
|
+
color: {
|
|
44
|
+
fileLine: green,
|
|
45
|
+
hint: cyan,
|
|
46
|
+
marker: red,
|
|
47
|
+
message: red,
|
|
48
|
+
method: greenBright,
|
|
49
|
+
title: red
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
this.#stdout = stdout;
|
|
53
|
+
this.#stderr = stderr;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Sets the stdout stream for the reporter.
|
|
57
|
+
* @param stdout_ The writable stream to use for standard output
|
|
58
|
+
*/
|
|
59
|
+
setStdout(stdout_) {
|
|
60
|
+
this.#stdout = stdout_;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Sets the stderr stream for the reporter.
|
|
64
|
+
* @param stderr_ The writable stream to use for error output
|
|
65
|
+
*/
|
|
66
|
+
setStderr(stderr_) {
|
|
67
|
+
this.#stderr = stderr_;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Sets the interactive manager for handling interactive output.
|
|
71
|
+
* @param manager The interactive manager instance, or undefined to disable
|
|
72
|
+
*/
|
|
73
|
+
setInteractiveManager(manager) {
|
|
74
|
+
this.#interactiveManager = manager;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Enables or disables interactive mode.
|
|
78
|
+
* @param interactive Whether to enable interactive terminal features
|
|
79
|
+
*/
|
|
80
|
+
setIsInteractive(interactive) {
|
|
81
|
+
this.#interactive = interactive;
|
|
82
|
+
}
|
|
83
|
+
log(meta) {
|
|
84
|
+
this._log(this._formatMessage(meta), meta.type.level);
|
|
85
|
+
}
|
|
86
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity, no-underscore-dangle
|
|
87
|
+
_formatMessage(data) {
|
|
88
|
+
const { columns } = terminalSize();
|
|
89
|
+
let size = columns;
|
|
90
|
+
if (typeof this.styles.messageLength === "number") {
|
|
91
|
+
size = this.styles.messageLength;
|
|
92
|
+
}
|
|
93
|
+
const { badge, context, date, error, file, groups, label, message, prefix, repeated, scope, suffix, traceError, type } = data;
|
|
94
|
+
const { color } = this.loggerTypes[type.name];
|
|
95
|
+
const colorized = color ? colorize[color] : white;
|
|
96
|
+
const groupSpaces = groups.map(() => " ").join("");
|
|
97
|
+
const items = [];
|
|
98
|
+
if (groups.length > 0) {
|
|
99
|
+
items.push(`${groupSpaces + grey(`[${groups.at(-1)}]`)} `);
|
|
100
|
+
}
|
|
101
|
+
if (date) {
|
|
102
|
+
items.push(`${grey(this.styles.dateFormatter(typeof date === "string" ? new Date(date) : date))} `);
|
|
103
|
+
}
|
|
104
|
+
if (badge) {
|
|
105
|
+
items.push(colorized(badge));
|
|
106
|
+
} else {
|
|
107
|
+
const longestBadge = getLongestBadge(this.loggerTypes);
|
|
108
|
+
if (longestBadge.length > 0) {
|
|
109
|
+
items.push(`${grey(".".repeat(longestBadge.length))} `);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const longestLabel = getLongestLabel(this.loggerTypes);
|
|
113
|
+
if (label) {
|
|
114
|
+
const longestLabelWidth = getStringWidth(longestLabel);
|
|
115
|
+
const labelWidth = getStringWidth(label);
|
|
116
|
+
items.push(`${colorized(formatLabel(label, this.styles))} `, grey(".".repeat(Math.max(0, longestLabelWidth - labelWidth))));
|
|
117
|
+
} else {
|
|
118
|
+
items.push(grey(".".repeat(longestLabel.length + 2)));
|
|
119
|
+
}
|
|
120
|
+
if (repeated) {
|
|
121
|
+
items.push(`${bgGrey.white(`[${repeated}x]`)} `);
|
|
122
|
+
}
|
|
123
|
+
if (Array.isArray(scope) && scope.length > 0) {
|
|
124
|
+
items.push(` ${grey(`[${scope.join(" > ")}]`)} `);
|
|
125
|
+
}
|
|
126
|
+
if (prefix) {
|
|
127
|
+
items.push(
|
|
128
|
+
`${grey(`${Array.isArray(scope) && scope.length > 0 ? ". " : " "}[${this.styles.underline.prefix ? underline(prefix) : prefix}]`)} `
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
const titleSize = getStringWidth(items.join(" "));
|
|
132
|
+
if (file) {
|
|
133
|
+
const fileMessage = file.name + (file.line ? `:${file.line}` : "");
|
|
134
|
+
const fileMessageSize = getStringWidth(fileMessage);
|
|
135
|
+
if (fileMessageSize + titleSize + 2 > size) {
|
|
136
|
+
items.push(grey(` ${fileMessage}`));
|
|
137
|
+
} else {
|
|
138
|
+
const dots = Math.max(0, size - titleSize - fileMessageSize - 2);
|
|
139
|
+
items.push(grey(`${".".repeat(dots)} ${fileMessage}`));
|
|
140
|
+
}
|
|
141
|
+
} else {
|
|
142
|
+
items.push(grey(".".repeat(Math.max(0, size - titleSize - 1))));
|
|
143
|
+
}
|
|
144
|
+
if (items.length > 0) {
|
|
145
|
+
items.push("\n\n");
|
|
146
|
+
}
|
|
147
|
+
if (message !== EMPTY_SYMBOL) {
|
|
148
|
+
const formattedMessage = typeof message === "string" ? message : inspect(message, this.#inspectOptions);
|
|
149
|
+
items.push(
|
|
150
|
+
groupSpaces + wordWrap(formattedMessage, {
|
|
151
|
+
trim: false,
|
|
152
|
+
width: size - 3,
|
|
153
|
+
wrapMode: WrapMode.STRICT_WIDTH
|
|
154
|
+
})
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
if (context) {
|
|
158
|
+
let hasError = false;
|
|
159
|
+
items.push(
|
|
160
|
+
...context.map((value) => {
|
|
161
|
+
if (value instanceof Error) {
|
|
162
|
+
hasError = true;
|
|
163
|
+
return `
|
|
164
|
+
|
|
165
|
+
${renderError(value, {
|
|
166
|
+
...this.#errorOptions,
|
|
167
|
+
filterStacktrace: pailFileFilter,
|
|
168
|
+
prefix: groupSpaces
|
|
169
|
+
})}`;
|
|
170
|
+
}
|
|
171
|
+
if (typeof value === "object") {
|
|
172
|
+
return ` ${inspect(value, this.#inspectOptions)}`;
|
|
173
|
+
}
|
|
174
|
+
const newValue = (hasError ? "\n\n" : " ") + value;
|
|
175
|
+
hasError = false;
|
|
176
|
+
return newValue;
|
|
177
|
+
})
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
if (error) {
|
|
181
|
+
items.push(
|
|
182
|
+
renderError(error, {
|
|
183
|
+
...this.#errorOptions,
|
|
184
|
+
filterStacktrace: pailFileFilter,
|
|
185
|
+
prefix: groupSpaces
|
|
186
|
+
})
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
if (traceError) {
|
|
190
|
+
items.push(
|
|
191
|
+
`
|
|
192
|
+
|
|
193
|
+
${renderError(traceError, {
|
|
194
|
+
...this.#errorOptions,
|
|
195
|
+
filterStacktrace: pailFileFilter,
|
|
196
|
+
hideErrorCauseCodeView: true,
|
|
197
|
+
hideErrorCodeView: true,
|
|
198
|
+
hideErrorErrorsCodeView: true,
|
|
199
|
+
hideMessage: true,
|
|
200
|
+
prefix: groupSpaces
|
|
201
|
+
})}`
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
if (suffix) {
|
|
205
|
+
items.push("\n", groupSpaces + grey(this.styles.underline.suffix ? underline(suffix) : suffix));
|
|
206
|
+
}
|
|
207
|
+
return items.join("");
|
|
208
|
+
}
|
|
209
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
210
|
+
_log(message, logLevel) {
|
|
211
|
+
const streamType = ["error", "trace", "warn"].includes(logLevel) ? "stderr" : "stdout";
|
|
212
|
+
const stream = streamType === "stderr" ? this.#stderr : this.#stdout;
|
|
213
|
+
if (this.#interactive && this.#interactiveManager !== void 0 && stream.isTTY) {
|
|
214
|
+
this.#interactiveManager.update(streamType, message.split("\n"), 0);
|
|
215
|
+
} else {
|
|
216
|
+
writeStream(`${message}
|
|
217
|
+
`, stream);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export { PrettyReporter };
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import colorize, { grey, white, underline, bold } from '@visulima/colorize/browser';
|
|
2
|
+
import { f as format } from './index-BomQ3E6J.js';
|
|
3
|
+
import { E as EMPTY_SYMBOL } from './constants-DfDr4MHC.js';
|
|
4
|
+
import { A as AbstractPrettyReporter, g as getLongestBadge } from './abstract-pretty-reporter-DMPDCslJ.js';
|
|
5
|
+
import { g as getLongestLabel } from './get-longest-label-C9PWeyKq.js';
|
|
6
|
+
import { w as writeConsoleLogBasedOnLevel } from './write-console-log-based-on-level-DBmRYXpj.js';
|
|
7
|
+
|
|
8
|
+
class PrettyReporter extends AbstractPrettyReporter {
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new Browser Pretty Reporter instance.
|
|
11
|
+
* @param options Styling options for pretty formatting
|
|
12
|
+
*/
|
|
13
|
+
constructor(options = {}) {
|
|
14
|
+
super({
|
|
15
|
+
uppercase: {
|
|
16
|
+
label: true,
|
|
17
|
+
...options.uppercase
|
|
18
|
+
},
|
|
19
|
+
...options
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
23
|
+
log(meta) {
|
|
24
|
+
const isNotBrowser = typeof globalThis.window !== "undefined" && typeof globalThis.document !== "undefined";
|
|
25
|
+
const consoleLogFunction = writeConsoleLogBasedOnLevel(meta.type.level);
|
|
26
|
+
const { badge, context, date, error, groups, label, message, prefix, repeated, scope, suffix, type } = meta;
|
|
27
|
+
const { color } = this.loggerTypes[type.name];
|
|
28
|
+
const colorized = color ? colorize[color] : white;
|
|
29
|
+
const items = [];
|
|
30
|
+
if (isNotBrowser && groups.length > 0) {
|
|
31
|
+
const groupSpaces = groups.map(() => " ").join("");
|
|
32
|
+
const cGroup = grey(`[${groups.at(-1)}]`);
|
|
33
|
+
items.push(format(groupSpaces + cGroup[0], cGroup.slice(1)));
|
|
34
|
+
}
|
|
35
|
+
if (date) {
|
|
36
|
+
const cDate = grey(this.styles.dateFormatter(typeof date === "string" ? new Date(date) : date));
|
|
37
|
+
if (isNotBrowser) {
|
|
38
|
+
items.push(format(cDate[0], cDate.slice(1)));
|
|
39
|
+
} else {
|
|
40
|
+
items.push([`${cDate[0]} `, ...cDate.slice(1)]);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (badge) {
|
|
44
|
+
const cBadge = colorized(badge);
|
|
45
|
+
if (isNotBrowser) {
|
|
46
|
+
items.push(format(cBadge[0], cBadge.slice(1)));
|
|
47
|
+
} else {
|
|
48
|
+
items.push([`${cBadge[0]} `, ...cBadge.slice(1)]);
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
const longestBadge = getLongestBadge(this.loggerTypes);
|
|
52
|
+
if (longestBadge.length > 0) {
|
|
53
|
+
const cBadgePlaceholder = grey(".".repeat(longestBadge.length));
|
|
54
|
+
if (isNotBrowser) {
|
|
55
|
+
items.push(format(`${cBadgePlaceholder[0]} `, cBadgePlaceholder.slice(1)));
|
|
56
|
+
} else {
|
|
57
|
+
items.push([`${cBadgePlaceholder[0]} `, ...cBadgePlaceholder.slice(1)]);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const longestLabel = getLongestLabel(this.loggerTypes);
|
|
62
|
+
let repeatedMessage;
|
|
63
|
+
if (repeated) {
|
|
64
|
+
const cRepeated = white(`[${repeated}x]`);
|
|
65
|
+
repeatedMessage = isNotBrowser ? format(cRepeated[0], cRepeated.slice(1)) : [cRepeated[0], ...cRepeated.slice(1)];
|
|
66
|
+
}
|
|
67
|
+
if (label) {
|
|
68
|
+
const cLabel = colorized(this.#formatLabel(label));
|
|
69
|
+
if (isNotBrowser) {
|
|
70
|
+
items.push(format(cLabel[0], cLabel.slice(1)));
|
|
71
|
+
} else {
|
|
72
|
+
items.push([cLabel[0], ...cLabel.slice(1)]);
|
|
73
|
+
}
|
|
74
|
+
if (repeatedMessage) {
|
|
75
|
+
items.push(repeatedMessage);
|
|
76
|
+
}
|
|
77
|
+
let lengthDiff = longestLabel.length - label.length;
|
|
78
|
+
if (repeated) {
|
|
79
|
+
lengthDiff -= String(repeated).length + 3;
|
|
80
|
+
} else {
|
|
81
|
+
lengthDiff += 1;
|
|
82
|
+
}
|
|
83
|
+
if (lengthDiff > 0) {
|
|
84
|
+
const cLabelSpacer = grey(".".repeat(lengthDiff));
|
|
85
|
+
if (isNotBrowser) {
|
|
86
|
+
items.push(format(cLabelSpacer[0], cLabelSpacer.slice(1)));
|
|
87
|
+
} else {
|
|
88
|
+
items.push([` ${cLabelSpacer[0]}`, ...cLabelSpacer.slice(1)]);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
const cSpacer = grey(".".repeat(longestLabel.length + 1));
|
|
93
|
+
if (isNotBrowser) {
|
|
94
|
+
items.push(format(cSpacer[0], cSpacer.slice(1)));
|
|
95
|
+
} else {
|
|
96
|
+
items.push([cSpacer[0], ...cSpacer.slice(1)]);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (Array.isArray(scope) && scope.length > 0) {
|
|
100
|
+
const cScope = grey(`[${scope.join(" > ")}]`);
|
|
101
|
+
if (isNotBrowser) {
|
|
102
|
+
items.push(format(cScope[0], cScope.slice(1)));
|
|
103
|
+
} else {
|
|
104
|
+
items.push([cScope[0], ...cScope.slice(1)]);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (prefix) {
|
|
108
|
+
const cPrefix = grey(
|
|
109
|
+
`${Array.isArray(scope) && scope.length > 0 ? ". " : " "}[${this.styles.underline.prefix ? underline(prefix) : prefix}] `
|
|
110
|
+
);
|
|
111
|
+
if (isNotBrowser) {
|
|
112
|
+
items.push(format(cPrefix[0], cPrefix.slice(1)));
|
|
113
|
+
} else {
|
|
114
|
+
items.push([cPrefix[0], ...cPrefix.slice(1)]);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (message !== EMPTY_SYMBOL) {
|
|
118
|
+
items.push(message);
|
|
119
|
+
}
|
|
120
|
+
if (context) {
|
|
121
|
+
items.push(...context);
|
|
122
|
+
}
|
|
123
|
+
if (error) {
|
|
124
|
+
items.push(error, "\n\n");
|
|
125
|
+
}
|
|
126
|
+
if (suffix) {
|
|
127
|
+
const cSuffix = grey(this.styles.underline.suffix ? underline(suffix) : suffix);
|
|
128
|
+
if (isNotBrowser) {
|
|
129
|
+
items.push(format(`
|
|
130
|
+
${cSuffix[0]}`, cSuffix.slice(1)));
|
|
131
|
+
} else {
|
|
132
|
+
items.push([`
|
|
133
|
+
${cSuffix[0]}`, ...cSuffix.slice(1)]);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (isNotBrowser) {
|
|
137
|
+
consoleLogFunction(...items);
|
|
138
|
+
} else {
|
|
139
|
+
let logMessage = "";
|
|
140
|
+
const css = [];
|
|
141
|
+
const arguments_ = [];
|
|
142
|
+
for (const value of items) {
|
|
143
|
+
if (Array.isArray(value) && value.length > 1 && value[0].includes("%c")) {
|
|
144
|
+
logMessage += value[0];
|
|
145
|
+
css.push(...value.slice(1));
|
|
146
|
+
} else {
|
|
147
|
+
arguments_.push(value);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
consoleLogFunction(`${logMessage}%c`, ...css, "", ...arguments_);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Formats a label according to styling options.
|
|
155
|
+
* @param label The label to format
|
|
156
|
+
* @returns The formatted label string
|
|
157
|
+
* @private
|
|
158
|
+
*/
|
|
159
|
+
#formatLabel(label) {
|
|
160
|
+
let formattedLabel = this.styles.uppercase.label ? label.toUpperCase() : label;
|
|
161
|
+
formattedLabel = this.styles.underline.label ? underline(formattedLabel) : formattedLabel;
|
|
162
|
+
if (this.styles.bold.label) {
|
|
163
|
+
formattedLabel = bold(formattedLabel);
|
|
164
|
+
}
|
|
165
|
+
return formattedLabel;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export { PrettyReporter as default };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { s as stringify } from './index.d-oxZvg_y7.js';
|
|
2
2
|
import { LiteralUnion } from 'type-fest';
|
|
3
|
-
import {
|
|
3
|
+
import { f as StringifyAwareReporter, e as ReadonlyMeta, E as ExtendedRfc5424LogLevels } from './types-D3ycu8-x.js';
|
|
4
4
|
|
|
5
5
|
type AbstractJsonReporterOptions = {
|
|
6
6
|
error: Partial<{
|
|
@@ -18,5 +18,5 @@ declare abstract class AbstractJsonReporter<L extends string = string> implement
|
|
|
18
18
|
protected abstract _log(message: string, logLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>): void;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export { AbstractJsonReporter as
|
|
22
|
-
export type { AbstractJsonReporterOptions as
|
|
21
|
+
export { AbstractJsonReporter as A };
|
|
22
|
+
export type { AbstractJsonReporterOptions as a };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LiteralUnion } from 'type-fest';
|
|
2
|
-
import { c as LoggerTypesAwareReporter, d as LoggerTypesConfig, a as DefaultLogTypes,
|
|
2
|
+
import { c as LoggerTypesAwareReporter, d as LoggerTypesConfig, a as DefaultLogTypes, e as ReadonlyMeta } from './types-D3ycu8-x.js';
|
|
3
3
|
|
|
4
4
|
declare abstract class AbstractPrettyReporter<T extends string = string, L extends string = string> implements LoggerTypesAwareReporter<T, L> {
|
|
5
5
|
protected readonly styles: PrettyStyleOptions;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { L as LOG_TYPES } from './constants-DfDr4MHC.js';
|
|
2
|
+
|
|
3
|
+
const getLongestBadge = (types) => {
|
|
4
|
+
const badges = Object.keys(types).map((x) => types[x].badge ?? "");
|
|
5
|
+
if (badges.length === 0) {
|
|
6
|
+
return "";
|
|
7
|
+
}
|
|
8
|
+
return badges.reduce((x, y) => x.length > y.length ? x : y);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const dateFormatter = (date) => [date.getHours(), date.getMinutes(), date.getSeconds()].map((n) => String(n).padStart(2, "0")).join(":");
|
|
12
|
+
class AbstractPrettyReporter {
|
|
13
|
+
/** Styling options for pretty formatting */
|
|
14
|
+
styles;
|
|
15
|
+
/** Logger type configurations for styling */
|
|
16
|
+
loggerTypes;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new AbstractPrettyReporter instance.
|
|
19
|
+
* @param options Styling options for pretty formatting
|
|
20
|
+
* @protected
|
|
21
|
+
*/
|
|
22
|
+
constructor(options) {
|
|
23
|
+
this.styles = {
|
|
24
|
+
bold: {
|
|
25
|
+
label: false
|
|
26
|
+
},
|
|
27
|
+
dateFormatter,
|
|
28
|
+
underline: {
|
|
29
|
+
label: false,
|
|
30
|
+
message: false,
|
|
31
|
+
prefix: false,
|
|
32
|
+
suffix: false
|
|
33
|
+
},
|
|
34
|
+
uppercase: {
|
|
35
|
+
label: false
|
|
36
|
+
},
|
|
37
|
+
...options
|
|
38
|
+
};
|
|
39
|
+
this.loggerTypes = LOG_TYPES;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Sets the logger types configuration for styling.
|
|
43
|
+
* @param types Logger type configurations with colors and labels
|
|
44
|
+
*/
|
|
45
|
+
setLoggerTypes(types) {
|
|
46
|
+
this.loggerTypes = types;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { AbstractPrettyReporter as A, getLongestBadge as g };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
const EXTENDED_RFC_5424_LOG_LEVELS = {
|
|
2
|
+
alert: 7,
|
|
3
|
+
// Action must be taken immediately. Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up.
|
|
4
|
+
critical: 6,
|
|
5
|
+
// Critical conditions. Example: Application component unavailable, unexpected exception.
|
|
6
|
+
debug: 1,
|
|
7
|
+
// Detailed debug information.
|
|
8
|
+
emergency: 8,
|
|
9
|
+
// Emergency: system is unusable.
|
|
10
|
+
error: 5,
|
|
11
|
+
// Runtime errors that do not require immediate action but should typically be logged and monitored.
|
|
12
|
+
informational: 2,
|
|
13
|
+
// Interesting events. Examples: User logs in, SQL logs.
|
|
14
|
+
notice: 3,
|
|
15
|
+
// Normal but significant events.
|
|
16
|
+
trace: 2,
|
|
17
|
+
// Trace information.
|
|
18
|
+
warning: 4
|
|
19
|
+
// Exceptional occurrences that are not errors. Examples: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong.
|
|
20
|
+
};
|
|
21
|
+
const LOG_TYPES = {
|
|
22
|
+
alert: {
|
|
23
|
+
color: "red",
|
|
24
|
+
label: "alert",
|
|
25
|
+
logLevel: "alert"
|
|
26
|
+
},
|
|
27
|
+
await: {
|
|
28
|
+
color: "blue",
|
|
29
|
+
label: "awaiting",
|
|
30
|
+
logLevel: "informational"
|
|
31
|
+
},
|
|
32
|
+
complete: {
|
|
33
|
+
color: "cyan",
|
|
34
|
+
label: "complete",
|
|
35
|
+
logLevel: "informational"
|
|
36
|
+
},
|
|
37
|
+
critical: {
|
|
38
|
+
color: "redBright",
|
|
39
|
+
label: "critical",
|
|
40
|
+
logLevel: "critical"
|
|
41
|
+
},
|
|
42
|
+
debug: {
|
|
43
|
+
color: "gray",
|
|
44
|
+
label: "debug",
|
|
45
|
+
logLevel: "debug"
|
|
46
|
+
},
|
|
47
|
+
emergency: {
|
|
48
|
+
color: "redBright",
|
|
49
|
+
label: "emergency",
|
|
50
|
+
logLevel: "emergency"
|
|
51
|
+
},
|
|
52
|
+
error: {
|
|
53
|
+
color: "red",
|
|
54
|
+
label: "error",
|
|
55
|
+
logLevel: "error"
|
|
56
|
+
},
|
|
57
|
+
info: {
|
|
58
|
+
color: "blueBright",
|
|
59
|
+
label: "info",
|
|
60
|
+
logLevel: "informational"
|
|
61
|
+
},
|
|
62
|
+
log: {
|
|
63
|
+
label: "",
|
|
64
|
+
logLevel: "informational"
|
|
65
|
+
},
|
|
66
|
+
notice: {
|
|
67
|
+
color: "magentaBright",
|
|
68
|
+
label: "notice",
|
|
69
|
+
logLevel: "notice"
|
|
70
|
+
},
|
|
71
|
+
pending: {
|
|
72
|
+
color: "magenta",
|
|
73
|
+
label: "pending",
|
|
74
|
+
logLevel: "informational"
|
|
75
|
+
},
|
|
76
|
+
start: {
|
|
77
|
+
color: "greenBright",
|
|
78
|
+
label: "start",
|
|
79
|
+
logLevel: "informational"
|
|
80
|
+
},
|
|
81
|
+
stop: {
|
|
82
|
+
color: "red",
|
|
83
|
+
label: "stop",
|
|
84
|
+
logLevel: "informational"
|
|
85
|
+
},
|
|
86
|
+
success: {
|
|
87
|
+
color: "green",
|
|
88
|
+
label: "success",
|
|
89
|
+
logLevel: "informational"
|
|
90
|
+
},
|
|
91
|
+
trace: {
|
|
92
|
+
color: "cyanBright",
|
|
93
|
+
label: "trace",
|
|
94
|
+
logLevel: "trace"
|
|
95
|
+
},
|
|
96
|
+
wait: {
|
|
97
|
+
color: "blue",
|
|
98
|
+
label: "waiting",
|
|
99
|
+
logLevel: "informational"
|
|
100
|
+
},
|
|
101
|
+
warn: {
|
|
102
|
+
color: "yellow",
|
|
103
|
+
label: "warning",
|
|
104
|
+
logLevel: "warning"
|
|
105
|
+
},
|
|
106
|
+
warning: {
|
|
107
|
+
color: "yellow",
|
|
108
|
+
label: "warning",
|
|
109
|
+
logLevel: "warning"
|
|
110
|
+
},
|
|
111
|
+
watch: {
|
|
112
|
+
color: "yellowBright",
|
|
113
|
+
label: "watching",
|
|
114
|
+
logLevel: "informational"
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
const EMPTY_SYMBOL = Symbol("EMPTY");
|
|
118
|
+
|
|
119
|
+
export { EMPTY_SYMBOL as E, LOG_TYPES as L, EXTENDED_RFC_5424_LOG_LEVELS as a };
|