evlog 2.12.0 → 2.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/README.md +111 -0
  2. package/dist/adapters/axiom.d.mts +1 -1
  3. package/dist/adapters/better-stack.d.mts +1 -1
  4. package/dist/adapters/datadog.d.mts +1 -1
  5. package/dist/adapters/fs.d.mts +1 -1
  6. package/dist/adapters/hyperdx.d.mts +1 -1
  7. package/dist/adapters/otlp.d.mts +1 -1
  8. package/dist/adapters/posthog.d.mts +1 -1
  9. package/dist/adapters/sentry.d.mts +1 -1
  10. package/dist/ai/index.d.mts +106 -5
  11. package/dist/ai/index.d.mts.map +1 -1
  12. package/dist/ai/index.mjs +28 -5
  13. package/dist/ai/index.mjs.map +1 -1
  14. package/dist/audit-d9esRZOK.mjs +1440 -0
  15. package/dist/audit-d9esRZOK.mjs.map +1 -0
  16. package/dist/audit-mUutdf6A.d.mts +1130 -0
  17. package/dist/audit-mUutdf6A.d.mts.map +1 -0
  18. package/dist/better-auth/index.d.mts +220 -0
  19. package/dist/better-auth/index.d.mts.map +1 -0
  20. package/dist/better-auth/index.mjs +205 -0
  21. package/dist/better-auth/index.mjs.map +1 -0
  22. package/dist/browser.d.mts +1 -1
  23. package/dist/elysia/index.d.mts +2 -2
  24. package/dist/elysia/index.d.mts.map +1 -1
  25. package/dist/elysia/index.mjs +16 -4
  26. package/dist/elysia/index.mjs.map +1 -1
  27. package/dist/enrichers.d.mts +1 -1
  28. package/dist/{error-WRz4_F3W.d.mts → error-D1FZI2Kd.d.mts} +2 -2
  29. package/dist/{error-WRz4_F3W.d.mts.map → error-D1FZI2Kd.d.mts.map} +1 -1
  30. package/dist/error.d.mts +1 -1
  31. package/dist/{errors-J2kt7mZh.d.mts → errors-NIXCyk6I.d.mts} +2 -2
  32. package/dist/{errors-J2kt7mZh.d.mts.map → errors-NIXCyk6I.d.mts.map} +1 -1
  33. package/dist/express/index.d.mts +2 -2
  34. package/dist/express/index.d.mts.map +1 -1
  35. package/dist/express/index.mjs +8 -4
  36. package/dist/express/index.mjs.map +1 -1
  37. package/dist/fastify/index.d.mts +2 -2
  38. package/dist/fastify/index.d.mts.map +1 -1
  39. package/dist/fastify/index.mjs +8 -4
  40. package/dist/fastify/index.mjs.map +1 -1
  41. package/dist/fork-CTJXnpl8.mjs +72 -0
  42. package/dist/fork-CTJXnpl8.mjs.map +1 -0
  43. package/dist/headers-D74M0wsg.mjs +30 -0
  44. package/dist/headers-D74M0wsg.mjs.map +1 -0
  45. package/dist/hono/index.d.mts +2 -2
  46. package/dist/hono/index.mjs +2 -1
  47. package/dist/hono/index.mjs.map +1 -1
  48. package/dist/http.d.mts +1 -1
  49. package/dist/index.d.mts +7 -7
  50. package/dist/index.mjs +2 -2
  51. package/dist/{logger-Bm0k3Hf3.d.mts → logger-b3epPH0N.d.mts} +8 -4
  52. package/dist/logger-b3epPH0N.d.mts.map +1 -0
  53. package/dist/logger.d.mts +1 -1
  54. package/dist/logger.mjs +1 -1
  55. package/dist/{headers-ht4yS2mx.mjs → middleware-BWOJ7JI0.mjs} +9 -30
  56. package/dist/middleware-BWOJ7JI0.mjs.map +1 -0
  57. package/dist/{middleware-D_igVy93.d.mts → middleware-BYf26Lfu.d.mts} +14 -3
  58. package/dist/{middleware-D_igVy93.d.mts.map → middleware-BYf26Lfu.d.mts.map} +1 -1
  59. package/dist/nestjs/index.d.mts +2 -2
  60. package/dist/nestjs/index.d.mts.map +1 -1
  61. package/dist/nestjs/index.mjs +8 -4
  62. package/dist/nestjs/index.mjs.map +1 -1
  63. package/dist/next/client.d.mts +1 -1
  64. package/dist/next/index.d.mts +4 -4
  65. package/dist/next/index.d.mts.map +1 -1
  66. package/dist/next/index.mjs +15 -1
  67. package/dist/next/index.mjs.map +1 -1
  68. package/dist/next/instrumentation.d.mts +1 -1
  69. package/dist/next/instrumentation.mjs +1 -1
  70. package/dist/nitro/module.d.mts +2 -2
  71. package/dist/nitro/plugin.mjs +1 -1
  72. package/dist/nitro/v3/index.d.mts +2 -2
  73. package/dist/nitro/v3/module.d.mts +1 -1
  74. package/dist/nitro/v3/plugin.mjs +1 -1
  75. package/dist/nitro/v3/useLogger.d.mts +1 -1
  76. package/dist/{nitro-BeRXZcBd.d.mts → nitro-DenB86W6.d.mts} +2 -2
  77. package/dist/{nitro-BeRXZcBd.d.mts.map → nitro-DenB86W6.d.mts.map} +1 -1
  78. package/dist/nuxt/module.d.mts +1 -1
  79. package/dist/nuxt/module.mjs +1 -1
  80. package/dist/{parseError-DhXS_vzM.d.mts → parseError-BR9pocvY.d.mts} +2 -2
  81. package/dist/parseError-BR9pocvY.d.mts.map +1 -0
  82. package/dist/react-router/index.d.mts +2 -2
  83. package/dist/react-router/index.d.mts.map +1 -1
  84. package/dist/react-router/index.mjs +8 -4
  85. package/dist/react-router/index.mjs.map +1 -1
  86. package/dist/runtime/client/log.d.mts +1 -1
  87. package/dist/runtime/server/routes/_evlog/ingest.post.mjs +1 -1
  88. package/dist/runtime/server/useLogger.d.mts +1 -1
  89. package/dist/runtime/utils/parseError.d.mts +2 -2
  90. package/dist/{storage-DpLJYMoc.mjs → storage-CFGTn37X.mjs} +1 -1
  91. package/dist/{storage-DpLJYMoc.mjs.map → storage-CFGTn37X.mjs.map} +1 -1
  92. package/dist/sveltekit/index.d.mts +2 -2
  93. package/dist/sveltekit/index.d.mts.map +1 -1
  94. package/dist/sveltekit/index.mjs +8 -4
  95. package/dist/sveltekit/index.mjs.map +1 -1
  96. package/dist/toolkit.d.mts +41 -4
  97. package/dist/toolkit.d.mts.map +1 -1
  98. package/dist/toolkit.mjs +5 -3
  99. package/dist/types.d.mts +2 -2
  100. package/dist/{useLogger-Dcj1Nrsa.d.mts → useLogger-C56tDPwf.d.mts} +2 -2
  101. package/dist/{useLogger-Dcj1Nrsa.d.mts.map → useLogger-C56tDPwf.d.mts.map} +1 -1
  102. package/dist/{utils-Bnc95-VC.d.mts → utils-DzGCLRFe.d.mts} +2 -2
  103. package/dist/{utils-Bnc95-VC.d.mts.map → utils-DzGCLRFe.d.mts.map} +1 -1
  104. package/dist/utils.d.mts +1 -1
  105. package/dist/vite/index.d.mts +1 -1
  106. package/dist/workers.d.mts +1 -1
  107. package/dist/workers.mjs +1 -1
  108. package/package.json +16 -3
  109. package/dist/headers-ht4yS2mx.mjs.map +0 -1
  110. package/dist/logger-Bm0k3Hf3.d.mts.map +0 -1
  111. package/dist/logger-DY0X5oQd.mjs +0 -704
  112. package/dist/logger-DY0X5oQd.mjs.map +0 -1
  113. package/dist/parseError-DhXS_vzM.d.mts.map +0 -1
  114. package/dist/types-D5OwxZCw.d.mts +0 -587
  115. package/dist/types-D5OwxZCw.d.mts.map +0 -1
@@ -1,587 +0,0 @@
1
- //#region src/types.d.ts
2
- declare module 'nitropack/types' {
3
- interface NitroRuntimeHooks {
4
- /**
5
- * Tail sampling hook - called before emitting a log.
6
- * Set `ctx.shouldKeep = true` to force-keep the log regardless of head sampling.
7
- *
8
- * @example
9
- * ```ts
10
- * nitroApp.hooks.hook('evlog:emit:keep', (ctx) => {
11
- * if (ctx.context.user?.premium) {
12
- * ctx.shouldKeep = true
13
- * }
14
- * })
15
- * ```
16
- */
17
- 'evlog:emit:keep': (ctx: TailSamplingContext) => void | Promise<void>;
18
- /**
19
- * Enrichment hook - called after emit, before drain.
20
- * Use this to enrich the event with derived context (e.g. geo, user agent).
21
- *
22
- * @example
23
- * ```ts
24
- * nitroApp.hooks.hook('evlog:enrich', (ctx) => {
25
- * ctx.event.deploymentId = process.env.DEPLOYMENT_ID
26
- * })
27
- * ```
28
- */
29
- 'evlog:enrich': (ctx: EnrichContext) => void | Promise<void>;
30
- /**
31
- * Drain hook - called after emitting a log (fire-and-forget).
32
- * Use this to send logs to external services like Axiom, Loki, or custom endpoints.
33
- * Errors are logged but never block the request.
34
- *
35
- * @example
36
- * ```ts
37
- * nitroApp.hooks.hook('evlog:drain', async (ctx) => {
38
- * await fetch('https://api.axiom.co/v1/datasets/logs/ingest', {
39
- * method: 'POST',
40
- * headers: { Authorization: `Bearer ${process.env.AXIOM_TOKEN}` },
41
- * body: JSON.stringify([ctx.event])
42
- * })
43
- * })
44
- * ```
45
- */
46
- 'evlog:drain': (ctx: DrainContext) => void | Promise<void>;
47
- }
48
- }
49
- declare module 'nitro/types' {
50
- interface NitroRuntimeHooks {
51
- 'evlog:emit:keep': (ctx: TailSamplingContext) => void | Promise<void>;
52
- 'evlog:enrich': (ctx: EnrichContext) => void | Promise<void>;
53
- 'evlog:drain': (ctx: DrainContext) => void | Promise<void>;
54
- }
55
- }
56
- /**
57
- * Transport configuration for sending client logs to the server
58
- */
59
- interface TransportConfig {
60
- /**
61
- * Enable sending logs to the server API
62
- * @default false
63
- */
64
- enabled?: boolean;
65
- /**
66
- * API endpoint for log ingestion
67
- * @default '/api/_evlog/ingest'
68
- */
69
- endpoint?: string;
70
- /**
71
- * Fetch credentials mode
72
- * @default 'same-origin'
73
- */
74
- credentials?: RequestCredentials;
75
- }
76
- /**
77
- * Payload sent from client to server for log ingestion
78
- */
79
- interface IngestPayload {
80
- timestamp: string;
81
- level: 'info' | 'error' | 'warn' | 'debug';
82
- [key: string]: unknown;
83
- }
84
- /**
85
- * Auto-redaction configuration for PII protection.
86
- * Scrubs sensitive data from wide events before console output and draining.
87
- *
88
- * Built-in patterns are included by default. Opt out with `builtins: false`
89
- * or select specific ones with `builtins: ['email', 'creditCard']`.
90
- */
91
- interface RedactConfig {
92
- /** Dot-notation paths to redact (e.g., 'user.email', 'headers.x-forwarded-for') */
93
- paths?: string[];
94
- /** Additional regex patterns to match and replace string values anywhere in the event */
95
- patterns?: RegExp[];
96
- /**
97
- * Control built-in PII patterns.
98
- * - `undefined` / omitted → all built-ins enabled (default)
99
- * - `false` → no built-ins, only custom `paths`/`patterns`
100
- * - `['email', 'creditCard', ...]` → only the listed built-ins
101
- *
102
- * Available: `'creditCard'`, `'email'`, `'ipv4'`, `'phone'`, `'jwt'`, `'bearer'`, `'iban'`
103
- */
104
- builtins?: false | Array<'creditCard' | 'email' | 'ipv4' | 'phone' | 'jwt' | 'bearer' | 'iban'>;
105
- /**
106
- * Replacement string used for path-based and custom pattern redaction.
107
- * Built-in patterns use smart partial masking instead (e.g. `****1111` for credit cards).
108
- * @default '[REDACTED]'
109
- */
110
- replacement?: string;
111
- /** @internal Resolved masker functions from built-in patterns. Not user-facing. */
112
- _maskers?: Array<[RegExp, (match: string) => string]>;
113
- }
114
- /**
115
- * Sampling rates per log level (0-100 percentage)
116
- */
117
- interface SamplingRates {
118
- /** Percentage of info logs to keep (0-100). Default: 100 */
119
- info?: number;
120
- /** Percentage of warn logs to keep (0-100). Default: 100 */
121
- warn?: number;
122
- /** Percentage of debug logs to keep (0-100). Default: 100 */
123
- debug?: number;
124
- /** Percentage of error logs to keep (0-100). Default: 100 */
125
- error?: number;
126
- }
127
- /**
128
- * Tail sampling condition for forcing log retention based on request outcome.
129
- * All conditions use >= comparison (e.g., status: 400 means status >= 400).
130
- */
131
- interface TailSamplingCondition {
132
- /** Keep if HTTP status >= this value (e.g., 400 for all errors) */
133
- status?: number;
134
- /** Keep if request duration >= this value in milliseconds */
135
- duration?: number;
136
- /** Keep if path matches this glob pattern (e.g., '/api/critical/**') */
137
- path?: string;
138
- }
139
- /**
140
- * Context passed to tail sampling evaluation and hooks.
141
- * Contains request outcome information for sampling decisions.
142
- */
143
- interface TailSamplingContext {
144
- /** HTTP response status code */
145
- status?: number;
146
- /** Request duration in milliseconds (raw number) */
147
- duration?: number;
148
- /** Request path */
149
- path?: string;
150
- /** HTTP method */
151
- method?: string;
152
- /** Full accumulated context from the request logger */
153
- context: Record<string, unknown>;
154
- /**
155
- * Set to true in evlog:emit:keep hook to force keep this log.
156
- * Multiple hooks can set this - if any sets it to true, the log is kept.
157
- */
158
- shouldKeep?: boolean;
159
- }
160
- /**
161
- * Context passed to the evlog:enrich hook.
162
- * Called after emit, before drain.
163
- */
164
- interface EnrichContext {
165
- /** The emitted wide event (mutable). */
166
- event: WideEvent;
167
- /** Request metadata (if available) */
168
- request?: {
169
- method?: string;
170
- path: string;
171
- requestId?: string;
172
- };
173
- /** Safe HTTP request headers (sensitive headers filtered out) */
174
- headers?: Record<string, string>;
175
- /** Optional response metadata */
176
- response?: {
177
- status?: number;
178
- headers?: Record<string, string>;
179
- };
180
- }
181
- /**
182
- * Context passed to the evlog:drain hook.
183
- * Contains the complete wide event and request metadata for external transport.
184
- */
185
- interface DrainContext {
186
- /** The complete wide event to drain */
187
- event: WideEvent;
188
- /** Request metadata (if available) */
189
- request?: {
190
- method?: string;
191
- path?: string;
192
- requestId?: string;
193
- };
194
- /** HTTP headers from the original request (useful for correlation with external services) */
195
- headers?: Record<string, string>;
196
- }
197
- /**
198
- * Sampling configuration for filtering logs
199
- */
200
- interface SamplingConfig {
201
- /**
202
- * Sampling rates per log level (head sampling).
203
- * Values are percentages from 0 to 100.
204
- * Default: 100 for all levels (log everything).
205
- * Error defaults to 100 even if not specified.
206
- *
207
- * @example
208
- * ```ts
209
- * sampling: {
210
- * rates: {
211
- * info: 10, // Keep 10% of info logs
212
- * warn: 50, // Keep 50% of warning logs
213
- * debug: 5, // Keep 5% of debug logs
214
- * error: 100, // Always keep errors (default)
215
- * }
216
- * }
217
- * ```
218
- */
219
- rates?: SamplingRates;
220
- /**
221
- * Tail sampling conditions for forcing log retention (OR logic).
222
- * If ANY condition matches, the log is kept regardless of head sampling.
223
- * Use the `evlog:emit:keep` Nitro hook for custom conditions.
224
- *
225
- * @example
226
- * ```ts
227
- * sampling: {
228
- * rates: { info: 10 }, // Head sampling: keep 10% of info logs
229
- * keep: [
230
- * { status: 400 }, // Always keep if status >= 400
231
- * { duration: 1000 }, // Always keep if duration >= 1000ms
232
- * { path: '/api/critical/**' }, // Always keep critical paths
233
- * ]
234
- * }
235
- * ```
236
- */
237
- keep?: TailSamplingCondition[];
238
- }
239
- /**
240
- * Route-based service configuration
241
- */
242
- interface RouteConfig {
243
- /** Service name to use for routes matching this pattern */
244
- service: string;
245
- }
246
- /**
247
- * Environment context automatically included in every log event
248
- */
249
- interface EnvironmentContext {
250
- /** Service name (auto-detected from package.json or configurable) */
251
- service: string;
252
- /** Environment: 'development', 'production', 'test', etc. */
253
- environment: 'development' | 'production' | 'test' | string;
254
- /** Application version (auto-detected from package.json) */
255
- version?: string;
256
- /** Git commit hash (auto-detected from CI/CD env vars) */
257
- commitHash?: string;
258
- /** Deployment region (auto-detected from cloud provider env vars) */
259
- region?: string;
260
- }
261
- /**
262
- * Logger configuration options
263
- */
264
- interface LoggerConfig {
265
- /**
266
- * Enable or disable all logging globally.
267
- * When false, all emits, tagged logs, and request logger operations become no-ops.
268
- * @default true
269
- */
270
- enabled?: boolean;
271
- /** Environment context overrides */
272
- env?: Partial<EnvironmentContext>;
273
- /** Enable pretty printing (auto-detected: true in dev, false in prod) */
274
- pretty?: boolean;
275
- /** Sampling configuration for filtering logs */
276
- sampling?: SamplingConfig;
277
- /**
278
- * Minimum severity for the global `log` API (tagged and object form).
279
- * Does not apply to `createLogger().emit()` / request wide events (use `sampling` for volume).
280
- * Order: debug < info < warn < error.
281
- * @default 'debug' (all levels)
282
- */
283
- minLevel?: LogLevel;
284
- /**
285
- * When pretty is disabled, emit JSON strings (default) or raw objects.
286
- * Set to false for environments like Cloudflare Workers that expect objects.
287
- * @default true
288
- */
289
- stringify?: boolean;
290
- /**
291
- * Suppress built-in console output.
292
- * When true, events are still built, sampled, and passed to drains,
293
- * but nothing is written to console. Use when drains own the output
294
- * channel (e.g., stdout-based platforms like GCP Cloud Run, AWS Lambda).
295
- * @default false
296
- */
297
- silent?: boolean;
298
- /**
299
- * Auto-redaction configuration for PII protection.
300
- * Scrubs sensitive data from wide events before console output and before any drain.
301
- *
302
- * - `true` → enable with all built-in patterns (email, credit card, IPv4, phone, JWT, Bearer, IBAN)
303
- * - `{ paths, patterns, builtins }` → fine-grained control
304
- * - `false` → explicitly disable redaction
305
- *
306
- * @default true in production, false in development
307
- *
308
- * @example
309
- * ```ts
310
- * // Disable in production
311
- * initLogger({ redact: false })
312
- *
313
- * // With custom paths on top of built-ins
314
- * initLogger({
315
- * redact: {
316
- * paths: ['user.password', 'headers.authorization'],
317
- * },
318
- * })
319
- *
320
- * // Only specific built-ins + custom patterns
321
- * initLogger({
322
- * redact: {
323
- * builtins: ['email', 'creditCard'],
324
- * patterns: [/SECRET_\w+/g],
325
- * },
326
- * })
327
- * ```
328
- */
329
- redact?: boolean | RedactConfig;
330
- /**
331
- * Drain callback called with every emitted event (fire-and-forget).
332
- * Use this to send logs to external services outside of Nitro.
333
- * Compatible with drain adapters (`createAxiomDrain()`) and pipeline-wrapped drains.
334
- *
335
- * @example
336
- * ```ts
337
- * import { initLogger, log } from 'evlog'
338
- * import { createAxiomDrain } from 'evlog/axiom'
339
- *
340
- * initLogger({
341
- * drain: createAxiomDrain({ dataset: 'logs', token: '...' }),
342
- * })
343
- *
344
- * log.info({ action: 'user_login' }) // automatically drained
345
- * ```
346
- *
347
- * @example
348
- * ```ts
349
- * // With pipeline for batching and retry
350
- * import { createDrainPipeline } from 'evlog/pipeline'
351
- *
352
- * const pipeline = createDrainPipeline({ batch: { size: 25 } })
353
- * const drain = pipeline(createAxiomDrain({ dataset: 'logs', token: '...' }))
354
- *
355
- * initLogger({ drain })
356
- *
357
- * // Flush on shutdown
358
- * process.on('beforeExit', () => drain.flush())
359
- * ```
360
- */
361
- drain?: (ctx: DrainContext) => void | Promise<void>;
362
- /** @internal Suppress the "silent without drain" warning (used by hook-based frameworks like Nitro/Nuxt) */
363
- _suppressDrainWarning?: boolean;
364
- }
365
- /**
366
- * Base structure for all wide events
367
- */
368
- interface BaseWideEvent {
369
- timestamp: string;
370
- level: 'info' | 'error' | 'warn' | 'debug';
371
- service: string;
372
- environment: string;
373
- version?: string;
374
- commitHash?: string;
375
- region?: string;
376
- }
377
- /**
378
- * Wide event with arbitrary additional fields
379
- */
380
- type WideEvent = BaseWideEvent & Record<string, unknown>;
381
- /**
382
- * Recursively makes all properties optional.
383
- * Arrays are kept as-is (not deeply partial).
384
- */
385
- type DeepPartial<T> = T extends Array<unknown> ? T : T extends object ? { [K in keyof T]?: DeepPartial<T[K]> } : T;
386
- /**
387
- * Fields set internally by the evlog plugin (status, service, etc.).
388
- * These are always accepted by `set()` regardless of the user-defined field type.
389
- */
390
- interface InternalFields {
391
- status?: number;
392
- service?: string;
393
- requestLogs?: RequestLogEntry[];
394
- }
395
- /**
396
- * Request-scoped log entry captured during a request lifecycle.
397
- */
398
- interface RequestLogEntry {
399
- level: 'info' | 'warn';
400
- message: string;
401
- timestamp: string;
402
- }
403
- /**
404
- * Resolved context type for logger methods.
405
- * User fields are deeply partial (matching deep merge behavior) with internal
406
- * field keys omitted to avoid intersection conflicts, then internal fields
407
- * are added back with their canonical types.
408
- */
409
- type FieldContext<T extends object = Record<string, unknown>> = DeepPartial<Omit<T, keyof InternalFields>> & InternalFields;
410
- /**
411
- * Request-scoped logger for building wide events
412
- *
413
- * @example
414
- * ```ts
415
- * const logger = useLogger(event)
416
- * logger.set({ user: { id: '123' } })
417
- * logger.set({ cart: { items: 3 } })
418
- * // emit() is called automatically by the plugin
419
- * ```
420
- *
421
- * @example
422
- * ```ts
423
- * // With typed fields for compile-time safety
424
- * interface MyFields {
425
- * user: { id: string; plan: string }
426
- * action: string
427
- * }
428
- * const logger = useLogger<MyFields>(event)
429
- * logger.set({ user: { id: '123', plan: 'pro' } }) // OK
430
- * logger.set({ user: { id: '123' } }) // OK (deep partial)
431
- * logger.set({ action: 'checkout' }) // OK
432
- * logger.set({ status: 200 }) // OK (internal field)
433
- * logger.set({ account: '...' }) // TS error
434
- * ```
435
- */
436
- interface RequestLogger<T extends object = Record<string, unknown>> {
437
- /**
438
- * Add context to the wide event (deep merge via defu)
439
- */
440
- set: (context: FieldContext<T>) => void;
441
- /**
442
- * Log an error and capture its details
443
- */
444
- error: (error: Error | string, context?: FieldContext<T>) => void;
445
- /**
446
- * Capture an informational message inside the request wide event.
447
- */
448
- info: (message: string, context?: FieldContext<T>) => void;
449
- /**
450
- * Capture a warning message inside the request wide event.
451
- */
452
- warn: (message: string, context?: FieldContext<T>) => void;
453
- /**
454
- * Emit the final wide event with all accumulated context.
455
- * Returns the emitted WideEvent, or null if the log was sampled out.
456
- */
457
- emit: (overrides?: FieldContext<T> & {
458
- _forceKeep?: boolean;
459
- }) => WideEvent | null;
460
- /**
461
- * Get the current accumulated context
462
- */
463
- getContext: () => FieldContext<T> & Record<string, unknown>;
464
- }
465
- /**
466
- * Log level type
467
- */
468
- type LogLevel = 'info' | 'error' | 'warn' | 'debug';
469
- /**
470
- * Simple logging API - as easy as console.log
471
- *
472
- * @example
473
- * ```ts
474
- * log.info('auth', 'User logged in')
475
- * log.error({ action: 'payment', error: 'failed' })
476
- * ```
477
- */
478
- interface Log {
479
- /**
480
- * Log an info message or wide event
481
- * @example log.info('auth', 'User logged in')
482
- * @example log.info({ action: 'login', userId: '123' })
483
- */
484
- info(tag: string, message: string): void;
485
- info(event: Record<string, unknown>): void;
486
- /**
487
- * Log an error message or wide event
488
- * @example log.error('payment', 'Payment failed')
489
- * @example log.error({ action: 'payment', error: 'declined' })
490
- */
491
- error(tag: string, message: string): void;
492
- error(event: Record<string, unknown>): void;
493
- /**
494
- * Log a warning message or wide event
495
- * @example log.warn('api', 'Rate limit approaching')
496
- * @example log.warn({ action: 'api', remaining: 10 })
497
- */
498
- warn(tag: string, message: string): void;
499
- warn(event: Record<string, unknown>): void;
500
- /**
501
- * Log a debug message or wide event
502
- * @example log.debug('cache', 'Cache miss')
503
- * @example log.debug({ action: 'cache', key: 'user_123' })
504
- */
505
- debug(tag: string, message: string): void;
506
- debug(event: Record<string, unknown>): void;
507
- }
508
- /**
509
- * Error options for creating structured errors
510
- */
511
- interface ErrorOptions {
512
- /** What actually happened */
513
- message: string;
514
- /** HTTP status code (default: 500) */
515
- status?: number;
516
- /** Why this error occurred */
517
- why?: string;
518
- /** How to fix this issue */
519
- fix?: string;
520
- /** Link to documentation or more information */
521
- link?: string;
522
- /** The original error that caused this */
523
- cause?: Error;
524
- /**
525
- * Backend-only diagnostic context (auditing, support, debugging).
526
- * Never included in HTTP responses or `EvlogError#toJSON`; included in wide events when the error is passed to `log.error()`.
527
- */
528
- internal?: Record<string, unknown>;
529
- }
530
- /**
531
- * Options for creating a request logger
532
- */
533
- interface RequestLoggerOptions {
534
- method?: string;
535
- path?: string;
536
- requestId?: string;
537
- }
538
- /**
539
- * H3 event context with evlog logger attached
540
- */
541
- interface H3EventContext {
542
- log?: RequestLogger;
543
- requestId?: string;
544
- status?: number;
545
- /** Internal: start time for duration calculation in tail sampling */
546
- _evlogStartTime?: number;
547
- /** Internal: flag to prevent double emission on errors */
548
- _evlogEmitted?: boolean;
549
- /** Internal: whether the route matched shouldLog filtering (emit-time guard) */
550
- _evlogShouldEmit?: boolean;
551
- [key: string]: unknown;
552
- }
553
- /**
554
- * Server event type for Nitro/h3 handlers
555
- */
556
- interface ServerEvent {
557
- method: string;
558
- path: string;
559
- context: H3EventContext & {
560
- /** Cloudflare Workers context (available when deployed to CF Workers) */cloudflare?: {
561
- context: {
562
- waitUntil: (promise: Promise<unknown>) => void;
563
- };
564
- }; /** Vercel Edge context (available when deployed to Vercel Edge) */
565
- waitUntil?: (promise: Promise<unknown>) => void;
566
- };
567
- node?: {
568
- res?: {
569
- statusCode?: number;
570
- };
571
- };
572
- response?: Response;
573
- }
574
- /**
575
- * Parsed evlog error with all fields at the top level
576
- */
577
- interface ParsedError {
578
- message: string;
579
- status: number;
580
- why?: string;
581
- fix?: string;
582
- link?: string;
583
- raw: unknown;
584
- }
585
- //#endregion
586
- export { TailSamplingCondition as C, WideEvent as E, ServerEvent as S, TransportConfig as T, RequestLogger as _, EnvironmentContext as a, SamplingConfig as b, H3EventContext as c, Log as d, LogLevel as f, RequestLogEntry as g, RedactConfig as h, EnrichContext as i, IngestPayload as l, ParsedError as m, DeepPartial as n, ErrorOptions as o, LoggerConfig as p, DrainContext as r, FieldContext as s, BaseWideEvent as t, InternalFields as u, RequestLoggerOptions as v, TailSamplingContext as w, SamplingRates as x, RouteConfig as y };
587
- //# sourceMappingURL=types-D5OwxZCw.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types-D5OwxZCw.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";;YAGY,iBAAA;;;;;;;;;;;;;;IAcR,iBAAA,GAAoB,GAAA,EAAK,mBAAA,YAA+B,OAAA;IAAA;;;;;;;;;;;IAaxD,cAAA,GAAiB,GAAA,EAAK,aAAA,YAAyB,OAAA;IAkBK;;;;;;;;;;;;;;;;IAApD,aAAA,GAAgB,GAAA,EAAK,YAAA,YAAwB,OAAA;EAAA;AAAA;AAAA;EAAA,UAKrC,iBAAA;IACR,iBAAA,GAAoB,GAAA,EAAK,mBAAA,YAA+B,OAAA;IACxD,cAAA,GAAiB,GAAA,EAAK,aAAA,YAAyB,OAAA;IAC/C,aAAA,GAAgB,GAAA,EAAK,YAAA,YAAwB,OAAA;EAAA;AAAA;;AAOjD;;UAAiB,eAAA;EAiBiB;;;;EAZhC,OAAA;EAYgC;;AAMlC;;EAZE,QAAA;EAY4B;;;;EAN5B,WAAA,GAAc,kBAAA;AAAA;AAmBhB;;;AAAA,UAbiB,aAAA;EACf,SAAA;EACA,KAAA;EAAA,CACC,GAAA;AAAA;;;;;;;;UAUc,YAAA;EAqBJ;EAnBX,KAAA;EAmB2B;EAjB3B,QAAA,GAAW,MAAA;EAiB6B;AAM1C;;;;;;;EAdE,QAAA,WAAmB,KAAA;EAsBd;;AAOP;;;EAvBE,WAAA;EAyBA;EAvBA,QAAA,GAAW,KAAA,EAAO,MAAA,GAAS,KAAA;AAAA;;;AAkC7B;UA5BiB,aAAA;;EAEf,IAAA;EA4BA;EA1BA,IAAA;EA8BA;EA5BA,KAAA;EAgCA;EA9BA,KAAA;AAAA;;;AA0CF;;UAnCiB,qBAAA;EAqCR;EAnCP,MAAA;EA+CY;EA7CZ,QAAA;EA6CkB;EA3ClB,IAAA;AAAA;;;;;UAOe,mBAAA;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