@visulima/pail 4.0.0-alpha.11 → 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.
Files changed (78) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE.md +152 -894
  3. package/dist/error.d.ts +95 -96
  4. package/dist/index.browser.d.ts +557 -47
  5. package/dist/index.browser.js +1 -1
  6. package/dist/index.server.d.ts +722 -61
  7. package/dist/index.server.js +5 -4
  8. package/dist/middleware/elysia.d.ts +65 -63
  9. package/dist/middleware/express.d.ts +73 -71
  10. package/dist/middleware/fastify.d.ts +69 -67
  11. package/dist/middleware/hono.d.ts +74 -72
  12. package/dist/middleware/next/handler.d.ts +101 -34
  13. package/dist/middleware/sveltekit.d.ts +100 -98
  14. package/dist/object-tree.d.ts +67 -70
  15. package/dist/packem_shared/{PrettyReporter-BtTr13Ha.js → PrettyReporter-CIbrmjUV.js} +1 -1
  16. package/dist/packem_shared/{PrettyReporter-BCvyNzXO.js → PrettyReporter-CNJEO9g7.js} +11 -8
  17. package/dist/packem_shared/abstract-json-reporter.d-BAgznjyU.d.ts +61 -0
  18. package/dist/packem_shared/{abstract-pretty-reporter-CXAKYCb8.js → abstract-pretty-reporter-CkqCt5hg.js} +4 -2
  19. package/dist/packem_shared/create-middleware-logger.d-DheMh8q4.d.ts +47 -0
  20. package/dist/packem_shared/{index-Bx3-C0j9.js → index-6cG1Kp0t.js} +2 -2
  21. package/dist/packem_shared/types.d-BeLumqgD.d.ts +246 -0
  22. package/dist/packem_shared/types.d-C51XNfQz.d.ts +194 -0
  23. package/dist/packem_shared/types.d-CM5ie2qm.d.ts +236 -0
  24. package/dist/packem_shared/wide-event.d-B-t8ZnhI.d.ts +704 -0
  25. package/dist/processor/caller/caller-processor.d.ts +49 -47
  26. package/dist/processor/environment-processor.d.ts +113 -113
  27. package/dist/processor/environment-processor.js +3 -10
  28. package/dist/processor/message-formatter-processor.d.ts +51 -49
  29. package/dist/processor/message-formatter-processor.js +2 -2
  30. package/dist/processor/opentelemetry-processor.d.ts +69 -66
  31. package/dist/processor/redact-processor.d.ts +60 -41
  32. package/dist/processor/sampling-processor.d.ts +102 -101
  33. package/dist/reporter/file/json-file-reporter.d.ts +91 -42
  34. package/dist/reporter/http/abstract-http-reporter.d.ts +213 -211
  35. package/dist/reporter/http/http-reporter.d.ts +40 -36
  36. package/dist/reporter/http/http-reporter.edge-light.d.ts +430 -38
  37. package/dist/reporter/json/index.browser.d.ts +99 -3
  38. package/dist/reporter/json/index.d.ts +51 -3
  39. package/dist/reporter/pretty/index.browser.d.ts +106 -2
  40. package/dist/reporter/pretty/index.browser.js +1 -1
  41. package/dist/reporter/pretty/index.d.ts +219 -2
  42. package/dist/reporter/pretty/index.js +1 -1
  43. package/dist/reporter/simple/simple-reporter.server.d.ts +168 -18
  44. package/dist/reporter/simple/simple-reporter.server.js +3 -2
  45. package/dist/wide-event.d.ts +5 -300
  46. package/package.json +6 -7
  47. package/dist/constants.d.ts +0 -37
  48. package/dist/middleware/next/middleware.d.ts +0 -59
  49. package/dist/middleware/next/storage.d.ts +0 -14
  50. package/dist/middleware/shared/create-middleware-logger.d.ts +0 -82
  51. package/dist/middleware/shared/headers.d.ts +0 -14
  52. package/dist/middleware/shared/routes.d.ts +0 -30
  53. package/dist/middleware/shared/storage.d.ts +0 -29
  54. package/dist/pail.browser.d.ts +0 -412
  55. package/dist/pail.server.d.ts +0 -158
  56. package/dist/processor/caller/get-caller-filename.d.ts +0 -23
  57. package/dist/reporter/file/utils/rotating-file-stream.d.ts +0 -48
  58. package/dist/reporter/http/utils/compression.d.ts +0 -7
  59. package/dist/reporter/http/utils/log-size-error.d.ts +0 -30
  60. package/dist/reporter/http/utils/retry.d.ts +0 -27
  61. package/dist/reporter/json/abstract-json-reporter.d.ts +0 -61
  62. package/dist/reporter/json/json-reporter.browser.d.ts +0 -40
  63. package/dist/reporter/json/json-reporter.server.d.ts +0 -50
  64. package/dist/reporter/pretty/abstract-pretty-reporter.d.ts +0 -83
  65. package/dist/reporter/pretty/pretty-reporter.browser.d.ts +0 -36
  66. package/dist/reporter/pretty/pretty-reporter.server.d.ts +0 -70
  67. package/dist/reporter/raw/raw-reporter.browser.d.ts +0 -5
  68. package/dist/reporter/raw/raw-reporter.server.d.ts +0 -13
  69. package/dist/reporter/utils/default-inspector-config.d.ts +0 -3
  70. package/dist/reporter/utils/format-label.d.ts +0 -3
  71. package/dist/types.d.ts +0 -241
  72. package/dist/utils/arrayify.d.ts +0 -2
  73. package/dist/utils/get-longest-badge.d.ts +0 -4
  74. package/dist/utils/get-longest-label.d.ts +0 -4
  75. package/dist/utils/merge-types.d.ts +0 -4
  76. package/dist/utils/stream/safe-stream-handler.d.ts +0 -21
  77. package/dist/utils/write-console-log-based-on-level.d.ts +0 -4
  78. package/dist/utils/write-stream.d.ts +0 -2
@@ -1,300 +1,5 @@
1
- import type { PailBrowserImpl } from "./pail.d.ts";
2
- import type { DefaultLogTypes, LoggerFunction } from "./types.d.ts";
3
- /**
4
- * A pail instance with dynamically generated log methods.
5
- * This is the minimal interface WideEvent needs from a pail logger.
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/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@visulima/pail",
3
- "version": "4.0.0-alpha.11",
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",
@@ -232,8 +232,7 @@
232
232
  ],
233
233
  "dependencies": {
234
234
  "@visulima/colorize": "2.0.0-alpha.10",
235
- "@visulima/interactive-manager": "1.0.0-alpha.2",
236
- "type-fest": "5.6.0"
235
+ "@visulima/interactive-manager": "1.0.0-alpha.2"
237
236
  },
238
237
  "peerDependencies": {
239
238
  "@opentelemetry/api": "1.9.1",
@@ -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
- };