@visulima/pail 4.0.0-alpha.12 → 4.0.0-alpha.14
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 +23 -0
- package/LICENSE.md +4 -1
- package/dist/error.js +5 -76
- package/dist/index.browser.js +19 -1499
- package/dist/index.server.js +31 -2804
- package/dist/middleware/elysia.d.ts +3 -3
- package/dist/middleware/elysia.js +1 -70
- package/dist/middleware/express.d.ts +3 -3
- package/dist/middleware/express.js +1 -29
- package/dist/middleware/fastify.d.ts +3 -3
- package/dist/middleware/fastify.js +1 -46
- package/dist/middleware/hono.d.ts +3 -3
- package/dist/middleware/hono.js +1 -33
- package/dist/middleware/next/handler.d.ts +5 -5
- package/dist/middleware/next/handler.js +1 -53
- package/dist/middleware/sveltekit.d.ts +3 -3
- package/dist/middleware/sveltekit.js +1 -43
- package/dist/object-tree.js +2 -89
- package/dist/packem_shared/AbstractJsonReporter-D_Pb6kpB.js +1 -0
- package/dist/packem_shared/AbstractJsonReporter-PVC4ONf2.js +1 -0
- package/dist/packem_shared/JsonReporter-BEEmb0W4.js +2 -0
- package/dist/packem_shared/JsonReporter-CE-lw7R0.js +1 -0
- package/dist/packem_shared/PrettyReporter-Br5njEEy.js +5 -0
- package/dist/packem_shared/PrettyReporter-N7FvHzl5.js +44 -0
- package/dist/packem_shared/{abstract-json-reporter.d-BAgznjyU.d.ts → abstract-json-reporter.d-Boj5w068.d.ts} +1 -1
- package/dist/packem_shared/abstract-pretty-reporter-Bag7lQKf.js +33 -0
- package/dist/packem_shared/constants-DKfCaSUR.js +1 -0
- package/dist/packem_shared/constants-ep2nsfdy.js +1 -0
- package/dist/packem_shared/{create-middleware-logger.d-DheMh8q4.d.ts → create-middleware-logger.d-CMQdVeVE.d.ts} +2 -2
- package/dist/packem_shared/createPailError-53jAfQ-T.js +5 -0
- package/dist/packem_shared/headers-S8WyX-2m.js +1 -0
- package/dist/packem_shared/index-Bzp4LnJ5.js +1 -0
- package/dist/packem_shared/pailMiddleware-CWOJRmJq.js +1 -0
- package/dist/packem_shared/storage-DHM1EP2P.js +1 -0
- package/dist/packem_shared/{types.d-BeLumqgD.d.ts → types.d-Ck_RSjLg.d.ts} +1 -1
- package/dist/packem_shared/useLogger-qyZrjy4D.js +1 -0
- package/dist/packem_shared/{wide-event.d-B-t8ZnhI.d.ts → wide-event.d-DA-6dTPc.d.ts} +1 -1
- package/dist/packem_shared/write-console-log-based-on-level-DfD64owL.js +1 -0
- package/dist/packem_shared/write-stream-Dd4_PTcm.js +1 -0
- package/dist/processor/caller/caller-processor.d.ts +1 -1
- package/dist/processor/caller/caller-processor.js +1 -59
- package/dist/processor/environment-processor.d.ts +1 -1
- package/dist/processor/environment-processor.js +1 -82
- package/dist/processor/message-formatter-processor.d.ts +1 -1
- package/dist/processor/message-formatter-processor.js +1 -715
- package/dist/processor/opentelemetry-processor.d.ts +1 -1
- package/dist/processor/opentelemetry-processor.js +1 -52
- package/dist/processor/redact-processor.d.ts +1 -1
- package/dist/processor/redact-processor.js +1 -31
- package/dist/processor/sampling-processor.d.ts +1 -1
- package/dist/processor/sampling-processor.js +1 -59
- package/dist/reporter/file/json-file-reporter.d.ts +2 -2
- package/dist/reporter/file/json-file-reporter.js +2 -136
- package/dist/reporter/http/abstract-http-reporter.d.ts +2 -2
- package/dist/reporter/http/abstract-http-reporter.js +2 -432
- package/dist/reporter/http/http-reporter.d.ts +2 -2
- package/dist/reporter/http/http-reporter.edge-light.js +2 -728
- package/dist/reporter/http/http-reporter.js +1 -13
- package/dist/reporter/json/index.browser.js +1 -2
- package/dist/reporter/json/index.d.ts +2 -2
- package/dist/reporter/json/index.js +1 -2
- package/dist/reporter/pretty/index.browser.js +1 -1
- package/dist/reporter/pretty/index.d.ts +1 -1
- package/dist/reporter/pretty/index.js +1 -1
- package/dist/reporter/simple/simple-reporter.server.js +8 -183
- package/dist/wide-event.d.ts +2 -2
- package/dist/wide-event.js +1 -284
- package/package.json +24 -24
- package/dist/packem_shared/AbstractJsonReporter-BO8Calb4.js +0 -284
- package/dist/packem_shared/AbstractJsonReporter-nOj0Ft1F.js +0 -284
- package/dist/packem_shared/JsonReporter-CCmj7oYL.js +0 -28
- package/dist/packem_shared/JsonReporter-Ck2PIAEw.js +0 -58
- package/dist/packem_shared/PrettyReporter-CIbrmjUV.js +0 -213
- package/dist/packem_shared/PrettyReporter-CNJEO9g7.js +0 -2723
- package/dist/packem_shared/abstract-pretty-reporter-CkqCt5hg.js +0 -2637
- package/dist/packem_shared/constants-B1RjD_ps.js +0 -99
- package/dist/packem_shared/constants-omsTHUWB.js +0 -119
- package/dist/packem_shared/createPailError-B_sgL0nF.js +0 -76
- package/dist/packem_shared/headers-BxHWM6KI.js +0 -127
- package/dist/packem_shared/index-6cG1Kp0t.js +0 -658
- package/dist/packem_shared/pailMiddleware-Ci88geIF.js +0 -24
- package/dist/packem_shared/storage-D0vqz8OX.js +0 -36
- package/dist/packem_shared/useLogger-D0rU3lcX.js +0 -33
- package/dist/packem_shared/write-console-log-based-on-level-ree2lDPw.js +0 -15
- package/dist/packem_shared/write-stream-MDqyXmc_.js +0 -6
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
import colorize, { grey, white, underline, bold } from '@visulima/colorize/browser';
|
|
2
|
-
import { f as format, g as getLongestLabel } from './index-6cG1Kp0t.js';
|
|
3
|
-
import { L as LOG_TYPES, E as EMPTY_SYMBOL } from './constants-omsTHUWB.js';
|
|
4
|
-
import { w as writeConsoleLogBasedOnLevel } from './write-console-log-based-on-level-ree2lDPw.js';
|
|
5
|
-
|
|
6
|
-
const getLongestBadge = (types) => {
|
|
7
|
-
const badges = Object.keys(types).map((x) => types[x].badge ?? "");
|
|
8
|
-
if (badges.length === 0) {
|
|
9
|
-
return "";
|
|
10
|
-
}
|
|
11
|
-
return badges.reduce((x, y) => x.length > y.length ? x : y, "");
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const dateFormatter = (date) => [date.getHours(), date.getMinutes(), date.getSeconds()].map((n) => String(n).padStart(2, "0")).join(":");
|
|
15
|
-
class AbstractPrettyReporter {
|
|
16
|
-
/** Styling options for pretty formatting */
|
|
17
|
-
styles;
|
|
18
|
-
/** Logger type configurations for styling */
|
|
19
|
-
loggerTypes;
|
|
20
|
-
/**
|
|
21
|
-
* Creates a new AbstractPrettyReporter instance.
|
|
22
|
-
* @param options Styling options for pretty formatting
|
|
23
|
-
* @protected
|
|
24
|
-
*/
|
|
25
|
-
constructor(options) {
|
|
26
|
-
this.styles = {
|
|
27
|
-
bold: {
|
|
28
|
-
label: false
|
|
29
|
-
},
|
|
30
|
-
dateFormatter,
|
|
31
|
-
underline: {
|
|
32
|
-
label: false,
|
|
33
|
-
message: false,
|
|
34
|
-
prefix: false,
|
|
35
|
-
suffix: false
|
|
36
|
-
},
|
|
37
|
-
uppercase: {
|
|
38
|
-
label: false
|
|
39
|
-
},
|
|
40
|
-
...options
|
|
41
|
-
};
|
|
42
|
-
this.loggerTypes = LOG_TYPES;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Sets the logger types configuration for styling.
|
|
46
|
-
* @param types Logger type configurations with colors and labels
|
|
47
|
-
*/
|
|
48
|
-
setLoggerTypes(types) {
|
|
49
|
-
this.loggerTypes = types;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
class PrettyReporter extends AbstractPrettyReporter {
|
|
54
|
-
/**
|
|
55
|
-
* Creates a new Browser Pretty Reporter instance.
|
|
56
|
-
* @param options Styling options for pretty formatting
|
|
57
|
-
*/
|
|
58
|
-
constructor(options = {}) {
|
|
59
|
-
super({
|
|
60
|
-
uppercase: {
|
|
61
|
-
label: true,
|
|
62
|
-
...options.uppercase
|
|
63
|
-
},
|
|
64
|
-
...options
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
// eslint-disable-next-line sonarjs/cognitive-complexity -- browser colorize returns arrays where spread is intentional
|
|
68
|
-
log(meta) {
|
|
69
|
-
const isNotBrowser = typeof globalThis.window !== "undefined" && typeof globalThis.document !== "undefined";
|
|
70
|
-
const consoleLogFunction = writeConsoleLogBasedOnLevel(meta.type.level);
|
|
71
|
-
const { badge, context, date, error, groups, label, message, prefix, repeated, scope, suffix, type } = meta;
|
|
72
|
-
const { color } = this.loggerTypes[type.name];
|
|
73
|
-
const colorized = color ? colorize[color] : white;
|
|
74
|
-
const items = [];
|
|
75
|
-
if (isNotBrowser && groups.length > 0) {
|
|
76
|
-
const groupSpaces = groups.map(() => " ").join("");
|
|
77
|
-
const cGroup = grey(`[${groups.at(-1)}]`);
|
|
78
|
-
items.push(format(groupSpaces + cGroup[0], cGroup.slice(1)));
|
|
79
|
-
}
|
|
80
|
-
if (date) {
|
|
81
|
-
const cDate = grey(this.styles.dateFormatter(typeof date === "string" ? new Date(date) : date));
|
|
82
|
-
if (isNotBrowser) {
|
|
83
|
-
items.push(format(cDate[0], cDate.slice(1)));
|
|
84
|
-
} else {
|
|
85
|
-
items.push([`${cDate[0]} `, ...cDate.slice(1)]);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if (badge) {
|
|
89
|
-
const cBadge = colorized(badge);
|
|
90
|
-
if (isNotBrowser) {
|
|
91
|
-
items.push(format(cBadge[0], cBadge.slice(1)));
|
|
92
|
-
} else {
|
|
93
|
-
items.push([`${cBadge[0]} `, ...cBadge.slice(1)]);
|
|
94
|
-
}
|
|
95
|
-
} else {
|
|
96
|
-
const longestBadge = getLongestBadge(this.loggerTypes);
|
|
97
|
-
if (longestBadge.length > 0) {
|
|
98
|
-
const cBadgePlaceholder = grey(".".repeat(longestBadge.length));
|
|
99
|
-
if (isNotBrowser) {
|
|
100
|
-
items.push(format(`${cBadgePlaceholder[0]} `, cBadgePlaceholder.slice(1)));
|
|
101
|
-
} else {
|
|
102
|
-
items.push([`${cBadgePlaceholder[0]} `, ...cBadgePlaceholder.slice(1)]);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
const longestLabel = getLongestLabel(this.loggerTypes);
|
|
107
|
-
let repeatedMessage;
|
|
108
|
-
if (repeated) {
|
|
109
|
-
const cRepeated = white(`[${repeated}x]`);
|
|
110
|
-
repeatedMessage = isNotBrowser ? format(cRepeated[0], cRepeated.slice(1)) : [cRepeated[0], ...cRepeated.slice(1)];
|
|
111
|
-
}
|
|
112
|
-
if (label) {
|
|
113
|
-
const cLabel = colorized(this.#formatLabel(label));
|
|
114
|
-
if (isNotBrowser) {
|
|
115
|
-
items.push(format(cLabel[0], cLabel.slice(1)));
|
|
116
|
-
} else {
|
|
117
|
-
items.push([cLabel[0], ...cLabel.slice(1)]);
|
|
118
|
-
}
|
|
119
|
-
if (repeatedMessage) {
|
|
120
|
-
items.push(repeatedMessage);
|
|
121
|
-
}
|
|
122
|
-
let lengthDiff = longestLabel.length - label.length;
|
|
123
|
-
if (repeated) {
|
|
124
|
-
lengthDiff -= String(repeated).length + 3;
|
|
125
|
-
} else {
|
|
126
|
-
lengthDiff += 1;
|
|
127
|
-
}
|
|
128
|
-
if (lengthDiff > 0) {
|
|
129
|
-
const cLabelSpacer = grey(".".repeat(lengthDiff));
|
|
130
|
-
if (isNotBrowser) {
|
|
131
|
-
items.push(format(cLabelSpacer[0], cLabelSpacer.slice(1)));
|
|
132
|
-
} else {
|
|
133
|
-
items.push([` ${cLabelSpacer[0]}`, ...cLabelSpacer.slice(1)]);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
} else {
|
|
137
|
-
const cSpacer = grey(".".repeat(longestLabel.length + 1));
|
|
138
|
-
if (isNotBrowser) {
|
|
139
|
-
items.push(format(cSpacer[0], cSpacer.slice(1)));
|
|
140
|
-
} else {
|
|
141
|
-
items.push([cSpacer[0], ...cSpacer.slice(1)]);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
if (Array.isArray(scope) && scope.length > 0) {
|
|
145
|
-
const cScope = grey(`[${scope.join(" > ")}]`);
|
|
146
|
-
if (isNotBrowser) {
|
|
147
|
-
items.push(format(cScope[0], cScope.slice(1)));
|
|
148
|
-
} else {
|
|
149
|
-
items.push([cScope[0], ...cScope.slice(1)]);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
if (prefix) {
|
|
153
|
-
const cPrefix = grey(`${Array.isArray(scope) && scope.length > 0 ? ". " : " "}[${this.styles.underline.prefix ? underline(prefix) : prefix}] `);
|
|
154
|
-
if (isNotBrowser) {
|
|
155
|
-
items.push(format(cPrefix[0], cPrefix.slice(1)));
|
|
156
|
-
} else {
|
|
157
|
-
items.push([cPrefix[0], ...cPrefix.slice(1)]);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
if (message !== EMPTY_SYMBOL) {
|
|
161
|
-
items.push(message);
|
|
162
|
-
}
|
|
163
|
-
if (context) {
|
|
164
|
-
items.push(...context);
|
|
165
|
-
}
|
|
166
|
-
if (error) {
|
|
167
|
-
items.push(error, "\n\n");
|
|
168
|
-
}
|
|
169
|
-
if (suffix) {
|
|
170
|
-
const cSuffix = grey(this.styles.underline.suffix ? underline(suffix) : suffix);
|
|
171
|
-
if (isNotBrowser) {
|
|
172
|
-
items.push(format(`
|
|
173
|
-
${cSuffix[0]}`, cSuffix.slice(1)));
|
|
174
|
-
} else {
|
|
175
|
-
items.push([`
|
|
176
|
-
${cSuffix[0]}`, ...cSuffix.slice(1)]);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
if (isNotBrowser) {
|
|
180
|
-
consoleLogFunction(...items);
|
|
181
|
-
} else {
|
|
182
|
-
let logMessage = "";
|
|
183
|
-
const css = [];
|
|
184
|
-
const arguments_ = [];
|
|
185
|
-
for (let i = 0; i < items.length; i += 1) {
|
|
186
|
-
const value = items[i];
|
|
187
|
-
if (Array.isArray(value) && value.length > 1 && value[0].includes("%c")) {
|
|
188
|
-
logMessage += String(value[0]);
|
|
189
|
-
css.push(...value.slice(1));
|
|
190
|
-
} else {
|
|
191
|
-
arguments_.push(value);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
consoleLogFunction(`${logMessage}%c`, ...css, "", ...arguments_);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Formats a label according to styling options.
|
|
199
|
-
* @param label The label to format
|
|
200
|
-
* @returns The formatted label string
|
|
201
|
-
* @private
|
|
202
|
-
*/
|
|
203
|
-
#formatLabel(label) {
|
|
204
|
-
let formattedLabel = this.styles.uppercase.label ? label.toUpperCase() : label;
|
|
205
|
-
formattedLabel = this.styles.underline.label ? underline(formattedLabel) : formattedLabel;
|
|
206
|
-
if (this.styles.bold.label) {
|
|
207
|
-
formattedLabel = bold(formattedLabel);
|
|
208
|
-
}
|
|
209
|
-
return formattedLabel;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
export { PrettyReporter as default };
|