@visulima/pail 4.0.0-alpha.11 → 4.0.0-alpha.13
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 +33 -0
- package/LICENSE.md +131 -900
- package/dist/error.d.ts +95 -96
- package/dist/error.js +5 -76
- package/dist/index.browser.d.ts +557 -47
- package/dist/index.browser.js +19 -1499
- package/dist/index.server.d.ts +722 -61
- package/dist/index.server.js +31 -2803
- package/dist/middleware/elysia.d.ts +65 -63
- package/dist/middleware/elysia.js +1 -70
- package/dist/middleware/express.d.ts +73 -71
- package/dist/middleware/express.js +1 -29
- package/dist/middleware/fastify.d.ts +69 -67
- package/dist/middleware/fastify.js +1 -46
- package/dist/middleware/hono.d.ts +74 -72
- package/dist/middleware/hono.js +1 -33
- package/dist/middleware/next/handler.d.ts +101 -34
- package/dist/middleware/next/handler.js +1 -53
- package/dist/middleware/sveltekit.d.ts +100 -98
- package/dist/middleware/sveltekit.js +1 -43
- package/dist/object-tree.d.ts +67 -70
- package/dist/object-tree.js +2 -89
- package/dist/packem_shared/AbstractJsonReporter-BawNFYxI.js +1 -0
- package/dist/packem_shared/AbstractJsonReporter-Dt5-5x2R.js +1 -0
- package/dist/packem_shared/JsonReporter-15ln04rX.js +2 -0
- package/dist/packem_shared/JsonReporter-CerNvhg-.js +1 -0
- package/dist/packem_shared/PrettyReporter-Br5njEEy.js +5 -0
- package/dist/packem_shared/PrettyReporter-CgXnwIip.js +44 -0
- package/dist/packem_shared/abstract-json-reporter.d-Bz3lZEDi.d.ts +61 -0
- package/dist/packem_shared/abstract-pretty-reporter-BiHgKxG_.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-DeNLii5l.d.ts +47 -0
- 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-ByY2ZuYG.d.ts +246 -0
- package/dist/packem_shared/types.d-C51XNfQz.d.ts +194 -0
- package/dist/packem_shared/types.d-CM5ie2qm.d.ts +236 -0
- package/dist/packem_shared/useLogger-qyZrjy4D.js +1 -0
- package/dist/packem_shared/wide-event.d-Ke44zirU.d.ts +704 -0
- 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 +49 -47
- package/dist/processor/caller/caller-processor.js +1 -59
- package/dist/processor/environment-processor.d.ts +113 -113
- package/dist/processor/environment-processor.js +1 -89
- package/dist/processor/message-formatter-processor.d.ts +51 -49
- package/dist/processor/message-formatter-processor.js +1 -715
- package/dist/processor/opentelemetry-processor.d.ts +69 -66
- package/dist/processor/opentelemetry-processor.js +1 -52
- package/dist/processor/redact-processor.d.ts +60 -41
- package/dist/processor/redact-processor.js +1 -31
- package/dist/processor/sampling-processor.d.ts +102 -101
- package/dist/processor/sampling-processor.js +1 -59
- package/dist/reporter/file/json-file-reporter.d.ts +91 -42
- package/dist/reporter/file/json-file-reporter.js +2 -136
- package/dist/reporter/http/abstract-http-reporter.d.ts +213 -211
- package/dist/reporter/http/abstract-http-reporter.js +2 -432
- package/dist/reporter/http/http-reporter.d.ts +40 -36
- package/dist/reporter/http/http-reporter.edge-light.d.ts +430 -38
- 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.d.ts +99 -3
- package/dist/reporter/json/index.browser.js +1 -2
- package/dist/reporter/json/index.d.ts +51 -3
- package/dist/reporter/json/index.js +1 -2
- package/dist/reporter/pretty/index.browser.d.ts +106 -2
- package/dist/reporter/pretty/index.browser.js +1 -1
- package/dist/reporter/pretty/index.d.ts +186 -2
- package/dist/reporter/pretty/index.js +1 -1
- package/dist/reporter/simple/simple-reporter.server.d.ts +168 -18
- package/dist/reporter/simple/simple-reporter.server.js +8 -182
- package/dist/wide-event.d.ts +5 -300
- package/dist/wide-event.js +1 -284
- package/package.json +29 -30
- package/dist/constants.d.ts +0 -37
- package/dist/middleware/next/middleware.d.ts +0 -59
- package/dist/middleware/next/storage.d.ts +0 -14
- package/dist/middleware/shared/create-middleware-logger.d.ts +0 -82
- package/dist/middleware/shared/headers.d.ts +0 -14
- package/dist/middleware/shared/routes.d.ts +0 -30
- package/dist/middleware/shared/storage.d.ts +0 -29
- 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-BCvyNzXO.js +0 -2720
- package/dist/packem_shared/PrettyReporter-BtTr13Ha.js +0 -213
- package/dist/packem_shared/abstract-pretty-reporter-CXAKYCb8.js +0 -2635
- 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-Bx3-C0j9.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
- package/dist/pail.browser.d.ts +0 -412
- package/dist/pail.server.d.ts +0 -158
- package/dist/processor/caller/get-caller-filename.d.ts +0 -23
- package/dist/reporter/file/utils/rotating-file-stream.d.ts +0 -48
- package/dist/reporter/http/utils/compression.d.ts +0 -7
- package/dist/reporter/http/utils/log-size-error.d.ts +0 -30
- package/dist/reporter/http/utils/retry.d.ts +0 -27
- package/dist/reporter/json/abstract-json-reporter.d.ts +0 -61
- package/dist/reporter/json/json-reporter.browser.d.ts +0 -40
- package/dist/reporter/json/json-reporter.server.d.ts +0 -50
- package/dist/reporter/pretty/abstract-pretty-reporter.d.ts +0 -83
- package/dist/reporter/pretty/pretty-reporter.browser.d.ts +0 -36
- package/dist/reporter/pretty/pretty-reporter.server.d.ts +0 -70
- package/dist/reporter/raw/raw-reporter.browser.d.ts +0 -5
- package/dist/reporter/raw/raw-reporter.server.d.ts +0 -13
- package/dist/reporter/utils/default-inspector-config.d.ts +0 -3
- package/dist/reporter/utils/format-label.d.ts +0 -3
- package/dist/types.d.ts +0 -241
- package/dist/utils/arrayify.d.ts +0 -2
- package/dist/utils/get-longest-badge.d.ts +0 -4
- package/dist/utils/get-longest-label.d.ts +0 -4
- package/dist/utils/merge-types.d.ts +0 -4
- package/dist/utils/stream/safe-stream-handler.d.ts +0 -21
- package/dist/utils/write-console-log-based-on-level.d.ts +0 -4
- package/dist/utils/write-stream.d.ts +0 -2
package/dist/wide-event.js
CHANGED
|
@@ -1,284 +1 @@
|
|
|
1
|
-
const
|
|
2
|
-
debug: 0,
|
|
3
|
-
error: 3,
|
|
4
|
-
info: 1,
|
|
5
|
-
warn: 2
|
|
6
|
-
};
|
|
7
|
-
const LEVEL_TO_LOG_TYPE = {
|
|
8
|
-
debug: "debug",
|
|
9
|
-
error: "error",
|
|
10
|
-
info: "info",
|
|
11
|
-
warn: "warn"
|
|
12
|
-
};
|
|
13
|
-
const deepMerge = (target, source) => {
|
|
14
|
-
const result = { ...target };
|
|
15
|
-
const keys = Object.keys(source);
|
|
16
|
-
for (let i = 0; i < keys.length; i += 1) {
|
|
17
|
-
const key = keys[i];
|
|
18
|
-
const sourceValue = source[key];
|
|
19
|
-
const targetValue = result[key];
|
|
20
|
-
if (sourceValue !== null && typeof sourceValue === "object" && !Array.isArray(sourceValue) && targetValue !== null && typeof targetValue === "object" && !Array.isArray(targetValue)) {
|
|
21
|
-
result[key] = deepMerge(targetValue, sourceValue);
|
|
22
|
-
} else {
|
|
23
|
-
result[key] = sourceValue;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return result;
|
|
27
|
-
};
|
|
28
|
-
const formatDuration = (ms) => {
|
|
29
|
-
if (ms < 1e3) {
|
|
30
|
-
return `${String(ms)}ms`;
|
|
31
|
-
}
|
|
32
|
-
return `${(ms / 1e3).toFixed(2)}s`;
|
|
33
|
-
};
|
|
34
|
-
const serializeError = (error) => {
|
|
35
|
-
const serialized = {
|
|
36
|
-
message: error.message,
|
|
37
|
-
name: error.name
|
|
38
|
-
};
|
|
39
|
-
if (error.stack) {
|
|
40
|
-
serialized.stack = error.stack;
|
|
41
|
-
}
|
|
42
|
-
const errorWithStatus = error;
|
|
43
|
-
if (errorWithStatus.status !== void 0) {
|
|
44
|
-
serialized.status = errorWithStatus.status;
|
|
45
|
-
} else if (errorWithStatus.statusCode !== void 0) {
|
|
46
|
-
serialized.status = errorWithStatus.statusCode;
|
|
47
|
-
}
|
|
48
|
-
if (errorWithStatus.data !== void 0) {
|
|
49
|
-
serialized.data = errorWithStatus.data;
|
|
50
|
-
}
|
|
51
|
-
if (error.cause instanceof Error) {
|
|
52
|
-
serialized.cause = serializeError(error.cause);
|
|
53
|
-
}
|
|
54
|
-
return serialized;
|
|
55
|
-
};
|
|
56
|
-
class WideEvent {
|
|
57
|
-
name;
|
|
58
|
-
autoEmit;
|
|
59
|
-
data;
|
|
60
|
-
emitted;
|
|
61
|
-
attachedError;
|
|
62
|
-
level;
|
|
63
|
-
pail;
|
|
64
|
-
requestLogs;
|
|
65
|
-
service;
|
|
66
|
-
startTime;
|
|
67
|
-
status;
|
|
68
|
-
timestamp;
|
|
69
|
-
// @ts-expect-error TS6133 -- preserved for future use (richer event categorization)
|
|
70
|
-
_type;
|
|
71
|
-
constructor(options) {
|
|
72
|
-
this.name = options.name;
|
|
73
|
-
this.pail = options.pail;
|
|
74
|
-
this.data = {};
|
|
75
|
-
this.startTime = performance.now();
|
|
76
|
-
this.timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
77
|
-
this.emitted = false;
|
|
78
|
-
this.autoEmit = options.autoEmit ?? true;
|
|
79
|
-
this._type = options.type ?? "info";
|
|
80
|
-
this.level = "info";
|
|
81
|
-
this.requestLogs = [];
|
|
82
|
-
this.service = options.service;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Record a debug-level lifecycle log entry.
|
|
86
|
-
* Does not escalate the event level.
|
|
87
|
-
* @param message Description of what happened
|
|
88
|
-
* @param context Optional structured context
|
|
89
|
-
* @returns `this` for chaining
|
|
90
|
-
*/
|
|
91
|
-
debug(message, context) {
|
|
92
|
-
return this.addLogEntry("debug", message, context);
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Emit the wide event through the pail logger. Can only be called once;
|
|
96
|
-
* subsequent calls are no-ops.
|
|
97
|
-
*
|
|
98
|
-
* Automatically calculates duration, determines the log type based on
|
|
99
|
-
* the highest severity level reached, and serializes any attached error.
|
|
100
|
-
*
|
|
101
|
-
* Prefer `finish()` for HTTP request contexts where you have a status code.
|
|
102
|
-
* @param typeOverride Override the log type for this emission
|
|
103
|
-
*/
|
|
104
|
-
emit(typeOverride) {
|
|
105
|
-
if (this.emitted) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
this.emitted = true;
|
|
109
|
-
const durationMs = Math.round(performance.now() - this.startTime);
|
|
110
|
-
const resolvedLevel = this.attachedError ? "error" : this.level;
|
|
111
|
-
const type = typeOverride ?? LEVEL_TO_LOG_TYPE[resolvedLevel];
|
|
112
|
-
const payload = {
|
|
113
|
-
duration: formatDuration(durationMs),
|
|
114
|
-
duration_ms: durationMs,
|
|
115
|
-
event: this.name,
|
|
116
|
-
timestamp: this.timestamp,
|
|
117
|
-
...this.data
|
|
118
|
-
};
|
|
119
|
-
if (this.service) {
|
|
120
|
-
payload.service = this.service;
|
|
121
|
-
}
|
|
122
|
-
if (this.status !== void 0) {
|
|
123
|
-
payload.status = this.status;
|
|
124
|
-
}
|
|
125
|
-
if (this.attachedError) {
|
|
126
|
-
payload.error = serializeError(this.attachedError);
|
|
127
|
-
}
|
|
128
|
-
if (this.requestLogs.length > 0) {
|
|
129
|
-
payload.requestLogs = this.requestLogs;
|
|
130
|
-
}
|
|
131
|
-
const logFunction = this.pail[type];
|
|
132
|
-
logFunction({ message: payload });
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Record an error-level lifecycle log entry and attach the error.
|
|
136
|
-
* Escalates the event level to "error".
|
|
137
|
-
* @param message Description of what went wrong
|
|
138
|
-
* @param error The error that occurred
|
|
139
|
-
* @param context Optional structured context
|
|
140
|
-
* @returns `this` for chaining
|
|
141
|
-
*/
|
|
142
|
-
error(message, error, context) {
|
|
143
|
-
if (error) {
|
|
144
|
-
this.attachedError = error;
|
|
145
|
-
}
|
|
146
|
-
return this.addLogEntry("error", message, context);
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Finish and emit the wide event with HTTP context.
|
|
150
|
-
* Sets the response status and optional error before emitting.
|
|
151
|
-
* @example
|
|
152
|
-
* ```typescript
|
|
153
|
-
* ev.finish({ status: 200 });
|
|
154
|
-
* ev.finish({ status: 500, error: new Error("DB timeout") });
|
|
155
|
-
* ```
|
|
156
|
-
* @param options Status code and/or error
|
|
157
|
-
*/
|
|
158
|
-
finish(options) {
|
|
159
|
-
if (options?.status !== void 0) {
|
|
160
|
-
this.status = options.status;
|
|
161
|
-
}
|
|
162
|
-
if (options?.error) {
|
|
163
|
-
this.attachedError = options.error;
|
|
164
|
-
}
|
|
165
|
-
this.emit();
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Get a read-only snapshot of the accumulated data.
|
|
169
|
-
*/
|
|
170
|
-
getData() {
|
|
171
|
-
return this.data;
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Get the current severity level of the event.
|
|
175
|
-
* The level auto-escalates as `warn()` or `error()` entries are added.
|
|
176
|
-
*/
|
|
177
|
-
getLevel() {
|
|
178
|
-
return this.attachedError ? "error" : this.level;
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Get a read-only copy of the request lifecycle log entries.
|
|
182
|
-
*/
|
|
183
|
-
getRequestLogs() {
|
|
184
|
-
return this.requestLogs;
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Record an info-level lifecycle log entry.
|
|
188
|
-
* Does not escalate the event level.
|
|
189
|
-
* @param message Description of what happened
|
|
190
|
-
* @param context Optional structured context
|
|
191
|
-
* @returns `this` for chaining
|
|
192
|
-
*/
|
|
193
|
-
info(message, context) {
|
|
194
|
-
return this.addLogEntry("info", message, context);
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Accumulate context into the wide event via deep merge.
|
|
198
|
-
* Call as many times as needed throughout the operation.
|
|
199
|
-
* @example
|
|
200
|
-
* ```typescript
|
|
201
|
-
* ev.set({ user: { id: 1 } });
|
|
202
|
-
* ev.set({ user: { plan: "pro" } });
|
|
203
|
-
* // data = { user: { id: 1, plan: "pro" } }
|
|
204
|
-
* ```
|
|
205
|
-
* @param data Partial data to merge into the event
|
|
206
|
-
* @returns `this` for chaining
|
|
207
|
-
*/
|
|
208
|
-
set(data) {
|
|
209
|
-
this.data = deepMerge(this.data, data);
|
|
210
|
-
return this;
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Attach an error to the event. Automatically escalates the event
|
|
214
|
-
* level to "error".
|
|
215
|
-
* @param error The error to attach
|
|
216
|
-
* @returns `this` for chaining
|
|
217
|
-
*/
|
|
218
|
-
setError(error) {
|
|
219
|
-
this.attachedError = error;
|
|
220
|
-
return this;
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* Set the HTTP response status code.
|
|
224
|
-
* @param status HTTP status code
|
|
225
|
-
* @returns `this` for chaining
|
|
226
|
-
*/
|
|
227
|
-
setStatus(status) {
|
|
228
|
-
this.status = status;
|
|
229
|
-
return this;
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Record a warn-level lifecycle log entry.
|
|
233
|
-
* Escalates the event level to "warn" (unless already "error").
|
|
234
|
-
* @param message Description of the warning
|
|
235
|
-
* @param context Optional structured context
|
|
236
|
-
* @returns `this` for chaining
|
|
237
|
-
*/
|
|
238
|
-
warn(message, context) {
|
|
239
|
-
return this.addLogEntry("warn", message, context);
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Disposable implementation. Auto-emits the event if `autoEmit` is true
|
|
243
|
-
* and the event hasn't been manually emitted yet.
|
|
244
|
-
*
|
|
245
|
-
* Enables usage with TC39 Explicit Resource Management:
|
|
246
|
-
* ```typescript
|
|
247
|
-
* using ev = createWideEvent({ pail: logger, name: "api.checkout" });
|
|
248
|
-
* ev.set({ user: { id: 1 } });
|
|
249
|
-
* // auto-emits here when scope exits
|
|
250
|
-
* ```
|
|
251
|
-
*/
|
|
252
|
-
[Symbol.dispose]() {
|
|
253
|
-
if (this.autoEmit && !this.emitted) {
|
|
254
|
-
this.emit();
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Add an entry to the request lifecycle log and escalate level if needed.
|
|
259
|
-
*/
|
|
260
|
-
addLogEntry(level, message, context) {
|
|
261
|
-
const entry = {
|
|
262
|
-
level,
|
|
263
|
-
message,
|
|
264
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
265
|
-
};
|
|
266
|
-
if (context) {
|
|
267
|
-
entry.context = context;
|
|
268
|
-
}
|
|
269
|
-
this.requestLogs.push(entry);
|
|
270
|
-
this.escalateLevel(level);
|
|
271
|
-
return this;
|
|
272
|
-
}
|
|
273
|
-
/**
|
|
274
|
-
* Escalate the event level if the new level has higher severity.
|
|
275
|
-
*/
|
|
276
|
-
escalateLevel(level) {
|
|
277
|
-
if ((LEVEL_PRIORITY[level] ?? 0) > (LEVEL_PRIORITY[this.level] ?? 0)) {
|
|
278
|
-
this.level = level;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
const createWideEvent = (options) => new WideEvent(options);
|
|
283
|
-
|
|
284
|
-
export { WideEvent, createWideEvent };
|
|
1
|
+
var l=Object.defineProperty;var u=(s,t)=>l(s,"name",{value:t,configurable:!0});var g=Object.defineProperty,n=u((s,t)=>g(s,"name",{value:t,configurable:!0}),"o");const d={debug:0,error:3,info:1,warn:2},v={debug:"debug",error:"error",info:"info",warn:"warn"},c=n((s,t)=>{const e={...s},a=Object.keys(t);for(let i=0;i<a.length;i+=1){const r=a[i],o=t[r],h=e[r];o!==null&&typeof o=="object"&&!Array.isArray(o)&&h!==null&&typeof h=="object"&&!Array.isArray(h)?e[r]=c(h,o):e[r]=o}return e},"deepMerge"),E=n(s=>s<1e3?`${String(s)}ms`:`${(s/1e3).toFixed(2)}s`,"formatDuration"),m=n(s=>{const t={message:s.message,name:s.name};s.stack&&(t.stack=s.stack);const e=s;return e.status!==void 0?t.status=e.status:e.statusCode!==void 0&&(t.status=e.statusCode),e.data!==void 0&&(t.data=e.data),s.cause instanceof Error&&(t.cause=m(s.cause)),t},"serializeError");class p{static{u(this,"WideEvent")}static{n(this,"WideEvent")}name;autoEmit;data;emitted;attachedError;level;pail;requestLogs;service;startTime;status;timestamp;_type;constructor(t){this.name=t.name,this.pail=t.pail,this.data={},this.startTime=performance.now(),this.timestamp=new Date().toISOString(),this.emitted=!1,this.autoEmit=t.autoEmit??!0,this._type=t.type??"info",this.level="info",this.requestLogs=[],this.service=t.service}debug(t,e){return this.addLogEntry("debug",t,e)}emit(t){if(this.emitted)return;this.emitted=!0;const e=Math.round(performance.now()-this.startTime),a=this.attachedError?"error":this.level,i=t??v[a],r={duration:E(e),duration_ms:e,event:this.name,timestamp:this.timestamp,...this.data};this.service&&(r.service=this.service),this.status!==void 0&&(r.status=this.status),this.attachedError&&(r.error=m(this.attachedError)),this.requestLogs.length>0&&(r.requestLogs=this.requestLogs);const o=this.pail[i];o({message:r})}error(t,e,a){return e&&(this.attachedError=e),this.addLogEntry("error",t,a)}finish(t){t?.status!==void 0&&(this.status=t.status),t?.error&&(this.attachedError=t.error),this.emit()}getData(){return this.data}getLevel(){return this.attachedError?"error":this.level}getRequestLogs(){return this.requestLogs}info(t,e){return this.addLogEntry("info",t,e)}set(t){return this.data=c(this.data,t),this}setError(t){return this.attachedError=t,this}setStatus(t){return this.status=t,this}warn(t,e){return this.addLogEntry("warn",t,e)}[Symbol.dispose](){this.autoEmit&&!this.emitted&&this.emit()}addLogEntry(t,e,a){const i={level:t,message:e,timestamp:new Date().toISOString()};return a&&(i.context=a),this.requestLogs.push(i),this.escalateLevel(t),this}escalateLevel(t){(d[t]??0)>(d[this.level]??0)&&(this.level=t)}}const y=n(s=>new p(s),"createWideEvent");export{p as WideEvent,y as createWideEvent};
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@visulima/pail",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.13",
|
|
4
4
|
"description": "Highly configurable Logger for Node.js, Edge and Browser.",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"ansi",
|
|
7
6
|
"anolilab",
|
|
7
|
+
"ansi",
|
|
8
8
|
"browser",
|
|
9
9
|
"browser-logger",
|
|
10
10
|
"callsite",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"json",
|
|
28
28
|
"json-logger",
|
|
29
29
|
"json-logging",
|
|
30
|
-
"log level",
|
|
31
30
|
"log",
|
|
31
|
+
"log level",
|
|
32
32
|
"log-cleaner",
|
|
33
33
|
"log-rotation",
|
|
34
34
|
"log4j",
|
|
@@ -37,11 +37,10 @@
|
|
|
37
37
|
"logger",
|
|
38
38
|
"logging",
|
|
39
39
|
"node",
|
|
40
|
-
"stream",
|
|
41
|
-
"pretty",
|
|
42
40
|
"node-logger",
|
|
43
41
|
"pail",
|
|
44
42
|
"pino",
|
|
43
|
+
"pretty",
|
|
45
44
|
"pretty-error",
|
|
46
45
|
"pretty-log",
|
|
47
46
|
"print",
|
|
@@ -49,6 +48,7 @@
|
|
|
49
48
|
"redact",
|
|
50
49
|
"rotating-log",
|
|
51
50
|
"show error",
|
|
51
|
+
"stream",
|
|
52
52
|
"timer",
|
|
53
53
|
"universal",
|
|
54
54
|
"visulima",
|
|
@@ -59,6 +59,12 @@
|
|
|
59
59
|
"bugs": {
|
|
60
60
|
"url": "https://github.com/visulima/visulima/issues"
|
|
61
61
|
},
|
|
62
|
+
"license": "MIT",
|
|
63
|
+
"author": {
|
|
64
|
+
"name": "Daniel Bannert",
|
|
65
|
+
"email": "d.bannert@anolilab.de",
|
|
66
|
+
"url": "https://danielbannert.com"
|
|
67
|
+
},
|
|
62
68
|
"repository": {
|
|
63
69
|
"type": "git",
|
|
64
70
|
"url": "git+https://github.com/visulima/visulima.git",
|
|
@@ -74,14 +80,19 @@
|
|
|
74
80
|
"url": "https://anolilab.com/support"
|
|
75
81
|
}
|
|
76
82
|
],
|
|
77
|
-
"
|
|
78
|
-
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
|
|
83
|
-
"
|
|
83
|
+
"files": [
|
|
84
|
+
"dist/**",
|
|
85
|
+
"README.md",
|
|
86
|
+
"CHANGELOG.md",
|
|
87
|
+
"LICENSE.md"
|
|
88
|
+
],
|
|
89
|
+
"os": [
|
|
90
|
+
"darwin",
|
|
91
|
+
"linux",
|
|
92
|
+
"win32"
|
|
93
|
+
],
|
|
84
94
|
"type": "module",
|
|
95
|
+
"sideEffects": false,
|
|
85
96
|
"exports": {
|
|
86
97
|
".": {
|
|
87
98
|
"browser": "./dist/index.browser.js",
|
|
@@ -224,19 +235,16 @@
|
|
|
224
235
|
},
|
|
225
236
|
"./package.json": "./package.json"
|
|
226
237
|
},
|
|
227
|
-
"
|
|
228
|
-
"
|
|
229
|
-
"
|
|
230
|
-
|
|
231
|
-
"LICENSE.md"
|
|
232
|
-
],
|
|
238
|
+
"publishConfig": {
|
|
239
|
+
"access": "public",
|
|
240
|
+
"provenance": true
|
|
241
|
+
},
|
|
233
242
|
"dependencies": {
|
|
234
243
|
"@visulima/colorize": "2.0.0-alpha.10",
|
|
235
|
-
"@visulima/interactive-manager": "1.0.0-alpha.2"
|
|
236
|
-
"type-fest": "5.6.0"
|
|
244
|
+
"@visulima/interactive-manager": "1.0.0-alpha.2"
|
|
237
245
|
},
|
|
238
246
|
"peerDependencies": {
|
|
239
|
-
"@opentelemetry/api": "1.9.
|
|
247
|
+
"@opentelemetry/api": "^1.9.0",
|
|
240
248
|
"@sveltejs/kit": ">=2.0",
|
|
241
249
|
"@visulima/redact": "3.0.0-alpha.10",
|
|
242
250
|
"elysia": ">=1.0",
|
|
@@ -277,14 +285,5 @@
|
|
|
277
285
|
},
|
|
278
286
|
"engines": {
|
|
279
287
|
"node": "^22.14.0 || >=24.10.0"
|
|
280
|
-
},
|
|
281
|
-
"os": [
|
|
282
|
-
"darwin",
|
|
283
|
-
"linux",
|
|
284
|
-
"win32"
|
|
285
|
-
],
|
|
286
|
-
"publishConfig": {
|
|
287
|
-
"access": "public",
|
|
288
|
-
"provenance": true
|
|
289
288
|
}
|
|
290
289
|
}
|
package/dist/constants.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { DefaultLoggerTypes } from "./types.d.ts";
|
|
2
|
-
/**
|
|
3
|
-
* Extended RFC 5424 Log Levels
|
|
4
|
-
*
|
|
5
|
-
* The log levels pail uses are those defined in the syslog protocol.
|
|
6
|
-
* Each level is assigned a numeric priority where lower numbers indicate higher priority.
|
|
7
|
-
* @see https://datatracker.ietf.org/doc/html/rfc5424#page-36
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* import { EXTENDED_RFC_5424_LOG_LEVELS } from "@visulima/pail";
|
|
11
|
-
*
|
|
12
|
-
* console.log(EXTENDED_RFC_5424_LOG_LEVELS.error); // 5
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
export declare const EXTENDED_RFC_5424_LOG_LEVELS: Record<string, number>;
|
|
16
|
-
/**
|
|
17
|
-
* Default Logger Types Configuration
|
|
18
|
-
*
|
|
19
|
-
* Predefined logger types with their associated colors, labels, and log levels.
|
|
20
|
-
* These types provide semantic meaning to different kinds of log messages.
|
|
21
|
-
* @example
|
|
22
|
-
* ```typescript
|
|
23
|
-
* import { LOG_TYPES } from "@visulima/pail";
|
|
24
|
-
*
|
|
25
|
-
* console.log(LOG_TYPES.error.color); // "red"
|
|
26
|
-
* console.log(LOG_TYPES.success.label); // "success"
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
export declare const LOG_TYPES: DefaultLoggerTypes;
|
|
30
|
-
/**
|
|
31
|
-
* Empty Symbol
|
|
32
|
-
*
|
|
33
|
-
* A unique symbol used internally to represent empty or undefined message values.
|
|
34
|
-
* This helps distinguish between intentional empty messages and undefined values.
|
|
35
|
-
* @internal
|
|
36
|
-
*/
|
|
37
|
-
export declare const EMPTY_SYMBOL: symbol;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Minimal type definitions to avoid requiring next as a dependency.
|
|
3
|
-
*/
|
|
4
|
-
interface NextRequest {
|
|
5
|
-
headers: Headers;
|
|
6
|
-
nextUrl: {
|
|
7
|
-
pathname: string;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
interface NextResponse {
|
|
11
|
-
headers: Headers;
|
|
12
|
-
}
|
|
13
|
-
interface NextResponseConstructor {
|
|
14
|
-
next: (options?: {
|
|
15
|
-
request?: {
|
|
16
|
-
headers?: Headers;
|
|
17
|
-
};
|
|
18
|
-
}) => NextResponse;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Options for the Next.js pail middleware.
|
|
22
|
-
*/
|
|
23
|
-
interface PailNextMiddlewareOptions {
|
|
24
|
-
/**
|
|
25
|
-
* Glob patterns for paths to exclude from logging.
|
|
26
|
-
* Excluded paths won't get request IDs or timing headers.
|
|
27
|
-
* @example ["/_next/**", "/favicon.ico"]
|
|
28
|
-
*/
|
|
29
|
-
exclude?: string[];
|
|
30
|
-
/**
|
|
31
|
-
* Glob patterns for paths to include in logging.
|
|
32
|
-
* If not set, all non-excluded paths are included.
|
|
33
|
-
*/
|
|
34
|
-
include?: string[];
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Create a Next.js edge middleware that sets `x-request-id` and `x-pail-start`
|
|
38
|
-
* headers on the request for downstream use by `withPail()`.
|
|
39
|
-
*
|
|
40
|
-
* This middleware runs at the edge and prepares request metadata.
|
|
41
|
-
* The actual wide event logging happens in `withPail()`.
|
|
42
|
-
* @param NextResponseClass The NextResponse class from "next/server.d.ts";
|
|
43
|
-
* @param options Middleware configuration
|
|
44
|
-
* @returns A middleware function
|
|
45
|
-
* @example
|
|
46
|
-
* ```typescript
|
|
47
|
-
* // middleware.ts
|
|
48
|
-
* import { NextResponse } from "next/server.d.ts";
|
|
49
|
-
* import { pailMiddleware } from "@visulima/pail/middleware/next";
|
|
50
|
-
*
|
|
51
|
-
* const middleware = pailMiddleware(NextResponse, {
|
|
52
|
-
* exclude: ["/_next/**", "/favicon.ico"],
|
|
53
|
-
* });
|
|
54
|
-
*
|
|
55
|
-
* export default middleware;
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
export declare const pailMiddleware: (NextResponseClass: NextResponseConstructor, options?: PailNextMiddlewareOptions) => ((request: NextRequest) => NextResponse);
|
|
59
|
-
export type { PailNextMiddlewareOptions };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
-
import type { WideEvent } from "../../wide-event.d.ts";
|
|
3
|
-
/**
|
|
4
|
-
* AsyncLocalStorage instance used to propagate the WideEvent logger
|
|
5
|
-
* through Next.js server actions, route handlers, and server components.
|
|
6
|
-
*/
|
|
7
|
-
export declare const pailStorage: AsyncLocalStorage<WideEvent>;
|
|
8
|
-
/**
|
|
9
|
-
* Retrieve the request-scoped WideEvent logger from AsyncLocalStorage.
|
|
10
|
-
* Must be called within a `withPail()` wrapped handler or server action.
|
|
11
|
-
* @returns The request-scoped WideEvent logger
|
|
12
|
-
* @throws Error if called outside of a withPail context
|
|
13
|
-
*/
|
|
14
|
-
export declare const useLogger: () => WideEvent;
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import type { PailBrowserImpl } from "../../pail.d.ts";
|
|
2
|
-
import type { DefaultLogTypes, LoggerFunction } from "../../types.d.ts";
|
|
3
|
-
import type { WideEventFinishOptions } from "../../wide-event.d.ts";
|
|
4
|
-
import { WideEvent } from "../../wide-event.d.ts";
|
|
5
|
-
import type { RouteConfig } from "./routes.d.ts";
|
|
6
|
-
/**
|
|
7
|
-
* A pail instance with dynamically generated log methods.
|
|
8
|
-
*/
|
|
9
|
-
type PailLike<T extends string = string> = PailBrowserImpl<T> & Record<DefaultLogTypes | T, LoggerFunction>;
|
|
10
|
-
/**
|
|
11
|
-
* Base options shared by all framework middleware adapters.
|
|
12
|
-
* @template T - Custom logger type names from the pail instance
|
|
13
|
-
*/
|
|
14
|
-
export interface PailMiddlewareOptions<T extends string = string> {
|
|
15
|
-
/**
|
|
16
|
-
* Glob patterns for paths to exclude from logging.
|
|
17
|
-
* Exclusions take precedence over inclusions.
|
|
18
|
-
* @example ["/health", "/api/_internal/**"]
|
|
19
|
-
*/
|
|
20
|
-
exclude?: string[];
|
|
21
|
-
/**
|
|
22
|
-
* Glob patterns for paths to include in logging.
|
|
23
|
-
* If not set, all non-excluded paths are logged.
|
|
24
|
-
* @example ["/api/**"]
|
|
25
|
-
*/
|
|
26
|
-
include?: string[];
|
|
27
|
-
/**
|
|
28
|
-
* The pail logger instance to use for wide event emission.
|
|
29
|
-
*/
|
|
30
|
-
pail: PailLike<T>;
|
|
31
|
-
/**
|
|
32
|
-
* Route-specific configuration. Maps glob patterns to config.
|
|
33
|
-
* First matching route wins.
|
|
34
|
-
* @example { "/api/auth/**": { service: "auth-service" } }
|
|
35
|
-
*/
|
|
36
|
-
routes?: Record<string, RouteConfig>;
|
|
37
|
-
/**
|
|
38
|
-
* Default service name for all wide events.
|
|
39
|
-
* Can be overridden per-route via `routes`.
|
|
40
|
-
*/
|
|
41
|
-
service?: string;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Result of creating a middleware logger for a request.
|
|
45
|
-
*/
|
|
46
|
-
export interface MiddlewareLoggerResult {
|
|
47
|
-
/**
|
|
48
|
-
* Finalize and emit the wide event. Sets status/error before emitting.
|
|
49
|
-
* Safe to call multiple times — only the first call emits.
|
|
50
|
-
*/
|
|
51
|
-
finish: (options?: WideEventFinishOptions) => void;
|
|
52
|
-
/**
|
|
53
|
-
* The request-scoped WideEvent logger.
|
|
54
|
-
* Use `set()`, `info()`, `warn()`, `error()`, `debug()` to accumulate context.
|
|
55
|
-
*/
|
|
56
|
-
logger: WideEvent;
|
|
57
|
-
/**
|
|
58
|
-
* Whether this request was skipped (excluded from logging).
|
|
59
|
-
* When true, `logger` and `finish` should not be used.
|
|
60
|
-
*/
|
|
61
|
-
skipped: boolean;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Core factory function used by all framework middleware adapters.
|
|
65
|
-
*
|
|
66
|
-
* Creates a WideEvent for the given request, checks route inclusion/exclusion,
|
|
67
|
-
* resolves the service name, and returns a logger + finish callback.
|
|
68
|
-
* @param options Middleware options including pail instance and route config
|
|
69
|
-
* @param request Request metadata for the current HTTP request
|
|
70
|
-
* @param request.headers Safe headers extracted from the request
|
|
71
|
-
* @param request.method The HTTP method (GET, POST, etc.)
|
|
72
|
-
* @param request.path The URL path of the request
|
|
73
|
-
* @param request.requestId A unique identifier for this request
|
|
74
|
-
* @returns A result object with logger, finish callback, and skipped flag
|
|
75
|
-
*/
|
|
76
|
-
export declare const createMiddlewareLogger: <T extends string = string>(options: PailMiddlewareOptions<T>, request: {
|
|
77
|
-
headers?: Record<string, string>;
|
|
78
|
-
method: string;
|
|
79
|
-
path: string;
|
|
80
|
-
requestId: string;
|
|
81
|
-
}) => MiddlewareLoggerResult;
|
|
82
|
-
export {};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Extract safe headers from a Web API Headers object, filtering out
|
|
3
|
-
* sensitive headers like Authorization, Cookie, and API keys.
|
|
4
|
-
* @param headers Web API Headers object
|
|
5
|
-
* @returns Plain object of safe header key-value pairs
|
|
6
|
-
*/
|
|
7
|
-
export declare const extractSafeHeaders: (headers: Headers) => Record<string, string>;
|
|
8
|
-
/**
|
|
9
|
-
* Extract safe headers from a Node.js IncomingHttpHeaders object,
|
|
10
|
-
* filtering out sensitive headers.
|
|
11
|
-
* @param headers Node.js IncomingHttpHeaders-like object
|
|
12
|
-
* @returns Plain object of safe header key-value pairs
|
|
13
|
-
*/
|
|
14
|
-
export declare const extractSafeNodeHeaders: (headers: Record<string, string | string[] | undefined>) => Record<string, string>;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Check if a path matches a glob pattern.
|
|
3
|
-
*/
|
|
4
|
-
export declare const matchesPattern: (path: string, pattern: string) => boolean;
|
|
5
|
-
/**
|
|
6
|
-
* Route configuration for a specific path pattern.
|
|
7
|
-
*/
|
|
8
|
-
export interface RouteConfig {
|
|
9
|
-
/** Override the service name for requests matching this route. */
|
|
10
|
-
service?: string;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Determine whether a request path should be logged based on include/exclude patterns.
|
|
14
|
-
*
|
|
15
|
-
* - Exclusions take precedence over inclusions.
|
|
16
|
-
* - If no include patterns are provided, all non-excluded paths are logged.
|
|
17
|
-
* @param path The request path
|
|
18
|
-
* @param include Glob patterns of paths to include
|
|
19
|
-
* @param exclude Glob patterns of paths to exclude
|
|
20
|
-
* @returns Whether the path should be logged
|
|
21
|
-
*/
|
|
22
|
-
export declare const shouldLog: (path: string, include?: string[], exclude?: string[]) => boolean;
|
|
23
|
-
/**
|
|
24
|
-
* Get the service name override for a given path based on route configuration.
|
|
25
|
-
* Returns the first matching route's service name, or undefined if no match.
|
|
26
|
-
* @param path The request path
|
|
27
|
-
* @param routes Route configuration map (pattern → config)
|
|
28
|
-
* @returns The service name override, or undefined
|
|
29
|
-
*/
|
|
30
|
-
export declare const getServiceForPath: (path: string, routes?: Record<string, RouteConfig>) => string | undefined;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
-
import type { WideEvent } from "../../wide-event.d.ts";
|
|
3
|
-
/**
|
|
4
|
-
* Create an isolated AsyncLocalStorage instance and a `useLogger` accessor
|
|
5
|
-
* for retrieving the request-scoped WideEvent from anywhere in the call stack.
|
|
6
|
-
*
|
|
7
|
-
* Each framework adapter should call this once at module level to get its own
|
|
8
|
-
* isolated storage instance.
|
|
9
|
-
* @param contextHint A description of the expected context, used in the
|
|
10
|
-
* error message when `useLogger` is called outside of a request scope.
|
|
11
|
-
* @returns An object with `storage` and `useLogger`
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* const { storage, useLogger } = createLoggerStorage(
|
|
15
|
-
* "Express middleware context. Make sure evlog middleware is registered."
|
|
16
|
-
* );
|
|
17
|
-
*
|
|
18
|
-
* // In middleware:
|
|
19
|
-
* storage.run(wideEvent, () => next());
|
|
20
|
-
*
|
|
21
|
-
* // In handler:
|
|
22
|
-
* const log = useLogger();
|
|
23
|
-
* log.set({ user: { id: 1 } });
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
export declare const createLoggerStorage: (contextHint: string) => {
|
|
27
|
-
storage: AsyncLocalStorage<WideEvent>;
|
|
28
|
-
useLogger: () => WideEvent;
|
|
29
|
-
};
|