@visulima/pail 4.0.0-alpha.10 → 4.0.0-alpha.12
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 +57 -0
- package/LICENSE.md +143 -931
- package/dist/error.d.ts +95 -96
- package/dist/index.browser.d.ts +557 -47
- package/dist/index.browser.js +2 -2
- package/dist/index.server.d.ts +722 -65
- package/dist/index.server.js +27 -410
- package/dist/middleware/elysia.d.ts +65 -63
- package/dist/middleware/elysia.js +2 -2
- package/dist/middleware/express.d.ts +73 -71
- package/dist/middleware/express.js +1 -1
- package/dist/middleware/fastify.d.ts +69 -67
- package/dist/middleware/fastify.js +2 -2
- package/dist/middleware/hono.d.ts +74 -72
- package/dist/middleware/next/handler.d.ts +101 -34
- package/dist/middleware/sveltekit.d.ts +100 -98
- package/dist/object-tree.d.ts +67 -70
- package/dist/packem_shared/{AbstractJsonReporter-DlugSJpY.js → AbstractJsonReporter-BO8Calb4.js} +1 -5
- package/dist/packem_shared/{AbstractJsonReporter-CjtVgHbU.js → AbstractJsonReporter-nOj0Ft1F.js} +1 -5
- package/dist/packem_shared/{JsonReporter-Dbw82ewj.js → JsonReporter-CCmj7oYL.js} +1 -1
- package/dist/packem_shared/{JsonReporter-BgPvIyC2.js → JsonReporter-Ck2PIAEw.js} +2 -2
- package/dist/packem_shared/{PrettyReporter-C2dCzIaf.js → PrettyReporter-CIbrmjUV.js} +2 -4
- package/dist/packem_shared/{PrettyReporter-gMqa7j_m.js → PrettyReporter-CNJEO9g7.js} +1250 -15
- package/dist/packem_shared/abstract-json-reporter.d-BAgznjyU.d.ts +61 -0
- package/dist/packem_shared/{abstract-pretty-reporter-szQO-IgK.js → abstract-pretty-reporter-CkqCt5hg.js} +2300 -2298
- package/dist/packem_shared/create-middleware-logger.d-DheMh8q4.d.ts +47 -0
- package/dist/packem_shared/{index-Bx3-C0j9.js → index-6cG1Kp0t.js} +2 -2
- package/dist/packem_shared/types.d-BeLumqgD.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/wide-event.d-B-t8ZnhI.d.ts +704 -0
- package/dist/packem_shared/{write-stream-BuFtjATz.js → write-stream-MDqyXmc_.js} +1 -1
- package/dist/processor/caller/caller-processor.d.ts +49 -47
- package/dist/processor/caller/caller-processor.js +1 -1
- package/dist/processor/environment-processor.d.ts +113 -113
- package/dist/processor/message-formatter-processor.d.ts +51 -49
- package/dist/processor/message-formatter-processor.js +2 -2
- package/dist/processor/opentelemetry-processor.d.ts +69 -66
- package/dist/processor/redact-processor.d.ts +60 -41
- package/dist/processor/sampling-processor.d.ts +102 -101
- package/dist/reporter/file/json-file-reporter.d.ts +91 -42
- package/dist/reporter/file/json-file-reporter.js +1 -1
- package/dist/reporter/http/abstract-http-reporter.d.ts +213 -211
- package/dist/reporter/http/abstract-http-reporter.js +1 -1
- 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 +1 -5
- package/dist/reporter/json/index.browser.d.ts +99 -3
- package/dist/reporter/json/index.browser.js +2 -2
- package/dist/reporter/json/index.d.ts +51 -3
- package/dist/reporter/json/index.js +2 -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 +219 -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 +3 -2
- package/dist/wide-event.d.ts +5 -300
- package/dist/wide-event.js +3 -2
- package/package.json +9 -21
- package/dist/constants.d.ts +0 -37
- package/dist/interactive/index.d.ts +0 -2
- package/dist/interactive/index.js +0 -2
- package/dist/interactive/interactive-manager.d.ts +0 -108
- package/dist/interactive/interactive-stream-hook.d.ts +0 -68
- 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/InteractiveManager-CowYA3Hx.js +0 -178
- package/dist/packem_shared/InteractiveStreamHook-BypRlYTX.js +0 -133
- package/dist/packem_shared/Spinner-Cokext9b.js +0 -2183
- package/dist/packem_shared/getBarChar-D7JfmdTr.js +0 -459
- package/dist/packem_shared/index-BEfVUy9P.js +0 -1256
- package/dist/pail.browser.d.ts +0 -412
- package/dist/pail.server.d.ts +0 -233
- package/dist/processor/caller/get-caller-filename.d.ts +0 -23
- package/dist/progress-bar.d.ts +0 -145
- package/dist/progress-bar.js +0 -459
- 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/spinner.d.ts +0 -220
- package/dist/spinner.js +0 -2183
- package/dist/types.d.ts +0 -241
- package/dist/utils/ansi-escapes.d.ts +0 -4
- 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.d.ts
CHANGED
|
@@ -1,300 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
type PailLike<T extends string = string> = PailBrowserImpl<T> & Record<DefaultLogTypes | T, LoggerFunction>;
|
|
8
|
-
/**
|
|
9
|
-
* Makes all properties in T optional recursively.
|
|
10
|
-
*/
|
|
11
|
-
type DeepPartial<T> = {
|
|
12
|
-
[K in keyof T]?: T[K] extends Record<string, unknown> ? DeepPartial<T[K]> : T[K];
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Severity levels for wide events.
|
|
16
|
-
*/
|
|
17
|
-
export type WideEventLevel = "debug" | "error" | "info" | "warn";
|
|
18
|
-
/**
|
|
19
|
-
* An entry in the request lifecycle log.
|
|
20
|
-
*/
|
|
21
|
-
export interface RequestLogEntry {
|
|
22
|
-
/**
|
|
23
|
-
* Additional structured context for this log entry.
|
|
24
|
-
*/
|
|
25
|
-
context?: Record<string, unknown>;
|
|
26
|
-
/**
|
|
27
|
-
* Severity level of this entry.
|
|
28
|
-
*/
|
|
29
|
-
level: WideEventLevel;
|
|
30
|
-
/**
|
|
31
|
-
* Human-readable message describing what happened.
|
|
32
|
-
*/
|
|
33
|
-
message: string;
|
|
34
|
-
/**
|
|
35
|
-
* ISO 8601 timestamp of when this entry was recorded.
|
|
36
|
-
*/
|
|
37
|
-
timestamp: string;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Serialized error information included in the emitted wide event.
|
|
41
|
-
*/
|
|
42
|
-
export interface SerializedError {
|
|
43
|
-
cause?: SerializedError;
|
|
44
|
-
data?: unknown;
|
|
45
|
-
message: string;
|
|
46
|
-
name: string;
|
|
47
|
-
stack?: string;
|
|
48
|
-
status?: number;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Options for finishing a wide event with HTTP context.
|
|
52
|
-
*/
|
|
53
|
-
export interface WideEventFinishOptions {
|
|
54
|
-
/**
|
|
55
|
-
* An error that occurred during the operation.
|
|
56
|
-
* Will be serialized and included in the emitted event.
|
|
57
|
-
*/
|
|
58
|
-
error?: Error;
|
|
59
|
-
/**
|
|
60
|
-
* HTTP response status code.
|
|
61
|
-
*/
|
|
62
|
-
status?: number;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Options for creating a WideEvent instance.
|
|
66
|
-
* @template T - Custom logger type names
|
|
67
|
-
*/
|
|
68
|
-
export interface WideEventOptions<T extends string = string> {
|
|
69
|
-
/**
|
|
70
|
-
* Auto-emit the event when disposed via `Symbol.dispose`.
|
|
71
|
-
* Works with TC39 Explicit Resource Management (`using`).
|
|
72
|
-
* @default true
|
|
73
|
-
*/
|
|
74
|
-
autoEmit?: boolean;
|
|
75
|
-
/**
|
|
76
|
-
* Event name identifying this wide event, e.g. "api.checkout", "worker.send-email".
|
|
77
|
-
*/
|
|
78
|
-
name: string;
|
|
79
|
-
/**
|
|
80
|
-
* The pail logger instance to use for emission.
|
|
81
|
-
*/
|
|
82
|
-
pail: PailLike<T>;
|
|
83
|
-
/**
|
|
84
|
-
* Service name for this event. Overrides any service name from pail's scope.
|
|
85
|
-
*/
|
|
86
|
-
service?: string;
|
|
87
|
-
/**
|
|
88
|
-
* Base log type to use when emitting. Defaults to "info".
|
|
89
|
-
* The actual type may be escalated based on logged warnings/errors.
|
|
90
|
-
*/
|
|
91
|
-
type?: DefaultLogTypes | T;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* A wide event logger that accumulates context incrementally and emits
|
|
95
|
-
* a single comprehensive log event through pail.
|
|
96
|
-
*
|
|
97
|
-
* Instead of scattering multiple log calls throughout an operation,
|
|
98
|
-
* use `set()` to build up context as information becomes available,
|
|
99
|
-
* then emit once at the end. Lifecycle methods (`info()`, `warn()`, `error()`,
|
|
100
|
-
* `debug()`) record timestamped entries in a `requestLogs` array and
|
|
101
|
-
* automatically escalate the event's severity level.
|
|
102
|
-
*
|
|
103
|
-
* Implements `Disposable` for use with TC39 Explicit Resource Management.
|
|
104
|
-
* @template TData - Shape of the accumulated event data
|
|
105
|
-
* @template T - Custom logger type names from the pail instance
|
|
106
|
-
* @example
|
|
107
|
-
* ```typescript
|
|
108
|
-
* // Manual finish
|
|
109
|
-
* const ev = createWideEvent({ pail: logger, name: "api.checkout" });
|
|
110
|
-
* ev.set({ user: { id: 1 } });
|
|
111
|
-
* ev.info("Validated cart");
|
|
112
|
-
* ev.set({ cart: { items: 3, total: 9999 } });
|
|
113
|
-
* ev.finish({ status: 200 });
|
|
114
|
-
*
|
|
115
|
-
* // Auto-emit with Explicit Resource Management
|
|
116
|
-
* using ev = createWideEvent({ pail: logger, name: "api.checkout" });
|
|
117
|
-
* ev.set({ user: { id: 1 } });
|
|
118
|
-
* // emits automatically when scope exits
|
|
119
|
-
*
|
|
120
|
-
* // Typed data shape
|
|
121
|
-
* interface CheckoutData {
|
|
122
|
-
* user: { id: number; plan: string };
|
|
123
|
-
* cart: { items: number; total: number };
|
|
124
|
-
* }
|
|
125
|
-
* const ev = createWideEvent<CheckoutData>({ pail: logger, name: "api.checkout" });
|
|
126
|
-
* ev.set({ user: { id: 1, plan: "pro" } }); // fully typed
|
|
127
|
-
* ```
|
|
128
|
-
*/
|
|
129
|
-
export declare class WideEvent<TData extends Record<string, unknown> = Record<string, unknown>, T extends string = string> implements Disposable {
|
|
130
|
-
[Symbol.dispose]: () => void;
|
|
131
|
-
readonly name: string;
|
|
132
|
-
private readonly autoEmit;
|
|
133
|
-
private data;
|
|
134
|
-
private emitted;
|
|
135
|
-
private attachedError?;
|
|
136
|
-
private level;
|
|
137
|
-
private readonly pail;
|
|
138
|
-
private readonly requestLogs;
|
|
139
|
-
private readonly service;
|
|
140
|
-
private readonly startTime;
|
|
141
|
-
private status;
|
|
142
|
-
private readonly timestamp;
|
|
143
|
-
private readonly type;
|
|
144
|
-
constructor(options: WideEventOptions<T>);
|
|
145
|
-
/**
|
|
146
|
-
* Record a debug-level lifecycle log entry.
|
|
147
|
-
* Does not escalate the event level.
|
|
148
|
-
* @param message Description of what happened
|
|
149
|
-
* @param context Optional structured context
|
|
150
|
-
* @returns `this` for chaining
|
|
151
|
-
*/
|
|
152
|
-
debug(message: string, context?: Record<string, unknown>): this;
|
|
153
|
-
/**
|
|
154
|
-
* Emit the wide event through the pail logger. Can only be called once;
|
|
155
|
-
* subsequent calls are no-ops.
|
|
156
|
-
*
|
|
157
|
-
* Automatically calculates duration, determines the log type based on
|
|
158
|
-
* the highest severity level reached, and serializes any attached error.
|
|
159
|
-
*
|
|
160
|
-
* Prefer `finish()` for HTTP request contexts where you have a status code.
|
|
161
|
-
* @param typeOverride Override the log type for this emission
|
|
162
|
-
*/
|
|
163
|
-
emit(typeOverride?: DefaultLogTypes | T): void;
|
|
164
|
-
/**
|
|
165
|
-
* Record an error-level lifecycle log entry and attach the error.
|
|
166
|
-
* Escalates the event level to "error".
|
|
167
|
-
* @param message Description of what went wrong
|
|
168
|
-
* @param error The error that occurred
|
|
169
|
-
* @param context Optional structured context
|
|
170
|
-
* @returns `this` for chaining
|
|
171
|
-
*/
|
|
172
|
-
error(message: string, error?: Error, context?: Record<string, unknown>): this;
|
|
173
|
-
/**
|
|
174
|
-
* Finish and emit the wide event with HTTP context.
|
|
175
|
-
* Sets the response status and optional error before emitting.
|
|
176
|
-
* @example
|
|
177
|
-
* ```typescript
|
|
178
|
-
* ev.finish({ status: 200 });
|
|
179
|
-
* ev.finish({ status: 500, error: new Error("DB timeout") });
|
|
180
|
-
* ```
|
|
181
|
-
* @param options Status code and/or error
|
|
182
|
-
*/
|
|
183
|
-
finish(options?: WideEventFinishOptions): void;
|
|
184
|
-
/**
|
|
185
|
-
* Get a read-only snapshot of the accumulated data.
|
|
186
|
-
*/
|
|
187
|
-
getData(): Readonly<TData>;
|
|
188
|
-
/**
|
|
189
|
-
* Get the current severity level of the event.
|
|
190
|
-
* The level auto-escalates as `warn()` or `error()` entries are added.
|
|
191
|
-
*/
|
|
192
|
-
getLevel(): WideEventLevel;
|
|
193
|
-
/**
|
|
194
|
-
* Get a read-only copy of the request lifecycle log entries.
|
|
195
|
-
*/
|
|
196
|
-
getRequestLogs(): ReadonlyArray<RequestLogEntry>;
|
|
197
|
-
/**
|
|
198
|
-
* Record an info-level lifecycle log entry.
|
|
199
|
-
* Does not escalate the event level.
|
|
200
|
-
* @param message Description of what happened
|
|
201
|
-
* @param context Optional structured context
|
|
202
|
-
* @returns `this` for chaining
|
|
203
|
-
*/
|
|
204
|
-
info(message: string, context?: Record<string, unknown>): this;
|
|
205
|
-
/**
|
|
206
|
-
* Accumulate context into the wide event via deep merge.
|
|
207
|
-
* Call as many times as needed throughout the operation.
|
|
208
|
-
* @example
|
|
209
|
-
* ```typescript
|
|
210
|
-
* ev.set({ user: { id: 1 } });
|
|
211
|
-
* ev.set({ user: { plan: "pro" } });
|
|
212
|
-
* // data = { user: { id: 1, plan: "pro" } }
|
|
213
|
-
* ```
|
|
214
|
-
* @param data Partial data to merge into the event
|
|
215
|
-
* @returns `this` for chaining
|
|
216
|
-
*/
|
|
217
|
-
set(data: DeepPartial<TData>): this;
|
|
218
|
-
/**
|
|
219
|
-
* Attach an error to the event. Automatically escalates the event
|
|
220
|
-
* level to "error".
|
|
221
|
-
* @param error The error to attach
|
|
222
|
-
* @returns `this` for chaining
|
|
223
|
-
*/
|
|
224
|
-
setError(error: Error): this;
|
|
225
|
-
/**
|
|
226
|
-
* Set the HTTP response status code.
|
|
227
|
-
* @param status HTTP status code
|
|
228
|
-
* @returns `this` for chaining
|
|
229
|
-
*/
|
|
230
|
-
setStatus(status: number): this;
|
|
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: string, context?: Record<string, unknown>): this;
|
|
239
|
-
/**
|
|
240
|
-
* Disposable implementation. Auto-emits the event if `autoEmit` is true
|
|
241
|
-
* and the event hasn't been manually emitted yet.
|
|
242
|
-
*
|
|
243
|
-
* Enables usage with TC39 Explicit Resource Management:
|
|
244
|
-
* ```typescript
|
|
245
|
-
* using ev = createWideEvent({ pail: logger, name: "api.checkout" });
|
|
246
|
-
* ev.set({ user: { id: 1 } });
|
|
247
|
-
* // auto-emits here when scope exits
|
|
248
|
-
* ```
|
|
249
|
-
*/
|
|
250
|
-
[Symbol.dispose](): void;
|
|
251
|
-
/**
|
|
252
|
-
* Add an entry to the request lifecycle log and escalate level if needed.
|
|
253
|
-
*/
|
|
254
|
-
private addLogEntry;
|
|
255
|
-
/**
|
|
256
|
-
* Escalate the event level if the new level has higher severity.
|
|
257
|
-
*/
|
|
258
|
-
private escalateLevel;
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Create a wide event logger that accumulates context and emits a single
|
|
262
|
-
* comprehensive log event through pail.
|
|
263
|
-
* @template TData - Shape of the accumulated event data
|
|
264
|
-
* @template T - Custom logger type names from the pail instance
|
|
265
|
-
* @param options Configuration options
|
|
266
|
-
* @returns A new WideEvent instance
|
|
267
|
-
* @example
|
|
268
|
-
* ```typescript
|
|
269
|
-
* import { createPail } from "@visulima/pail";
|
|
270
|
-
* import { createWideEvent } from "@visulima/pail/wide-event";
|
|
271
|
-
*
|
|
272
|
-
* const logger = createPail();
|
|
273
|
-
*
|
|
274
|
-
* // In a request handler:
|
|
275
|
-
* const ev = createWideEvent({ pail: logger, name: "api.checkout" });
|
|
276
|
-
*
|
|
277
|
-
* ev.set({ user: { id: 1, plan: "pro" } });
|
|
278
|
-
* ev.info("Validated cart", { itemCount: 3 });
|
|
279
|
-
* ev.set({ cart: { id: 42, items: 3, total: 9999 } });
|
|
280
|
-
* ev.info("Payment processed");
|
|
281
|
-
* ev.finish({ status: 200 });
|
|
282
|
-
*
|
|
283
|
-
* // Emits a single structured log:
|
|
284
|
-
* // {
|
|
285
|
-
* // event: "api.checkout",
|
|
286
|
-
* // timestamp: "2025-01-24T10:23:45.612Z",
|
|
287
|
-
* // duration: "127ms",
|
|
288
|
-
* // duration_ms: 127,
|
|
289
|
-
* // status: 200,
|
|
290
|
-
* // user: { id: 1, plan: "pro" },
|
|
291
|
-
* // cart: { id: 42, items: 3, total: 9999 },
|
|
292
|
-
* // requestLogs: [
|
|
293
|
-
* // { level: "info", message: "Validated cart", timestamp: "...", context: { itemCount: 3 } },
|
|
294
|
-
* // { level: "info", message: "Payment processed", timestamp: "..." }
|
|
295
|
-
* // ]
|
|
296
|
-
* // }
|
|
297
|
-
* ```
|
|
298
|
-
*/
|
|
299
|
-
export declare const createWideEvent: <TData extends Record<string, unknown> = Record<string, unknown>, T extends string = string>(options: WideEventOptions<T>) => WideEvent<TData, T>;
|
|
300
|
-
export {};
|
|
1
|
+
export { R as RequestLogEntry, S as SerializedError, W as WideEvent, a as WideEventFinishOptions, b as WideEventLevel, c as WideEventOptions, d as createWideEvent } from "./packem_shared/wide-event.d-B-t8ZnhI.js";
|
|
2
|
+
import "./packem_shared/types.d-BeLumqgD.js";
|
|
3
|
+
import 'safe-stable-stringify';
|
|
4
|
+
import '@visulima/colorize';
|
|
5
|
+
import '@visulima/interactive-manager';
|
package/dist/wide-event.js
CHANGED
|
@@ -66,7 +66,8 @@ class WideEvent {
|
|
|
66
66
|
startTime;
|
|
67
67
|
status;
|
|
68
68
|
timestamp;
|
|
69
|
-
|
|
69
|
+
// @ts-expect-error TS6133 -- preserved for future use (richer event categorization)
|
|
70
|
+
_type;
|
|
70
71
|
constructor(options) {
|
|
71
72
|
this.name = options.name;
|
|
72
73
|
this.pail = options.pail;
|
|
@@ -75,7 +76,7 @@ class WideEvent {
|
|
|
75
76
|
this.timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
76
77
|
this.emitted = false;
|
|
77
78
|
this.autoEmit = options.autoEmit ?? true;
|
|
78
|
-
this.
|
|
79
|
+
this._type = options.type ?? "info";
|
|
79
80
|
this.level = "info";
|
|
80
81
|
this.requestLogs = [];
|
|
81
82
|
this.service = options.service;
|
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.12",
|
|
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",
|
|
@@ -190,18 +190,6 @@
|
|
|
190
190
|
"default": "./dist/reporter/http/http-reporter.js"
|
|
191
191
|
}
|
|
192
192
|
},
|
|
193
|
-
"./progress-bar": {
|
|
194
|
-
"types": "./dist/progress-bar.d.ts",
|
|
195
|
-
"default": "./dist/progress-bar.js"
|
|
196
|
-
},
|
|
197
|
-
"./spinner": {
|
|
198
|
-
"types": "./dist/spinner.d.ts",
|
|
199
|
-
"default": "./dist/spinner.js"
|
|
200
|
-
},
|
|
201
|
-
"./interactive": {
|
|
202
|
-
"types": "./dist/interactive/index.d.ts",
|
|
203
|
-
"default": "./dist/interactive/index.js"
|
|
204
|
-
},
|
|
205
193
|
"./object-tree": {
|
|
206
194
|
"types": "./dist/object-tree.d.ts",
|
|
207
195
|
"default": "./dist/object-tree.js"
|
|
@@ -243,13 +231,13 @@
|
|
|
243
231
|
"LICENSE.md"
|
|
244
232
|
],
|
|
245
233
|
"dependencies": {
|
|
246
|
-
"@visulima/colorize": "2.0.0-alpha.
|
|
247
|
-
"
|
|
234
|
+
"@visulima/colorize": "2.0.0-alpha.10",
|
|
235
|
+
"@visulima/interactive-manager": "1.0.0-alpha.2"
|
|
248
236
|
},
|
|
249
237
|
"peerDependencies": {
|
|
250
238
|
"@opentelemetry/api": "1.9.1",
|
|
251
239
|
"@sveltejs/kit": ">=2.0",
|
|
252
|
-
"@visulima/redact": "3.0.0-alpha.
|
|
240
|
+
"@visulima/redact": "3.0.0-alpha.10",
|
|
253
241
|
"elysia": ">=1.0",
|
|
254
242
|
"express": ">=4.0",
|
|
255
243
|
"fastify": ">=4.0",
|
|
@@ -287,7 +275,7 @@
|
|
|
287
275
|
}
|
|
288
276
|
},
|
|
289
277
|
"engines": {
|
|
290
|
-
"node": "
|
|
278
|
+
"node": "^22.14.0 || >=24.10.0"
|
|
291
279
|
},
|
|
292
280
|
"os": [
|
|
293
281
|
"darwin",
|
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,108 +0,0 @@
|
|
|
1
|
-
import type InteractiveStreamHook from "./interactive-stream-hook.d.ts";
|
|
2
|
-
/** Supported stream types for interactive output */
|
|
3
|
-
type StreamType = "stderr" | "stdout";
|
|
4
|
-
/**
|
|
5
|
-
* Interactive Manager.
|
|
6
|
-
*
|
|
7
|
-
* Manages interactive terminal output by coordinating stdout and stderr streams.
|
|
8
|
-
* Enables features like progress bars, spinners, and dynamic updates by temporarily
|
|
9
|
-
* capturing and controlling terminal output. Supports suspending and resuming
|
|
10
|
-
* interactive mode for external output.
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* const manager = new InteractiveManager(stdoutHook, stderrHook);
|
|
14
|
-
*
|
|
15
|
-
* // Start interactive mode
|
|
16
|
-
* manager.hook();
|
|
17
|
-
*
|
|
18
|
-
* // Update output dynamically
|
|
19
|
-
* manager.update("stdout", ["Processing...", "50% complete"]);
|
|
20
|
-
*
|
|
21
|
-
* // Temporarily suspend for external output
|
|
22
|
-
* manager.suspend("stdout");
|
|
23
|
-
* console.log("External message");
|
|
24
|
-
* manager.resume("stdout");
|
|
25
|
-
*
|
|
26
|
-
* // End interactive mode and show final output
|
|
27
|
-
* manager.unhook();
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
declare class InteractiveManager {
|
|
31
|
-
#private;
|
|
32
|
-
/**
|
|
33
|
-
* Creates a new InteractiveManager with the given stream hooks.
|
|
34
|
-
* @param stdout Hook for stdout stream
|
|
35
|
-
* @param stderr Hook for stderr stream
|
|
36
|
-
*/
|
|
37
|
-
constructor(stdout: InteractiveStreamHook, stderr: InteractiveStreamHook);
|
|
38
|
-
/**
|
|
39
|
-
* Last printed rows count.
|
|
40
|
-
*
|
|
41
|
-
* Tracks the number of rows that were last written to the terminal.
|
|
42
|
-
* Used internally for managing cursor positioning and output updates.
|
|
43
|
-
*/
|
|
44
|
-
get lastLength(): number;
|
|
45
|
-
/**
|
|
46
|
-
* Rows count outside editable area.
|
|
47
|
-
*
|
|
48
|
-
* Tracks the number of rows that extend beyond the current terminal height.
|
|
49
|
-
* Used for managing scrolling and ensuring all output remains visible.
|
|
50
|
-
*/
|
|
51
|
-
get outside(): number;
|
|
52
|
-
/**
|
|
53
|
-
* Hook activity status.
|
|
54
|
-
*
|
|
55
|
-
* Indicates whether the interactive hooks are currently active.
|
|
56
|
-
* When true, streams are being intercepted for interactive output.
|
|
57
|
-
*/
|
|
58
|
-
get isHooked(): boolean;
|
|
59
|
-
/**
|
|
60
|
-
* Suspend status for active hooks.
|
|
61
|
-
*
|
|
62
|
-
* Indicates whether interactive mode is temporarily suspended.
|
|
63
|
-
* When suspended, external output can be written without interference.
|
|
64
|
-
*/
|
|
65
|
-
get isSuspended(): boolean;
|
|
66
|
-
/**
|
|
67
|
-
* Removes lines from the terminal output.
|
|
68
|
-
*
|
|
69
|
-
* Erases the specified number of lines from the bottom of the output,
|
|
70
|
-
* moving the cursor up and clearing the lines. Useful for removing
|
|
71
|
-
* previous interactive output before displaying new content.
|
|
72
|
-
* @param stream The stream to erase lines from ("stdout" or "stderr")
|
|
73
|
-
* @param count Number of lines to remove (defaults to lastLength)
|
|
74
|
-
* @throws {TypeError} If the specified stream is not available
|
|
75
|
-
*/
|
|
76
|
-
erase(stream: StreamType, count?: number): void;
|
|
77
|
-
/**
|
|
78
|
-
* Hook stdout and stderr streams.
|
|
79
|
-
* @returns Success status
|
|
80
|
-
*/
|
|
81
|
-
hook(): boolean;
|
|
82
|
-
/**
|
|
83
|
-
* Resume suspend hooks.
|
|
84
|
-
* @param stream Stream to resume
|
|
85
|
-
* @param eraseRowCount erase output rows count
|
|
86
|
-
*/
|
|
87
|
-
resume(stream: StreamType, eraseRowCount?: number): void;
|
|
88
|
-
/**
|
|
89
|
-
* Suspend active hooks for external output.
|
|
90
|
-
* @param stream Stream to suspend
|
|
91
|
-
* @param erase erase output
|
|
92
|
-
*/
|
|
93
|
-
suspend(stream: StreamType, erase?: boolean): void;
|
|
94
|
-
/**
|
|
95
|
-
* Unhooks both stdout and stderr streams and print their story of logs.
|
|
96
|
-
* @param separateHistory If `true`, will add an empty line to the history output for individual recorded lines and console logs
|
|
97
|
-
* @returns Success status
|
|
98
|
-
*/
|
|
99
|
-
unhook(separateHistory?: boolean): boolean;
|
|
100
|
-
/**
|
|
101
|
-
* Update output.
|
|
102
|
-
* @param stream Stream to write to
|
|
103
|
-
* @param rows Text lines to write to standard output
|
|
104
|
-
* @param from Index of the line starting from which the contents of the terminal are being overwritten
|
|
105
|
-
*/
|
|
106
|
-
update(stream: StreamType, rows: string[], from?: number): void;
|
|
107
|
-
}
|
|
108
|
-
export default InteractiveManager;
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Interactive Stream Hook.
|
|
3
|
-
*
|
|
4
|
-
* A utility class that hooks into Node.js WriteStreams to capture output
|
|
5
|
-
* for interactive terminal applications. It allows temporarily intercepting
|
|
6
|
-
* stream writes to enable features like progress bars and dynamic updates.
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* const hook = new InteractiveStreamHook(process.stdout);
|
|
10
|
-
* hook.active(); // Start capturing output
|
|
11
|
-
*
|
|
12
|
-
* // Output will be stored in history instead of being written to stdout
|
|
13
|
-
* console.log("This won't appear immediately");
|
|
14
|
-
*
|
|
15
|
-
* hook.inactive(); // Stop capturing and replay stored output
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
declare class InteractiveStreamHook {
|
|
19
|
-
#private;
|
|
20
|
-
/** Constant indicating the stream write operation was successful */
|
|
21
|
-
static readonly DRAIN = true;
|
|
22
|
-
/**
|
|
23
|
-
* Creates a new InteractiveStreamHook for the given stream.
|
|
24
|
-
* @param stream The Node.js WriteStream to hook into (usually stdout or stderr)
|
|
25
|
-
*/
|
|
26
|
-
constructor(stream: NodeJS.WriteStream);
|
|
27
|
-
/**
|
|
28
|
-
* Activates the stream hook.
|
|
29
|
-
*
|
|
30
|
-
* When active, all writes to the stream are captured in history instead of
|
|
31
|
-
* being written immediately. This allows for interactive features like
|
|
32
|
-
* progress bars that can update dynamically.
|
|
33
|
-
*/
|
|
34
|
-
active(): void;
|
|
35
|
-
/**
|
|
36
|
-
* Erases the specified number of lines from the terminal.
|
|
37
|
-
*
|
|
38
|
-
* Uses ANSI escape sequences to remove lines from the current cursor position
|
|
39
|
-
* upwards, which is useful for clearing previous output in interactive applications.
|
|
40
|
-
* @param count Number of lines to erase (including the current line)
|
|
41
|
-
*/
|
|
42
|
-
erase(count: number): void;
|
|
43
|
-
/**
|
|
44
|
-
* Deactivates the stream hook and replays captured output.
|
|
45
|
-
*
|
|
46
|
-
* Restores normal stream operation and outputs all captured history.
|
|
47
|
-
* Optionally adds a newline separator before replaying the history.
|
|
48
|
-
* @param separateHistory Whether to add a newline before replaying history
|
|
49
|
-
*/
|
|
50
|
-
inactive(separateHistory?: boolean): void;
|
|
51
|
-
/**
|
|
52
|
-
* Renews the stream hook state.
|
|
53
|
-
*
|
|
54
|
-
* Restores the original stream write method and shows the cursor.
|
|
55
|
-
* This is typically called when temporarily suspending interactive mode.
|
|
56
|
-
*/
|
|
57
|
-
renew(): void;
|
|
58
|
-
/**
|
|
59
|
-
* Writes a message directly to the underlying stream.
|
|
60
|
-
*
|
|
61
|
-
* Bypasses the hook mechanism and writes directly using the original
|
|
62
|
-
* stream write method. Useful for writing control sequences or
|
|
63
|
-
* messages that should not be captured in history.
|
|
64
|
-
* @param message The message to write to the stream
|
|
65
|
-
*/
|
|
66
|
-
write(message: string): void;
|
|
67
|
-
}
|
|
68
|
-
export default InteractiveStreamHook;
|
|
@@ -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 };
|