@logtape/koa 2.2.0-dev.685 → 2.2.0-dev.686

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/README.md CHANGED
@@ -69,6 +69,49 @@ app.use(koaLogger({
69
69
  format: "dev", // Predefined format (default: "combined")
70
70
  skip: (ctx) => ctx.path === "/health", // Skip health check endpoint
71
71
  logRequest: false, // Log after response (default: false)
72
+ context: true, // Add requestId to request-scoped logs
73
+ }));
74
+ ~~~~
75
+
76
+
77
+ Request context
78
+ ---------------
79
+
80
+ Set `context: true` to add request-scoped correlation fields. By default,
81
+ the middleware reads the `x-request-id` request header, generates an ID when
82
+ the header is missing, writes the resolved ID to the `x-request-id` response
83
+ header, and adds `requestId` to the request log record.
84
+
85
+ To make logs emitted by your route handlers inherit the same `requestId`, also
86
+ configure LogTape with `contextLocalStorage`:
87
+
88
+ ~~~~ typescript
89
+ import { AsyncLocalStorage } from "node:async_hooks";
90
+ import { configure } from "@logtape/logtape";
91
+
92
+ await configure({
93
+ // ... sinks and loggers ...
94
+ contextLocalStorage: new AsyncLocalStorage(),
95
+ });
96
+
97
+ app.use(koaLogger({ context: true }));
98
+ ~~~~
99
+
100
+ The context is still established when `skip` suppresses the request log, so
101
+ application logs inside the skipped request can keep the same request ID.
102
+
103
+ You can customize request ID headers and add more request fields:
104
+
105
+ ~~~~ typescript
106
+ app.use(koaLogger({
107
+ context: {
108
+ requestId: {
109
+ headerNames: ["x-correlation-id", "x-request-id"],
110
+ responseHeader: "x-request-id",
111
+ },
112
+ include: ["requestId", "method", "path", "remoteAddr"],
113
+ enrich: (ctx) => ({ route: ctx.path }),
114
+ },
72
115
  }));
73
116
  ~~~~
74
117
 
package/dist/mod.cjs CHANGED
@@ -2,6 +2,65 @@ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
2
  const __logtape_logtape = require_rolldown_runtime.__toESM(require("@logtape/logtape"));
3
3
 
4
4
  //#region src/mod.ts
5
+ const defaultRequestIdHeader = "x-request-id";
6
+ /**
7
+ * Normalize request context options.
8
+ */
9
+ function normalizeRequestContextOptions(options) {
10
+ if (options === true) return {};
11
+ if (options === false || options == null) return void 0;
12
+ return options;
13
+ }
14
+ /**
15
+ * Normalize request ID options.
16
+ */
17
+ function normalizeRequestIdOptions(options) {
18
+ if (options === false) return void 0;
19
+ if (options === true || options == null) return {};
20
+ return options;
21
+ }
22
+ /**
23
+ * Generate a request ID with Web Crypto when possible.
24
+ */
25
+ function generateRequestId() {
26
+ if (typeof globalThis.crypto?.randomUUID === "function") return globalThis.crypto.randomUUID();
27
+ return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
28
+ }
29
+ /**
30
+ * Normalize an incoming request ID.
31
+ */
32
+ function defaultNormalizeRequestId(value) {
33
+ const trimmed = value.trim();
34
+ return trimmed === "" ? null : trimmed;
35
+ }
36
+ /**
37
+ * Resolve the request ID for a request.
38
+ */
39
+ function resolveRequestId(ctx, options) {
40
+ const property = options.property ?? "requestId";
41
+ const normalize = options.normalize ?? defaultNormalizeRequestId;
42
+ const headerNames = options.headerNames ?? [defaultRequestIdHeader];
43
+ for (const headerName of headerNames) {
44
+ const headerValue = ctx.get(headerName);
45
+ if (headerValue === "") continue;
46
+ const normalized = normalize(headerValue);
47
+ if (normalized != null) {
48
+ const responseHeader$1 = options.responseHeader ?? defaultRequestIdHeader;
49
+ if (responseHeader$1 !== false) ctx.set?.(responseHeader$1, normalized);
50
+ return {
51
+ property,
52
+ value: normalized
53
+ };
54
+ }
55
+ }
56
+ const generated = (options.generate ?? generateRequestId)();
57
+ const responseHeader = options.responseHeader ?? defaultRequestIdHeader;
58
+ if (responseHeader !== false) ctx.set?.(responseHeader, generated);
59
+ return {
60
+ property,
61
+ value: generated
62
+ };
63
+ }
5
64
  /**
6
65
  * Get referrer from request headers.
7
66
  * Returns undefined if the header is not present or empty.
@@ -48,6 +107,60 @@ function buildProperties(ctx, responseTime) {
48
107
  };
49
108
  }
50
109
  /**
110
+ * Build request context fields from a request.
111
+ */
112
+ function buildIncludedContext(ctx, resolvedRequestId, include) {
113
+ const context = {};
114
+ for (const field of include) switch (field) {
115
+ case "requestId":
116
+ if (resolvedRequestId != null) context[resolvedRequestId.property] = resolvedRequestId.value;
117
+ break;
118
+ case "method":
119
+ context.method = ctx.method;
120
+ break;
121
+ case "url":
122
+ context.url = ctx.url;
123
+ break;
124
+ case "path":
125
+ context.path = ctx.path;
126
+ break;
127
+ case "userAgent":
128
+ context.userAgent = getUserAgent(ctx);
129
+ break;
130
+ case "remoteAddr":
131
+ context.remoteAddr = getRemoteAddr(ctx);
132
+ break;
133
+ case "referrer":
134
+ context.referrer = getReferrer(ctx);
135
+ break;
136
+ }
137
+ return context;
138
+ }
139
+ /**
140
+ * Build the implicit context for a request.
141
+ */
142
+ async function buildRequestContext(ctx, options) {
143
+ const requestIdOptions = normalizeRequestIdOptions(options.requestId);
144
+ const resolvedRequestId = requestIdOptions == null ? void 0 : resolveRequestId(ctx, requestIdOptions);
145
+ const include = options.include ?? (resolvedRequestId == null ? [] : ["requestId"]);
146
+ const context = buildIncludedContext(ctx, resolvedRequestId, include);
147
+ if (options.enrich == null) return context;
148
+ return {
149
+ ...context,
150
+ ...await options.enrich(ctx)
151
+ };
152
+ }
153
+ /**
154
+ * Add request context fields to a request log result.
155
+ */
156
+ function withRequestLogContext(result, context) {
157
+ if (typeof result === "string") return result;
158
+ return {
159
+ ...result,
160
+ ...context
161
+ };
162
+ }
163
+ /**
51
164
  * Combined format (Apache Combined Log Format).
52
165
  * Returns all structured properties.
53
166
  */
@@ -167,25 +280,34 @@ function koaLogger(options = {}) {
167
280
  const formatOption = options.format ?? "combined";
168
281
  const skip = options.skip ?? (() => false);
169
282
  const logRequest = options.logRequest ?? false;
283
+ const contextOptions = normalizeRequestContextOptions(options.context);
170
284
  const formatFn = typeof formatOption === "string" ? predefinedFormats[formatOption] : formatOption;
171
285
  const logMethod = logger[level].bind(logger);
172
286
  return async (ctx, next) => {
173
287
  const startTime = Date.now();
174
- if (logRequest) {
175
- if (!skip(ctx)) {
176
- const result$1 = formatFn(ctx, 0);
177
- if (typeof result$1 === "string") logMethod(result$1);
178
- else logMethod("{method} {url}", result$1);
288
+ const handleRequest = async (requestContext$1) => {
289
+ if (logRequest) {
290
+ if (!skip(ctx)) {
291
+ const result$1 = withRequestLogContext(formatFn(ctx, 0), requestContext$1);
292
+ if (typeof result$1 === "string") logMethod(result$1, requestContext$1);
293
+ else logMethod("{method} {url}", result$1);
294
+ }
295
+ await next();
296
+ return;
179
297
  }
180
298
  await next();
299
+ if (skip(ctx)) return;
300
+ const responseTime = Date.now() - startTime;
301
+ const result = withRequestLogContext(formatFn(ctx, responseTime), requestContext$1);
302
+ if (typeof result === "string") logMethod(result, requestContext$1);
303
+ else logMethod("{method} {url} {status} - {responseTime} ms", result);
304
+ };
305
+ if (contextOptions == null) {
306
+ await handleRequest({});
181
307
  return;
182
308
  }
183
- await next();
184
- if (skip(ctx)) return;
185
- const responseTime = Date.now() - startTime;
186
- const result = formatFn(ctx, responseTime);
187
- if (typeof result === "string") logMethod(result);
188
- else logMethod("{method} {url} {status} - {responseTime} ms", result);
309
+ const requestContext = await buildRequestContext(ctx, contextOptions);
310
+ await (0, __logtape_logtape.withContext)(requestContext, () => handleRequest(requestContext));
189
311
  };
190
312
  }
191
313
 
package/dist/mod.d.cts CHANGED
@@ -31,6 +31,12 @@ interface KoaContext {
31
31
  * @returns The header value, or an empty string if not present.
32
32
  */
33
33
  get(field: string): string;
34
+ /**
35
+ * Set a response header field value.
36
+ * @param field The header field name.
37
+ * @param value The header field value.
38
+ */
39
+ set?(field: string, value: string): void;
34
40
  }
35
41
  /**
36
42
  * Koa middleware function type.
@@ -75,6 +81,63 @@ interface RequestLogProperties {
75
81
  /** Referrer header value */
76
82
  referrer: string | undefined;
77
83
  }
84
+ /**
85
+ * Request fields that can be added to the implicit request context.
86
+ * @since 2.2.0
87
+ */
88
+ type RequestContextField = "requestId" | "method" | "url" | "path" | "userAgent" | "remoteAddr" | "referrer";
89
+ /**
90
+ * Options for extracting, generating, and propagating a request ID.
91
+ * @since 2.2.0
92
+ */
93
+ interface RequestIdOptions {
94
+ /**
95
+ * The property name used in implicit context and request log records.
96
+ * @default "requestId"
97
+ */
98
+ readonly property?: string;
99
+ /**
100
+ * Incoming request headers to inspect in order.
101
+ * @default ["x-request-id"]
102
+ */
103
+ readonly headerNames?: readonly string[];
104
+ /**
105
+ * Response header that receives the resolved request ID.
106
+ * Set to `false` to disable response header propagation.
107
+ * @default "x-request-id"
108
+ */
109
+ readonly responseHeader?: string | false;
110
+ /**
111
+ * Generates a request ID when no incoming header is present.
112
+ * @default crypto.randomUUID()
113
+ */
114
+ readonly generate?: () => string;
115
+ /**
116
+ * Normalizes an incoming request ID. Return `null` to reject the value and
117
+ * keep looking for another header or generate a new ID.
118
+ */
119
+ readonly normalize?: (value: string) => string | null;
120
+ }
121
+ /**
122
+ * Options for request-scoped implicit context.
123
+ * @since 2.2.0
124
+ */
125
+ interface RequestContextOptions {
126
+ /**
127
+ * Enables request ID extraction, generation, and response propagation.
128
+ * @default true
129
+ */
130
+ readonly requestId?: boolean | RequestIdOptions;
131
+ /**
132
+ * Fields to add to the implicit context.
133
+ * @default ["requestId"]
134
+ */
135
+ readonly include?: readonly RequestContextField[];
136
+ /**
137
+ * Adds application-specific fields to the implicit request context.
138
+ */
139
+ readonly enrich?: (ctx: KoaContext) => Record<string, unknown> | Promise<Record<string, unknown>>;
140
+ }
78
141
  /**
79
142
  * Options for configuring the Koa LogTape middleware.
80
143
  * @since 1.3.0
@@ -128,6 +191,18 @@ interface KoaLogTapeOptions {
128
191
  * @default false
129
192
  */
130
193
  readonly logRequest?: boolean;
194
+ /**
195
+ * Enables request-scoped implicit context and request ID correlation.
196
+ *
197
+ * When set to `true`, the middleware reads the `x-request-id` header,
198
+ * generates one when it is absent, writes it to the `x-request-id` response
199
+ * header, and adds `requestId` to all LogTape records emitted while handling
200
+ * the request.
201
+ *
202
+ * @default false
203
+ * @since 2.2.0
204
+ */
205
+ readonly context?: boolean | RequestContextOptions;
131
206
  }
132
207
  /**
133
208
  * Creates Koa middleware for HTTP request logging using LogTape.
@@ -188,5 +263,5 @@ interface KoaLogTapeOptions {
188
263
  declare function koaLogger(options?: KoaLogTapeOptions): KoaMiddleware;
189
264
  //# sourceMappingURL=mod.d.ts.map
190
265
  //#endregion
191
- export { FormatFunction, KoaContext, KoaLogTapeOptions, KoaMiddleware, LogLevel, PredefinedFormat, RequestLogProperties, koaLogger };
266
+ export { FormatFunction, KoaContext, KoaLogTapeOptions, KoaMiddleware, LogLevel, PredefinedFormat, RequestContextField, RequestContextOptions, RequestIdOptions, RequestLogProperties, koaLogger };
192
267
  //# sourceMappingURL=mod.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.cts","names":[],"sources":["../src/mod.ts"],"sourcesContent":[],"mappings":";;;;;AAYA;AA2BA;;;;;AAGY;AAMA,UApCK,UAAA,CAoCW;EAUhB;EAAc,MAAA,EAAA,MAAA;EAAA;EACT,GAEH,EAAA,MAAA;EAAM;EAMH,IAAA,EAAA,MAAA;EAyBA;EAAiB,MAAA,EAAA,MAAA;EAAA;EAWP,EAAA,EAeP,MAAA;EAAgB;EAAiB,QAe7B,EAAA;IAAU,MAAA,CAAA,EAAA,MAAA;EAkNlB,CAAA;EAAS;;;AAET;;;;;;;;KAlTJ,aAAA,SACL,wBACO,kBACT;;;;;KAMO,gBAAA;;;;;;;;;KAUA,cAAA,SACL,8CAEO;;;;;UAMG,oBAAA;;;;;;;;;;;;;;;;;;;;;;;;UAyBA,iBAAA;;;;;;;;;;mBAWE;;;;;;;;;;;;;;oBAeC,mBAAmB;;;;;;;;;;;;;;wBAef;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkNR,SAAA,WACL,oBACR"}
1
+ {"version":3,"file":"mod.d.cts","names":[],"sources":["../src/mod.ts"],"sourcesContent":[],"mappings":";;;;;AAYA;AAiCA;;;;;AAGY;AAMA,UA1CK,UAAA,CA0CW;EAUhB;EAAc,MAAA,EAAA,MAAA;EAAA;EACT,GAEH,EAAA,MAAA;EAAM;EAMH,IAAA,EAAA,MAAA;EAyBL;EAaK,MAAA,EAAA,MAAA;EAqCA;EAAqB,EAAA,EAAA,MAAA;EAAA;EAKW,QAMnB,EAAA;IAMrB,MAAA,CAAA,EAAA,MAAA;EAAU,CAAA;EACN;;AAA2B;AAOxC;;EAAkC,GAWf,CAAA,KAAA,EAAA,MAAA,CAAA,EAAA,MAAA;EAAQ;;;;AAsDyB;EAkVpC,GAAA,EAAA,KAAA,EAAS,MAAA,EAAA,KAAA,EAAA,MAAA,CAAA,EAAA,IAAA;;;;AAET;;KArhBJ,aAAA,SACL,wBACO,kBACT;;;;;KAMO,gBAAA;;;;;;;;;KAUA,cAAA,SACL,8CAEO;;;;;UAMG,oBAAA;;;;;;;;;;;;;;;;;;;;;;;;KAyBL,mBAAA;;;;;UAaK,gBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAqCA,qBAAA;;;;;iCAKgB;;;;;8BAMH;;;;0BAMrB,eACF,0BAA0B,QAAQ;;;;;;UAOxB,iBAAA;;;;;;;;;;mBAWE;;;;;;;;;;;;;;oBAeC,mBAAmB;;;;;;;;;;;;;;wBAef;;;;;;;;;;;;;;;;;;;;;;+BAwBO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkVf,SAAA,WACL,oBACR"}
package/dist/mod.d.ts CHANGED
@@ -31,6 +31,12 @@ interface KoaContext {
31
31
  * @returns The header value, or an empty string if not present.
32
32
  */
33
33
  get(field: string): string;
34
+ /**
35
+ * Set a response header field value.
36
+ * @param field The header field name.
37
+ * @param value The header field value.
38
+ */
39
+ set?(field: string, value: string): void;
34
40
  }
35
41
  /**
36
42
  * Koa middleware function type.
@@ -75,6 +81,63 @@ interface RequestLogProperties {
75
81
  /** Referrer header value */
76
82
  referrer: string | undefined;
77
83
  }
84
+ /**
85
+ * Request fields that can be added to the implicit request context.
86
+ * @since 2.2.0
87
+ */
88
+ type RequestContextField = "requestId" | "method" | "url" | "path" | "userAgent" | "remoteAddr" | "referrer";
89
+ /**
90
+ * Options for extracting, generating, and propagating a request ID.
91
+ * @since 2.2.0
92
+ */
93
+ interface RequestIdOptions {
94
+ /**
95
+ * The property name used in implicit context and request log records.
96
+ * @default "requestId"
97
+ */
98
+ readonly property?: string;
99
+ /**
100
+ * Incoming request headers to inspect in order.
101
+ * @default ["x-request-id"]
102
+ */
103
+ readonly headerNames?: readonly string[];
104
+ /**
105
+ * Response header that receives the resolved request ID.
106
+ * Set to `false` to disable response header propagation.
107
+ * @default "x-request-id"
108
+ */
109
+ readonly responseHeader?: string | false;
110
+ /**
111
+ * Generates a request ID when no incoming header is present.
112
+ * @default crypto.randomUUID()
113
+ */
114
+ readonly generate?: () => string;
115
+ /**
116
+ * Normalizes an incoming request ID. Return `null` to reject the value and
117
+ * keep looking for another header or generate a new ID.
118
+ */
119
+ readonly normalize?: (value: string) => string | null;
120
+ }
121
+ /**
122
+ * Options for request-scoped implicit context.
123
+ * @since 2.2.0
124
+ */
125
+ interface RequestContextOptions {
126
+ /**
127
+ * Enables request ID extraction, generation, and response propagation.
128
+ * @default true
129
+ */
130
+ readonly requestId?: boolean | RequestIdOptions;
131
+ /**
132
+ * Fields to add to the implicit context.
133
+ * @default ["requestId"]
134
+ */
135
+ readonly include?: readonly RequestContextField[];
136
+ /**
137
+ * Adds application-specific fields to the implicit request context.
138
+ */
139
+ readonly enrich?: (ctx: KoaContext) => Record<string, unknown> | Promise<Record<string, unknown>>;
140
+ }
78
141
  /**
79
142
  * Options for configuring the Koa LogTape middleware.
80
143
  * @since 1.3.0
@@ -128,6 +191,18 @@ interface KoaLogTapeOptions {
128
191
  * @default false
129
192
  */
130
193
  readonly logRequest?: boolean;
194
+ /**
195
+ * Enables request-scoped implicit context and request ID correlation.
196
+ *
197
+ * When set to `true`, the middleware reads the `x-request-id` header,
198
+ * generates one when it is absent, writes it to the `x-request-id` response
199
+ * header, and adds `requestId` to all LogTape records emitted while handling
200
+ * the request.
201
+ *
202
+ * @default false
203
+ * @since 2.2.0
204
+ */
205
+ readonly context?: boolean | RequestContextOptions;
131
206
  }
132
207
  /**
133
208
  * Creates Koa middleware for HTTP request logging using LogTape.
@@ -188,5 +263,5 @@ interface KoaLogTapeOptions {
188
263
  declare function koaLogger(options?: KoaLogTapeOptions): KoaMiddleware;
189
264
  //# sourceMappingURL=mod.d.ts.map
190
265
  //#endregion
191
- export { FormatFunction, KoaContext, KoaLogTapeOptions, KoaMiddleware, LogLevel, PredefinedFormat, RequestLogProperties, koaLogger };
266
+ export { FormatFunction, KoaContext, KoaLogTapeOptions, KoaMiddleware, LogLevel, PredefinedFormat, RequestContextField, RequestContextOptions, RequestIdOptions, RequestLogProperties, koaLogger };
192
267
  //# sourceMappingURL=mod.d.ts.map
package/dist/mod.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","names":[],"sources":["../src/mod.ts"],"sourcesContent":[],"mappings":";;;;;AAYA;AA2BA;;;;;AAGY;AAMA,UApCK,UAAA,CAoCW;EAUhB;EAAc,MAAA,EAAA,MAAA;EAAA;EACT,GAEH,EAAA,MAAA;EAAM;EAMH,IAAA,EAAA,MAAA;EAyBA;EAAiB,MAAA,EAAA,MAAA;EAAA;EAWP,EAAA,EAeP,MAAA;EAAgB;EAAiB,QAe7B,EAAA;IAAU,MAAA,CAAA,EAAA,MAAA;EAkNlB,CAAA;EAAS;;;AAET;;;;;;;;KAlTJ,aAAA,SACL,wBACO,kBACT;;;;;KAMO,gBAAA;;;;;;;;;KAUA,cAAA,SACL,8CAEO;;;;;UAMG,oBAAA;;;;;;;;;;;;;;;;;;;;;;;;UAyBA,iBAAA;;;;;;;;;;mBAWE;;;;;;;;;;;;;;oBAeC,mBAAmB;;;;;;;;;;;;;;wBAef;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkNR,SAAA,WACL,oBACR"}
1
+ {"version":3,"file":"mod.d.ts","names":[],"sources":["../src/mod.ts"],"sourcesContent":[],"mappings":";;;;;AAYA;AAiCA;;;;;AAGY;AAMA,UA1CK,UAAA,CA0CW;EAUhB;EAAc,MAAA,EAAA,MAAA;EAAA;EACT,GAEH,EAAA,MAAA;EAAM;EAMH,IAAA,EAAA,MAAA;EAyBL;EAaK,MAAA,EAAA,MAAA;EAqCA;EAAqB,EAAA,EAAA,MAAA;EAAA;EAKW,QAMnB,EAAA;IAMrB,MAAA,CAAA,EAAA,MAAA;EAAU,CAAA;EACN;;AAA2B;AAOxC;;EAAkC,GAWf,CAAA,KAAA,EAAA,MAAA,CAAA,EAAA,MAAA;EAAQ;;;;AAsDyB;EAkVpC,GAAA,EAAA,KAAA,EAAS,MAAA,EAAA,KAAA,EAAA,MAAA,CAAA,EAAA,IAAA;;;;AAET;;KArhBJ,aAAA,SACL,wBACO,kBACT;;;;;KAMO,gBAAA;;;;;;;;;KAUA,cAAA,SACL,8CAEO;;;;;UAMG,oBAAA;;;;;;;;;;;;;;;;;;;;;;;;KAyBL,mBAAA;;;;;UAaK,gBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAqCA,qBAAA;;;;;iCAKgB;;;;;8BAMH;;;;0BAMrB,eACF,0BAA0B,QAAQ;;;;;;UAOxB,iBAAA;;;;;;;;;;mBAWE;;;;;;;;;;;;;;oBAeC,mBAAmB;;;;;;;;;;;;;;wBAef;;;;;;;;;;;;;;;;;;;;;;+BAwBO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkVf,SAAA,WACL,oBACR"}
package/dist/mod.js CHANGED
@@ -1,6 +1,65 @@
1
- import { getLogger } from "@logtape/logtape";
1
+ import { getLogger, withContext } from "@logtape/logtape";
2
2
 
3
3
  //#region src/mod.ts
4
+ const defaultRequestIdHeader = "x-request-id";
5
+ /**
6
+ * Normalize request context options.
7
+ */
8
+ function normalizeRequestContextOptions(options) {
9
+ if (options === true) return {};
10
+ if (options === false || options == null) return void 0;
11
+ return options;
12
+ }
13
+ /**
14
+ * Normalize request ID options.
15
+ */
16
+ function normalizeRequestIdOptions(options) {
17
+ if (options === false) return void 0;
18
+ if (options === true || options == null) return {};
19
+ return options;
20
+ }
21
+ /**
22
+ * Generate a request ID with Web Crypto when possible.
23
+ */
24
+ function generateRequestId() {
25
+ if (typeof globalThis.crypto?.randomUUID === "function") return globalThis.crypto.randomUUID();
26
+ return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
27
+ }
28
+ /**
29
+ * Normalize an incoming request ID.
30
+ */
31
+ function defaultNormalizeRequestId(value) {
32
+ const trimmed = value.trim();
33
+ return trimmed === "" ? null : trimmed;
34
+ }
35
+ /**
36
+ * Resolve the request ID for a request.
37
+ */
38
+ function resolveRequestId(ctx, options) {
39
+ const property = options.property ?? "requestId";
40
+ const normalize = options.normalize ?? defaultNormalizeRequestId;
41
+ const headerNames = options.headerNames ?? [defaultRequestIdHeader];
42
+ for (const headerName of headerNames) {
43
+ const headerValue = ctx.get(headerName);
44
+ if (headerValue === "") continue;
45
+ const normalized = normalize(headerValue);
46
+ if (normalized != null) {
47
+ const responseHeader$1 = options.responseHeader ?? defaultRequestIdHeader;
48
+ if (responseHeader$1 !== false) ctx.set?.(responseHeader$1, normalized);
49
+ return {
50
+ property,
51
+ value: normalized
52
+ };
53
+ }
54
+ }
55
+ const generated = (options.generate ?? generateRequestId)();
56
+ const responseHeader = options.responseHeader ?? defaultRequestIdHeader;
57
+ if (responseHeader !== false) ctx.set?.(responseHeader, generated);
58
+ return {
59
+ property,
60
+ value: generated
61
+ };
62
+ }
4
63
  /**
5
64
  * Get referrer from request headers.
6
65
  * Returns undefined if the header is not present or empty.
@@ -47,6 +106,60 @@ function buildProperties(ctx, responseTime) {
47
106
  };
48
107
  }
49
108
  /**
109
+ * Build request context fields from a request.
110
+ */
111
+ function buildIncludedContext(ctx, resolvedRequestId, include) {
112
+ const context = {};
113
+ for (const field of include) switch (field) {
114
+ case "requestId":
115
+ if (resolvedRequestId != null) context[resolvedRequestId.property] = resolvedRequestId.value;
116
+ break;
117
+ case "method":
118
+ context.method = ctx.method;
119
+ break;
120
+ case "url":
121
+ context.url = ctx.url;
122
+ break;
123
+ case "path":
124
+ context.path = ctx.path;
125
+ break;
126
+ case "userAgent":
127
+ context.userAgent = getUserAgent(ctx);
128
+ break;
129
+ case "remoteAddr":
130
+ context.remoteAddr = getRemoteAddr(ctx);
131
+ break;
132
+ case "referrer":
133
+ context.referrer = getReferrer(ctx);
134
+ break;
135
+ }
136
+ return context;
137
+ }
138
+ /**
139
+ * Build the implicit context for a request.
140
+ */
141
+ async function buildRequestContext(ctx, options) {
142
+ const requestIdOptions = normalizeRequestIdOptions(options.requestId);
143
+ const resolvedRequestId = requestIdOptions == null ? void 0 : resolveRequestId(ctx, requestIdOptions);
144
+ const include = options.include ?? (resolvedRequestId == null ? [] : ["requestId"]);
145
+ const context = buildIncludedContext(ctx, resolvedRequestId, include);
146
+ if (options.enrich == null) return context;
147
+ return {
148
+ ...context,
149
+ ...await options.enrich(ctx)
150
+ };
151
+ }
152
+ /**
153
+ * Add request context fields to a request log result.
154
+ */
155
+ function withRequestLogContext(result, context) {
156
+ if (typeof result === "string") return result;
157
+ return {
158
+ ...result,
159
+ ...context
160
+ };
161
+ }
162
+ /**
50
163
  * Combined format (Apache Combined Log Format).
51
164
  * Returns all structured properties.
52
165
  */
@@ -166,25 +279,34 @@ function koaLogger(options = {}) {
166
279
  const formatOption = options.format ?? "combined";
167
280
  const skip = options.skip ?? (() => false);
168
281
  const logRequest = options.logRequest ?? false;
282
+ const contextOptions = normalizeRequestContextOptions(options.context);
169
283
  const formatFn = typeof formatOption === "string" ? predefinedFormats[formatOption] : formatOption;
170
284
  const logMethod = logger[level].bind(logger);
171
285
  return async (ctx, next) => {
172
286
  const startTime = Date.now();
173
- if (logRequest) {
174
- if (!skip(ctx)) {
175
- const result$1 = formatFn(ctx, 0);
176
- if (typeof result$1 === "string") logMethod(result$1);
177
- else logMethod("{method} {url}", result$1);
287
+ const handleRequest = async (requestContext$1) => {
288
+ if (logRequest) {
289
+ if (!skip(ctx)) {
290
+ const result$1 = withRequestLogContext(formatFn(ctx, 0), requestContext$1);
291
+ if (typeof result$1 === "string") logMethod(result$1, requestContext$1);
292
+ else logMethod("{method} {url}", result$1);
293
+ }
294
+ await next();
295
+ return;
178
296
  }
179
297
  await next();
298
+ if (skip(ctx)) return;
299
+ const responseTime = Date.now() - startTime;
300
+ const result = withRequestLogContext(formatFn(ctx, responseTime), requestContext$1);
301
+ if (typeof result === "string") logMethod(result, requestContext$1);
302
+ else logMethod("{method} {url} {status} - {responseTime} ms", result);
303
+ };
304
+ if (contextOptions == null) {
305
+ await handleRequest({});
180
306
  return;
181
307
  }
182
- await next();
183
- if (skip(ctx)) return;
184
- const responseTime = Date.now() - startTime;
185
- const result = formatFn(ctx, responseTime);
186
- if (typeof result === "string") logMethod(result);
187
- else logMethod("{method} {url} {status} - {responseTime} ms", result);
308
+ const requestContext = await buildRequestContext(ctx, contextOptions);
309
+ await withContext(requestContext, () => handleRequest(requestContext));
188
310
  };
189
311
  }
190
312
 
package/dist/mod.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mod.js","names":["ctx: KoaContext","responseTime: number","predefinedFormats: Record<PredefinedFormat, FormatFunction>","category: string | readonly string[]","options: KoaLogTapeOptions","formatFn: FormatFunction","next: () => Promise<void>","result"],"sources":["../src/mod.ts"],"sourcesContent":["import { getLogger, type LogLevel } from \"@logtape/logtape\";\n\nexport type { LogLevel } from \"@logtape/logtape\";\n\n/**\n * Minimal Koa Context interface for compatibility across Koa 2.x and 3.x.\n *\n * This interface includes common aliases available on the Koa context object.\n * See https://koajs.com/#context for the full API.\n *\n * @since 1.3.0\n */\nexport interface KoaContext {\n /** HTTP request method (alias for ctx.request.method) */\n method: string;\n /** Request URL (alias for ctx.request.url) */\n url: string;\n /** Request pathname (alias for ctx.request.path) */\n path: string;\n /** HTTP response status code (alias for ctx.response.status) */\n status: number;\n /** Remote client IP address (alias for ctx.request.ip) */\n ip: string;\n /** Koa Response object */\n response: {\n length?: number;\n };\n /**\n * Get a request header field value (case-insensitive).\n * @param field The header field name.\n * @returns The header value, or an empty string if not present.\n */\n get(field: string): string;\n}\n\n/**\n * Koa middleware function type.\n * @since 1.3.0\n */\nexport type KoaMiddleware = (\n ctx: KoaContext,\n next: () => Promise<void>,\n) => Promise<void>;\n\n/**\n * Predefined log format names compatible with Morgan.\n * @since 1.3.0\n */\nexport type PredefinedFormat = \"combined\" | \"common\" | \"dev\" | \"short\" | \"tiny\";\n\n/**\n * Custom format function for request logging.\n *\n * @param ctx The Koa context object.\n * @param responseTime The response time in milliseconds.\n * @returns A string message or an object with structured properties.\n * @since 1.3.0\n */\nexport type FormatFunction = (\n ctx: KoaContext,\n responseTime: number,\n) => string | Record<string, unknown>;\n\n/**\n * Structured log properties for HTTP requests.\n * @since 1.3.0\n */\nexport interface RequestLogProperties {\n /** HTTP request method */\n method: string;\n /** Request URL */\n url: string;\n /** Request path */\n path: string;\n /** HTTP response status code */\n status: number;\n /** Response time in milliseconds */\n responseTime: number;\n /** Response content-length */\n contentLength: number | undefined;\n /** Remote client address */\n remoteAddr: string | undefined;\n /** User-Agent header value */\n userAgent: string | undefined;\n /** Referrer header value */\n referrer: string | undefined;\n}\n\n/**\n * Options for configuring the Koa LogTape middleware.\n * @since 1.3.0\n */\nexport interface KoaLogTapeOptions {\n /**\n * The LogTape category to use for logging.\n * @default [\"koa\"]\n */\n readonly category?: string | readonly string[];\n\n /**\n * The log level to use for request logging.\n * @default \"info\"\n */\n readonly level?: LogLevel;\n\n /**\n * The format for log output.\n * Can be a predefined format name or a custom format function.\n *\n * Predefined formats:\n * - `\"combined\"` - Apache Combined Log Format (structured, default)\n * - `\"common\"` - Apache Common Log Format (structured, no referrer/userAgent)\n * - `\"dev\"` - Concise colored output for development (string)\n * - `\"short\"` - Shorter than common (string)\n * - `\"tiny\"` - Minimal output (string)\n *\n * @default \"combined\"\n */\n readonly format?: PredefinedFormat | FormatFunction;\n\n /**\n * Function to determine whether logging should be skipped.\n * Return `true` to skip logging for a request.\n *\n * @example Skip logging for health check endpoint\n * ```typescript\n * app.use(koaLogger({\n * skip: (ctx) => ctx.path === \"/health\",\n * }));\n * ```\n *\n * @default () => false\n */\n readonly skip?: (ctx: KoaContext) => boolean;\n\n /**\n * If `true`, logs are written immediately when the request is received.\n * If `false` (default), logs are written after the response is sent.\n *\n * Note: When `logRequest` is `true`, response-related properties\n * (status, responseTime, contentLength) will not be available.\n *\n * @default false\n */\n readonly logRequest?: boolean;\n}\n\n/**\n * Get referrer from request headers.\n * Returns undefined if the header is not present or empty.\n */\nfunction getReferrer(ctx: KoaContext): string | undefined {\n const referrer = ctx.get(\"referrer\") || ctx.get(\"referer\");\n return referrer !== \"\" ? referrer : undefined;\n}\n\n/**\n * Get user agent from request headers.\n * Returns undefined if the header is not present or empty.\n */\nfunction getUserAgent(ctx: KoaContext): string | undefined {\n const userAgent = ctx.get(\"user-agent\");\n return userAgent !== \"\" ? userAgent : undefined;\n}\n\n/**\n * Get remote address from context.\n * Returns undefined if not available.\n */\nfunction getRemoteAddr(ctx: KoaContext): string | undefined {\n return ctx.ip !== \"\" ? ctx.ip : undefined;\n}\n\n/**\n * Get content length from response.\n */\nfunction getContentLength(ctx: KoaContext): number | undefined {\n return ctx.response.length;\n}\n\n/**\n * Build structured log properties from context.\n */\nfunction buildProperties(\n ctx: KoaContext,\n responseTime: number,\n): RequestLogProperties {\n return {\n method: ctx.method,\n url: ctx.url,\n path: ctx.path,\n status: ctx.status,\n responseTime,\n contentLength: getContentLength(ctx),\n remoteAddr: getRemoteAddr(ctx),\n userAgent: getUserAgent(ctx),\n referrer: getReferrer(ctx),\n };\n}\n\n/**\n * Combined format (Apache Combined Log Format).\n * Returns all structured properties.\n */\nfunction formatCombined(\n ctx: KoaContext,\n responseTime: number,\n): Record<string, unknown> {\n return { ...buildProperties(ctx, responseTime) };\n}\n\n/**\n * Common format (Apache Common Log Format).\n * Like combined but without referrer and userAgent.\n */\nfunction formatCommon(\n ctx: KoaContext,\n responseTime: number,\n): Record<string, unknown> {\n const props = buildProperties(ctx, responseTime);\n const { referrer: _referrer, userAgent: _userAgent, ...rest } = props;\n return rest;\n}\n\n/**\n * Dev format (colored output for development).\n * :method :path :status :response-time ms - :res[content-length]\n */\nfunction formatDev(\n ctx: KoaContext,\n responseTime: number,\n): string {\n const contentLength = getContentLength(ctx) ?? \"-\";\n return `${ctx.method} ${ctx.path} ${ctx.status} ${\n responseTime.toFixed(3)\n } ms - ${contentLength}`;\n}\n\n/**\n * Short format.\n * :remote-addr :method :url :status :res[content-length] - :response-time ms\n */\nfunction formatShort(\n ctx: KoaContext,\n responseTime: number,\n): string {\n const remoteAddr = getRemoteAddr(ctx) ?? \"-\";\n const contentLength = getContentLength(ctx) ?? \"-\";\n return `${remoteAddr} ${ctx.method} ${ctx.url} ${ctx.status} ${contentLength} - ${\n responseTime.toFixed(3)\n } ms`;\n}\n\n/**\n * Tiny format (minimal output).\n * :method :path :status :res[content-length] - :response-time ms\n */\nfunction formatTiny(\n ctx: KoaContext,\n responseTime: number,\n): string {\n const contentLength = getContentLength(ctx) ?? \"-\";\n return `${ctx.method} ${ctx.path} ${ctx.status} ${contentLength} - ${\n responseTime.toFixed(3)\n } ms`;\n}\n\n/**\n * Map of predefined format functions.\n */\nconst predefinedFormats: Record<PredefinedFormat, FormatFunction> = {\n combined: formatCombined,\n common: formatCommon,\n dev: formatDev,\n short: formatShort,\n tiny: formatTiny,\n};\n\n/**\n * Normalize category to array format.\n */\nfunction normalizeCategory(\n category: string | readonly string[],\n): readonly string[] {\n return typeof category === \"string\" ? [category] : category;\n}\n\n/**\n * Creates Koa middleware for HTTP request logging using LogTape.\n *\n * This middleware provides Morgan-compatible request logging with LogTape\n * as the backend, supporting structured logging and customizable formats.\n * It serves as an alternative to koa-logger with structured logging support.\n *\n * @example Basic usage\n * ```typescript\n * import Koa from \"koa\";\n * import { configure, getConsoleSink } from \"@logtape/logtape\";\n * import { koaLogger } from \"@logtape/koa\";\n *\n * await configure({\n * sinks: { console: getConsoleSink() },\n * loggers: [\n * { category: [\"koa\"], sinks: [\"console\"], lowestLevel: \"info\" }\n * ],\n * });\n *\n * const app = new Koa();\n * app.use(koaLogger());\n *\n * app.use((ctx) => {\n * ctx.body = { hello: \"world\" };\n * });\n *\n * app.listen(3000);\n * ```\n *\n * @example With custom options\n * ```typescript\n * app.use(koaLogger({\n * category: [\"myapp\", \"http\"],\n * level: \"debug\",\n * format: \"dev\",\n * skip: (ctx) => ctx.path === \"/health\",\n * }));\n * ```\n *\n * @example With custom format function\n * ```typescript\n * app.use(koaLogger({\n * format: (ctx, responseTime) => ({\n * method: ctx.method,\n * path: ctx.path,\n * status: ctx.status,\n * duration: responseTime,\n * }),\n * }));\n * ```\n *\n * @param options Configuration options for the middleware.\n * @returns Koa middleware function.\n * @since 1.3.0\n */\nexport function koaLogger(\n options: KoaLogTapeOptions = {},\n): KoaMiddleware {\n const category = normalizeCategory(options.category ?? [\"koa\"]);\n const logger = getLogger(category);\n const level = options.level ?? \"info\";\n const formatOption = options.format ?? \"combined\";\n const skip = options.skip ?? (() => false);\n const logRequest = options.logRequest ?? false;\n\n // Resolve format function\n const formatFn: FormatFunction = typeof formatOption === \"string\"\n ? predefinedFormats[formatOption]\n : formatOption;\n\n const logMethod = logger[level].bind(logger);\n\n return async (ctx: KoaContext, next: () => Promise<void>): Promise<void> => {\n const startTime = Date.now();\n\n // For immediate logging, log when request arrives\n if (logRequest) {\n if (!skip(ctx)) {\n const result = formatFn(ctx, 0);\n if (typeof result === \"string\") {\n logMethod(result);\n } else {\n logMethod(\"{method} {url}\", result);\n }\n }\n await next();\n return;\n }\n\n // Log after response is sent\n await next();\n\n if (skip(ctx)) return;\n\n const responseTime = Date.now() - startTime;\n const result = formatFn(ctx, responseTime);\n\n if (typeof result === \"string\") {\n logMethod(result);\n } else {\n logMethod(\"{method} {url} {status} - {responseTime} ms\", result);\n }\n };\n}\n"],"mappings":";;;;;;;AAuJA,SAAS,YAAYA,KAAqC;CACxD,MAAM,WAAW,IAAI,IAAI,WAAW,IAAI,IAAI,IAAI,UAAU;AAC1D,QAAO,aAAa,KAAK;AAC1B;;;;;AAMD,SAAS,aAAaA,KAAqC;CACzD,MAAM,YAAY,IAAI,IAAI,aAAa;AACvC,QAAO,cAAc,KAAK;AAC3B;;;;;AAMD,SAAS,cAAcA,KAAqC;AAC1D,QAAO,IAAI,OAAO,KAAK,IAAI;AAC5B;;;;AAKD,SAAS,iBAAiBA,KAAqC;AAC7D,QAAO,IAAI,SAAS;AACrB;;;;AAKD,SAAS,gBACPA,KACAC,cACsB;AACtB,QAAO;EACL,QAAQ,IAAI;EACZ,KAAK,IAAI;EACT,MAAM,IAAI;EACV,QAAQ,IAAI;EACZ;EACA,eAAe,iBAAiB,IAAI;EACpC,YAAY,cAAc,IAAI;EAC9B,WAAW,aAAa,IAAI;EAC5B,UAAU,YAAY,IAAI;CAC3B;AACF;;;;;AAMD,SAAS,eACPD,KACAC,cACyB;AACzB,QAAO,EAAE,GAAG,gBAAgB,KAAK,aAAa,CAAE;AACjD;;;;;AAMD,SAAS,aACPD,KACAC,cACyB;CACzB,MAAM,QAAQ,gBAAgB,KAAK,aAAa;CAChD,MAAM,EAAE,UAAU,WAAW,WAAW,WAAY,GAAG,MAAM,GAAG;AAChE,QAAO;AACR;;;;;AAMD,SAAS,UACPD,KACAC,cACQ;CACR,MAAM,gBAAgB,iBAAiB,IAAI,IAAI;AAC/C,SAAQ,EAAE,IAAI,OAAO,GAAG,IAAI,KAAK,GAAG,IAAI,OAAO,GAC7C,aAAa,QAAQ,EAAE,CACxB,QAAQ,cAAc;AACxB;;;;;AAMD,S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EtC;AACD,SAAM,MAAM;AACZ;EACD;AAGD,QAAM,MAAM;AAEZ,MAAI,KAAK,IAAI,CAAE;EAEf,MAAM,eAAe,KAAK,KAAK,GAAG;EAClC,MAAM,SAAS,SAAS,KAAK,aAAa;AAE1C,aAAW,WAAW,SACpB,WAAU,OAAO;MAEjB,WAAU,+CAA+C,OAAO;CAEnE;AACF"}
1
+ {"version":3,"file":"mod.js","names":["options: boolean | RequestContextOptions | undefined","options: boolean | RequestIdOptions | undefined","value: string","ctx: KoaContext","options: RequestIdOptions","responseHeader","responseTime: number","resolvedRequestId: { property: string; value: string } | undefined","include: readonly RequestContextField[]","context: Record<string, unknown>","options: RequestContextOptions","result: string | Record<string, unknown>","predefinedFormats: Record<PredefinedFormat, FormatFunction>","category: string | readonly string[]","options: KoaLogTapeOptions","formatFn: FormatFunction","next: () => Promise<void>","requestContext: Record<string, unknown>","result","requestContext"],"sources":["../src/mod.ts"],"sourcesContent":["import { getLogger, type LogLevel, withContext } from \"@logtape/logtape\";\n\nexport type { LogLevel } from \"@logtape/logtape\";\n\n/**\n * Minimal Koa Context interface for compatibility across Koa 2.x and 3.x.\n *\n * This interface includes common aliases available on the Koa context object.\n * See https://koajs.com/#context for the full API.\n *\n * @since 1.3.0\n */\nexport interface KoaContext {\n /** HTTP request method (alias for ctx.request.method) */\n method: string;\n /** Request URL (alias for ctx.request.url) */\n url: string;\n /** Request pathname (alias for ctx.request.path) */\n path: string;\n /** HTTP response status code (alias for ctx.response.status) */\n status: number;\n /** Remote client IP address (alias for ctx.request.ip) */\n ip: string;\n /** Koa Response object */\n response: {\n length?: number;\n };\n /**\n * Get a request header field value (case-insensitive).\n * @param field The header field name.\n * @returns The header value, or an empty string if not present.\n */\n get(field: string): string;\n /**\n * Set a response header field value.\n * @param field The header field name.\n * @param value The header field value.\n */\n set?(field: string, value: string): void;\n}\n\n/**\n * Koa middleware function type.\n * @since 1.3.0\n */\nexport type KoaMiddleware = (\n ctx: KoaContext,\n next: () => Promise<void>,\n) => Promise<void>;\n\n/**\n * Predefined log format names compatible with Morgan.\n * @since 1.3.0\n */\nexport type PredefinedFormat = \"combined\" | \"common\" | \"dev\" | \"short\" | \"tiny\";\n\n/**\n * Custom format function for request logging.\n *\n * @param ctx The Koa context object.\n * @param responseTime The response time in milliseconds.\n * @returns A string message or an object with structured properties.\n * @since 1.3.0\n */\nexport type FormatFunction = (\n ctx: KoaContext,\n responseTime: number,\n) => string | Record<string, unknown>;\n\n/**\n * Structured log properties for HTTP requests.\n * @since 1.3.0\n */\nexport interface RequestLogProperties {\n /** HTTP request method */\n method: string;\n /** Request URL */\n url: string;\n /** Request path */\n path: string;\n /** HTTP response status code */\n status: number;\n /** Response time in milliseconds */\n responseTime: number;\n /** Response content-length */\n contentLength: number | undefined;\n /** Remote client address */\n remoteAddr: string | undefined;\n /** User-Agent header value */\n userAgent: string | undefined;\n /** Referrer header value */\n referrer: string | undefined;\n}\n\n/**\n * Request fields that can be added to the implicit request context.\n * @since 2.2.0\n */\nexport type RequestContextField =\n | \"requestId\"\n | \"method\"\n | \"url\"\n | \"path\"\n | \"userAgent\"\n | \"remoteAddr\"\n | \"referrer\";\n\n/**\n * Options for extracting, generating, and propagating a request ID.\n * @since 2.2.0\n */\nexport interface RequestIdOptions {\n /**\n * The property name used in implicit context and request log records.\n * @default \"requestId\"\n */\n readonly property?: string;\n\n /**\n * Incoming request headers to inspect in order.\n * @default [\"x-request-id\"]\n */\n readonly headerNames?: readonly string[];\n\n /**\n * Response header that receives the resolved request ID.\n * Set to `false` to disable response header propagation.\n * @default \"x-request-id\"\n */\n readonly responseHeader?: string | false;\n\n /**\n * Generates a request ID when no incoming header is present.\n * @default crypto.randomUUID()\n */\n readonly generate?: () => string;\n\n /**\n * Normalizes an incoming request ID. Return `null` to reject the value and\n * keep looking for another header or generate a new ID.\n */\n readonly normalize?: (value: string) => string | null;\n}\n\n/**\n * Options for request-scoped implicit context.\n * @since 2.2.0\n */\nexport interface RequestContextOptions {\n /**\n * Enables request ID extraction, generation, and response propagation.\n * @default true\n */\n readonly requestId?: boolean | RequestIdOptions;\n\n /**\n * Fields to add to the implicit context.\n * @default [\"requestId\"]\n */\n readonly include?: readonly RequestContextField[];\n\n /**\n * Adds application-specific fields to the implicit request context.\n */\n readonly enrich?: (\n ctx: KoaContext,\n ) => Record<string, unknown> | Promise<Record<string, unknown>>;\n}\n\n/**\n * Options for configuring the Koa LogTape middleware.\n * @since 1.3.0\n */\nexport interface KoaLogTapeOptions {\n /**\n * The LogTape category to use for logging.\n * @default [\"koa\"]\n */\n readonly category?: string | readonly string[];\n\n /**\n * The log level to use for request logging.\n * @default \"info\"\n */\n readonly level?: LogLevel;\n\n /**\n * The format for log output.\n * Can be a predefined format name or a custom format function.\n *\n * Predefined formats:\n * - `\"combined\"` - Apache Combined Log Format (structured, default)\n * - `\"common\"` - Apache Common Log Format (structured, no referrer/userAgent)\n * - `\"dev\"` - Concise colored output for development (string)\n * - `\"short\"` - Shorter than common (string)\n * - `\"tiny\"` - Minimal output (string)\n *\n * @default \"combined\"\n */\n readonly format?: PredefinedFormat | FormatFunction;\n\n /**\n * Function to determine whether logging should be skipped.\n * Return `true` to skip logging for a request.\n *\n * @example Skip logging for health check endpoint\n * ```typescript\n * app.use(koaLogger({\n * skip: (ctx) => ctx.path === \"/health\",\n * }));\n * ```\n *\n * @default () => false\n */\n readonly skip?: (ctx: KoaContext) => boolean;\n\n /**\n * If `true`, logs are written immediately when the request is received.\n * If `false` (default), logs are written after the response is sent.\n *\n * Note: When `logRequest` is `true`, response-related properties\n * (status, responseTime, contentLength) will not be available.\n *\n * @default false\n */\n readonly logRequest?: boolean;\n\n /**\n * Enables request-scoped implicit context and request ID correlation.\n *\n * When set to `true`, the middleware reads the `x-request-id` header,\n * generates one when it is absent, writes it to the `x-request-id` response\n * header, and adds `requestId` to all LogTape records emitted while handling\n * the request.\n *\n * @default false\n * @since 2.2.0\n */\n readonly context?: boolean | RequestContextOptions;\n}\n\nconst defaultRequestIdHeader = \"x-request-id\";\n\n/**\n * Normalize request context options.\n */\nfunction normalizeRequestContextOptions(\n options: boolean | RequestContextOptions | undefined,\n): RequestContextOptions | undefined {\n if (options === true) return {};\n if (options === false || options == null) return undefined;\n return options;\n}\n\n/**\n * Normalize request ID options.\n */\nfunction normalizeRequestIdOptions(\n options: boolean | RequestIdOptions | undefined,\n): RequestIdOptions | undefined {\n if (options === false) return undefined;\n if (options === true || options == null) return {};\n return options;\n}\n\n/**\n * Generate a request ID with Web Crypto when possible.\n */\nfunction generateRequestId(): string {\n if (typeof globalThis.crypto?.randomUUID === \"function\") {\n return globalThis.crypto.randomUUID();\n }\n return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;\n}\n\n/**\n * Normalize an incoming request ID.\n */\nfunction defaultNormalizeRequestId(value: string): string | null {\n const trimmed = value.trim();\n return trimmed === \"\" ? null : trimmed;\n}\n\n/**\n * Resolve the request ID for a request.\n */\nfunction resolveRequestId(\n ctx: KoaContext,\n options: RequestIdOptions,\n): { property: string; value: string } {\n const property = options.property ?? \"requestId\";\n const normalize = options.normalize ?? defaultNormalizeRequestId;\n const headerNames = options.headerNames ?? [defaultRequestIdHeader];\n for (const headerName of headerNames) {\n const headerValue = ctx.get(headerName);\n if (headerValue === \"\") continue;\n const normalized = normalize(headerValue);\n if (normalized != null) {\n const responseHeader = options.responseHeader ?? defaultRequestIdHeader;\n if (responseHeader !== false) ctx.set?.(responseHeader, normalized);\n return { property, value: normalized };\n }\n }\n const generated = (options.generate ?? generateRequestId)();\n const responseHeader = options.responseHeader ?? defaultRequestIdHeader;\n if (responseHeader !== false) ctx.set?.(responseHeader, generated);\n return { property, value: generated };\n}\n\n/**\n * Get referrer from request headers.\n * Returns undefined if the header is not present or empty.\n */\nfunction getReferrer(ctx: KoaContext): string | undefined {\n const referrer = ctx.get(\"referrer\") || ctx.get(\"referer\");\n return referrer !== \"\" ? referrer : undefined;\n}\n\n/**\n * Get user agent from request headers.\n * Returns undefined if the header is not present or empty.\n */\nfunction getUserAgent(ctx: KoaContext): string | undefined {\n const userAgent = ctx.get(\"user-agent\");\n return userAgent !== \"\" ? userAgent : undefined;\n}\n\n/**\n * Get remote address from context.\n * Returns undefined if not available.\n */\nfunction getRemoteAddr(ctx: KoaContext): string | undefined {\n return ctx.ip !== \"\" ? ctx.ip : undefined;\n}\n\n/**\n * Get content length from response.\n */\nfunction getContentLength(ctx: KoaContext): number | undefined {\n return ctx.response.length;\n}\n\n/**\n * Build structured log properties from context.\n */\nfunction buildProperties(\n ctx: KoaContext,\n responseTime: number,\n): RequestLogProperties {\n return {\n method: ctx.method,\n url: ctx.url,\n path: ctx.path,\n status: ctx.status,\n responseTime,\n contentLength: getContentLength(ctx),\n remoteAddr: getRemoteAddr(ctx),\n userAgent: getUserAgent(ctx),\n referrer: getReferrer(ctx),\n };\n}\n\n/**\n * Build request context fields from a request.\n */\nfunction buildIncludedContext(\n ctx: KoaContext,\n resolvedRequestId: { property: string; value: string } | undefined,\n include: readonly RequestContextField[],\n): Record<string, unknown> {\n const context: Record<string, unknown> = {};\n for (const field of include) {\n switch (field) {\n case \"requestId\":\n if (resolvedRequestId != null) {\n context[resolvedRequestId.property] = resolvedRequestId.value;\n }\n break;\n case \"method\":\n context.method = ctx.method;\n break;\n case \"url\":\n context.url = ctx.url;\n break;\n case \"path\":\n context.path = ctx.path;\n break;\n case \"userAgent\":\n context.userAgent = getUserAgent(ctx);\n break;\n case \"remoteAddr\":\n context.remoteAddr = getRemoteAddr(ctx);\n break;\n case \"referrer\":\n context.referrer = getReferrer(ctx);\n break;\n }\n }\n return context;\n}\n\n/**\n * Build the implicit context for a request.\n */\nasync function buildRequestContext(\n ctx: KoaContext,\n options: RequestContextOptions,\n): Promise<Record<string, unknown>> {\n const requestIdOptions = normalizeRequestIdOptions(options.requestId);\n const resolvedRequestId = requestIdOptions == null\n ? undefined\n : resolveRequestId(ctx, requestIdOptions);\n const include = options.include ??\n (resolvedRequestId == null ? [] : [\"requestId\"] as const);\n const context = buildIncludedContext(ctx, resolvedRequestId, include);\n if (options.enrich == null) return context;\n return {\n ...context,\n ...await options.enrich(ctx),\n };\n}\n\n/**\n * Add request context fields to a request log result.\n */\nfunction withRequestLogContext(\n result: string | Record<string, unknown>,\n context: Record<string, unknown>,\n): string | Record<string, unknown> {\n if (typeof result === \"string\") return result;\n return { ...result, ...context };\n}\n\n/**\n * Combined format (Apache Combined Log Format).\n * Returns all structured properties.\n */\nfunction formatCombined(\n ctx: KoaContext,\n responseTime: number,\n): Record<string, unknown> {\n return { ...buildProperties(ctx, responseTime) };\n}\n\n/**\n * Common format (Apache Common Log Format).\n * Like combined but without referrer and userAgent.\n */\nfunction formatCommon(\n ctx: KoaContext,\n responseTime: number,\n): Record<string, unknown> {\n const props = buildProperties(ctx, responseTime);\n const { referrer: _referrer, userAgent: _userAgent, ...rest } = props;\n return rest;\n}\n\n/**\n * Dev format (colored output for development).\n * :method :path :status :response-time ms - :res[content-length]\n */\nfunction formatDev(\n ctx: KoaContext,\n responseTime: number,\n): string {\n const contentLength = getContentLength(ctx) ?? \"-\";\n return `${ctx.method} ${ctx.path} ${ctx.status} ${\n responseTime.toFixed(3)\n } ms - ${contentLength}`;\n}\n\n/**\n * Short format.\n * :remote-addr :method :url :status :res[content-length] - :response-time ms\n */\nfunction formatShort(\n ctx: KoaContext,\n responseTime: number,\n): string {\n const remoteAddr = getRemoteAddr(ctx) ?? \"-\";\n const contentLength = getContentLength(ctx) ?? \"-\";\n return `${remoteAddr} ${ctx.method} ${ctx.url} ${ctx.status} ${contentLength} - ${\n responseTime.toFixed(3)\n } ms`;\n}\n\n/**\n * Tiny format (minimal output).\n * :method :path :status :res[content-length] - :response-time ms\n */\nfunction formatTiny(\n ctx: KoaContext,\n responseTime: number,\n): string {\n const contentLength = getContentLength(ctx) ?? \"-\";\n return `${ctx.method} ${ctx.path} ${ctx.status} ${contentLength} - ${\n responseTime.toFixed(3)\n } ms`;\n}\n\n/**\n * Map of predefined format functions.\n */\nconst predefinedFormats: Record<PredefinedFormat, FormatFunction> = {\n combined: formatCombined,\n common: formatCommon,\n dev: formatDev,\n short: formatShort,\n tiny: formatTiny,\n};\n\n/**\n * Normalize category to array format.\n */\nfunction normalizeCategory(\n category: string | readonly string[],\n): readonly string[] {\n return typeof category === \"string\" ? [category] : category;\n}\n\n/**\n * Creates Koa middleware for HTTP request logging using LogTape.\n *\n * This middleware provides Morgan-compatible request logging with LogTape\n * as the backend, supporting structured logging and customizable formats.\n * It serves as an alternative to koa-logger with structured logging support.\n *\n * @example Basic usage\n * ```typescript\n * import Koa from \"koa\";\n * import { configure, getConsoleSink } from \"@logtape/logtape\";\n * import { koaLogger } from \"@logtape/koa\";\n *\n * await configure({\n * sinks: { console: getConsoleSink() },\n * loggers: [\n * { category: [\"koa\"], sinks: [\"console\"], lowestLevel: \"info\" }\n * ],\n * });\n *\n * const app = new Koa();\n * app.use(koaLogger());\n *\n * app.use((ctx) => {\n * ctx.body = { hello: \"world\" };\n * });\n *\n * app.listen(3000);\n * ```\n *\n * @example With custom options\n * ```typescript\n * app.use(koaLogger({\n * category: [\"myapp\", \"http\"],\n * level: \"debug\",\n * format: \"dev\",\n * skip: (ctx) => ctx.path === \"/health\",\n * }));\n * ```\n *\n * @example With custom format function\n * ```typescript\n * app.use(koaLogger({\n * format: (ctx, responseTime) => ({\n * method: ctx.method,\n * path: ctx.path,\n * status: ctx.status,\n * duration: responseTime,\n * }),\n * }));\n * ```\n *\n * @param options Configuration options for the middleware.\n * @returns Koa middleware function.\n * @since 1.3.0\n */\nexport function koaLogger(\n options: KoaLogTapeOptions = {},\n): KoaMiddleware {\n const category = normalizeCategory(options.category ?? [\"koa\"]);\n const logger = getLogger(category);\n const level = options.level ?? \"info\";\n const formatOption = options.format ?? \"combined\";\n const skip = options.skip ?? (() => false);\n const logRequest = options.logRequest ?? false;\n const contextOptions = normalizeRequestContextOptions(options.context);\n\n // Resolve format function\n const formatFn: FormatFunction = typeof formatOption === \"string\"\n ? predefinedFormats[formatOption]\n : formatOption;\n\n const logMethod = logger[level].bind(logger);\n\n return async (ctx: KoaContext, next: () => Promise<void>): Promise<void> => {\n const startTime = Date.now();\n\n const handleRequest = async (\n requestContext: Record<string, unknown>,\n ): Promise<void> => {\n // For immediate logging, log when request arrives\n if (logRequest) {\n if (!skip(ctx)) {\n const result = withRequestLogContext(\n formatFn(ctx, 0),\n requestContext,\n );\n if (typeof result === \"string\") {\n logMethod(result, requestContext);\n } else {\n logMethod(\"{method} {url}\", result);\n }\n }\n await next();\n return;\n }\n\n // Log after response is sent\n await next();\n\n if (skip(ctx)) return;\n\n const responseTime = Date.now() - startTime;\n const result = withRequestLogContext(\n formatFn(ctx, responseTime),\n requestContext,\n );\n\n if (typeof result === \"string\") {\n logMethod(result, requestContext);\n } else {\n logMethod(\"{method} {url} {status} - {responseTime} ms\", result);\n }\n };\n\n if (contextOptions == null) {\n await handleRequest({});\n return;\n }\n\n const requestContext = await buildRequestContext(ctx, contextOptions);\n await withContext(requestContext, () => handleRequest(requestContext));\n };\n}\n"],"mappings":";;;AAiPA,MAAM,yBAAyB;;;;AAK/B,SAAS,+BACPA,SACmC;AACnC,KAAI,YAAY,KAAM,QAAO,CAAE;AAC/B,KAAI,YAAY,SAAS,WAAW,KAAM;AAC1C,QAAO;AACR;;;;AAKD,SAAS,0BACPC,SAC8B;AAC9B,KAAI,YAAY,MAAO;AACvB,KAAI,YAAY,QAAQ,WAAW,KAAM,QAAO,CAAE;AAClD,QAAO;AACR;;;;AAKD,SAAS,oBAA4B;AACnC,YAAW,WAAW,QAAQ,eAAe,WAC3C,QAAO,WAAW,OAAO,YAAY;AAEvC,SAAQ,EAAE,KAAK,KAAK,CAAC,SAAS,GAAG,CAAC,GAAG,KAAK,QAAQ,CAAC,SAAS,GAAG,CAAC,MAAM,EAAE,CAAC;AAC1E;;;;AAKD,SAAS,0BAA0BC,OAA8B;CAC/D,MAAM,UAAU,MAAM,MAAM;AAC5B,QAAO,YAAY,KAAK,OAAO;AAChC;;;;AAKD,SAA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AAY,KAAK,KAAK;EAE5B,MAAM,gBAAgB,OACpBC,qBACkB;AAElB,OAAI,YAAY;AACd,SAAK,KAAK,IAAI,EAAE;KACd,MAAMC,WAAS,sBACb,SAAS,KAAK,EAAE,EAChBC,iBACD;AACD,gBAAWD,aAAW,SACpB,WAAUA,UAAQC,iBAAe;SAEjC,WAAU,kBAAkBD,SAAO;IAEtC;AACD,UAAM,MAAM;AACZ;GACD;AAGD,SAAM,MAAM;AAEZ,OAAI,KAAK,IAAI,CAAE;GAEf,MAAM,eAAe,KAAK,KAAK,GAAG;GAClC,MAAM,SAAS,sBACb,SAAS,KAAK,aAAa,EAC3BC,iBACD;AAED,cAAW,WAAW,SACpB,WAAU,QAAQA,iBAAe;OAEjC,WAAU,+CAA+C,OAAO;EAEnE;AAED,MAAI,kBAAkB,MAAM;AAC1B,SAAM,cAAc,CAAE,EAAC;AACvB;EACD;EAED,MAAM,iBAAiB,MAAM,oBAAoB,KAAK,eAAe;AACrE,QAAM,YAAY,gBAAgB,MAAM,cAAc,eAAe,CAAC;CACvE;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logtape/koa",
3
- "version": "2.2.0-dev.685+1c03a9fb",
3
+ "version": "2.2.0-dev.686+61fa5e1a",
4
4
  "description": "Koa adapter for LogTape logging library",
5
5
  "keywords": [
6
6
  "logging",
@@ -52,7 +52,7 @@
52
52
  ],
53
53
  "peerDependencies": {
54
54
  "koa": "^2.0.0 || ^3.0.0",
55
- "@logtape/logtape": "^2.2.0-dev.685+1c03a9fb"
55
+ "@logtape/logtape": "^2.2.0-dev.686+61fa5e1a"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@alinea/suite": "^0.6.3",