@logtape/hono 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 +43 -0
- package/dist/mod.cjs +157 -11
- package/dist/mod.d.cts +70 -1
- package/dist/mod.d.cts.map +1 -1
- package/dist/mod.d.ts +70 -1
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +158 -12
- package/dist/mod.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -66,6 +66,49 @@ app.use(honoLogger({
|
|
|
66
66
|
format: "dev", // Predefined format (default: "combined")
|
|
67
67
|
skip: (c) => c.req.path === "/health", // Skip logging for specific paths
|
|
68
68
|
logRequest: true, // Log at request start (default: false)
|
|
69
|
+
context: true, // Add requestId to request-scoped logs
|
|
70
|
+
}));
|
|
71
|
+
~~~~
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
Request context
|
|
75
|
+
---------------
|
|
76
|
+
|
|
77
|
+
Set `context: true` to add request-scoped correlation fields. By default,
|
|
78
|
+
the middleware reads the `x-request-id` request header, generates an ID when
|
|
79
|
+
the header is missing, writes the resolved ID to the `x-request-id` response
|
|
80
|
+
header, and adds `requestId` to the request log record.
|
|
81
|
+
|
|
82
|
+
To make logs emitted by your route handlers inherit the same `requestId`, also
|
|
83
|
+
configure LogTape with `contextLocalStorage`:
|
|
84
|
+
|
|
85
|
+
~~~~ typescript
|
|
86
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
87
|
+
import { configure } from "@logtape/logtape";
|
|
88
|
+
|
|
89
|
+
await configure({
|
|
90
|
+
// ... sinks and loggers ...
|
|
91
|
+
contextLocalStorage: new AsyncLocalStorage(),
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
app.use(honoLogger({ context: true }));
|
|
95
|
+
~~~~
|
|
96
|
+
|
|
97
|
+
The context is still established when `skip` suppresses the request log, so
|
|
98
|
+
application logs inside the skipped request can keep the same request ID.
|
|
99
|
+
|
|
100
|
+
You can customize request ID headers and add more request fields:
|
|
101
|
+
|
|
102
|
+
~~~~ typescript
|
|
103
|
+
app.use(honoLogger({
|
|
104
|
+
context: {
|
|
105
|
+
requestId: {
|
|
106
|
+
headerNames: ["x-correlation-id", "x-request-id"],
|
|
107
|
+
responseHeader: "x-request-id",
|
|
108
|
+
},
|
|
109
|
+
include: ["requestId", "method", "path", "userAgent"],
|
|
110
|
+
enrich: (c) => ({ route: c.req.path }),
|
|
111
|
+
},
|
|
69
112
|
}));
|
|
70
113
|
~~~~
|
|
71
114
|
|
package/dist/mod.cjs
CHANGED
|
@@ -3,6 +3,65 @@ const __logtape_logtape = require_rolldown_runtime.__toESM(require("@logtape/log
|
|
|
3
3
|
const hono_factory = require_rolldown_runtime.__toESM(require("hono/factory"));
|
|
4
4
|
|
|
5
5
|
//#region src/mod.ts
|
|
6
|
+
const defaultRequestIdHeader = "x-request-id";
|
|
7
|
+
/**
|
|
8
|
+
* Normalize request context options.
|
|
9
|
+
*/
|
|
10
|
+
function normalizeRequestContextOptions(options) {
|
|
11
|
+
if (options === true) return {};
|
|
12
|
+
if (options === false || options == null) return void 0;
|
|
13
|
+
return options;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Normalize request ID options.
|
|
17
|
+
*/
|
|
18
|
+
function normalizeRequestIdOptions(options) {
|
|
19
|
+
if (options === false) return void 0;
|
|
20
|
+
if (options === true || options == null) return {};
|
|
21
|
+
return options;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Generate a request ID with Web Crypto when possible.
|
|
25
|
+
*/
|
|
26
|
+
function generateRequestId() {
|
|
27
|
+
if (typeof globalThis.crypto?.randomUUID === "function") return globalThis.crypto.randomUUID();
|
|
28
|
+
return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Normalize an incoming request ID.
|
|
32
|
+
*/
|
|
33
|
+
function defaultNormalizeRequestId(value) {
|
|
34
|
+
const trimmed = value.trim();
|
|
35
|
+
return trimmed === "" ? null : trimmed;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Resolve the request ID for a request.
|
|
39
|
+
*/
|
|
40
|
+
function resolveRequestId(c, options) {
|
|
41
|
+
const property = options.property ?? "requestId";
|
|
42
|
+
const normalize = options.normalize ?? defaultNormalizeRequestId;
|
|
43
|
+
const headerNames = options.headerNames ?? [defaultRequestIdHeader];
|
|
44
|
+
for (const headerName of headerNames) {
|
|
45
|
+
const headerValue = c.req.header(headerName);
|
|
46
|
+
if (headerValue == null) continue;
|
|
47
|
+
const normalized = normalize(headerValue);
|
|
48
|
+
if (normalized != null) {
|
|
49
|
+
const responseHeader$1 = options.responseHeader ?? defaultRequestIdHeader;
|
|
50
|
+
return {
|
|
51
|
+
property,
|
|
52
|
+
value: normalized,
|
|
53
|
+
responseHeader: responseHeader$1 === false ? void 0 : responseHeader$1
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const generated = (options.generate ?? generateRequestId)();
|
|
58
|
+
const responseHeader = options.responseHeader ?? defaultRequestIdHeader;
|
|
59
|
+
return {
|
|
60
|
+
property,
|
|
61
|
+
value: generated,
|
|
62
|
+
responseHeader: responseHeader === false ? void 0 : responseHeader
|
|
63
|
+
};
|
|
64
|
+
}
|
|
6
65
|
/**
|
|
7
66
|
* Get referrer from request headers.
|
|
8
67
|
*/
|
|
@@ -16,6 +75,15 @@ function getUserAgent(c) {
|
|
|
16
75
|
return c.req.header("user-agent");
|
|
17
76
|
}
|
|
18
77
|
/**
|
|
78
|
+
* Get remote address from X-Forwarded-For header.
|
|
79
|
+
*/
|
|
80
|
+
function getRemoteAddr(c) {
|
|
81
|
+
const forwarded = c.req.header("x-forwarded-for");
|
|
82
|
+
if (forwarded == null) return void 0;
|
|
83
|
+
const firstIp = forwarded.split(",")[0].trim();
|
|
84
|
+
return firstIp || void 0;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
19
87
|
* Get content length from response headers.
|
|
20
88
|
*/
|
|
21
89
|
function getContentLength(c) {
|
|
@@ -39,6 +107,71 @@ function buildProperties(c, responseTime) {
|
|
|
39
107
|
};
|
|
40
108
|
}
|
|
41
109
|
/**
|
|
110
|
+
* Build request context fields from a request.
|
|
111
|
+
*/
|
|
112
|
+
function buildIncludedContext(c, 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 = c.req.method;
|
|
120
|
+
break;
|
|
121
|
+
case "url":
|
|
122
|
+
context.url = c.req.url;
|
|
123
|
+
break;
|
|
124
|
+
case "path":
|
|
125
|
+
context.path = c.req.path;
|
|
126
|
+
break;
|
|
127
|
+
case "userAgent":
|
|
128
|
+
context.userAgent = getUserAgent(c);
|
|
129
|
+
break;
|
|
130
|
+
case "remoteAddr":
|
|
131
|
+
context.remoteAddr = getRemoteAddr(c);
|
|
132
|
+
break;
|
|
133
|
+
case "referrer":
|
|
134
|
+
context.referrer = getReferrer(c);
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
return context;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Build the implicit context for a request.
|
|
141
|
+
*/
|
|
142
|
+
async function buildRequestContext(c, options) {
|
|
143
|
+
const requestIdOptions = normalizeRequestIdOptions(options.requestId);
|
|
144
|
+
const resolvedRequestId = requestIdOptions == null ? void 0 : resolveRequestId(c, requestIdOptions);
|
|
145
|
+
const include = options.include ?? (resolvedRequestId == null ? [] : ["requestId"]);
|
|
146
|
+
const context = buildIncludedContext(c, resolvedRequestId, include);
|
|
147
|
+
if (options.enrich != null) Object.assign(context, await options.enrich(c));
|
|
148
|
+
const responseHeader = resolvedRequestId?.responseHeader == null ? void 0 : {
|
|
149
|
+
name: resolvedRequestId.responseHeader,
|
|
150
|
+
value: resolvedRequestId.value
|
|
151
|
+
};
|
|
152
|
+
return {
|
|
153
|
+
context,
|
|
154
|
+
responseHeader
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Apply deferred context response headers to the final Hono response.
|
|
159
|
+
*/
|
|
160
|
+
function applyResponseHeaders(c, requestContext) {
|
|
161
|
+
if (requestContext.responseHeader == null) return;
|
|
162
|
+
c.header(requestContext.responseHeader.name, requestContext.responseHeader.value);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Add request context fields to a request log result.
|
|
166
|
+
*/
|
|
167
|
+
function withRequestLogContext(result, context) {
|
|
168
|
+
if (typeof result === "string") return result;
|
|
169
|
+
return {
|
|
170
|
+
...result,
|
|
171
|
+
...context
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
42
175
|
* Combined format (Apache Combined Log Format).
|
|
43
176
|
* Returns all structured properties.
|
|
44
177
|
*/
|
|
@@ -154,25 +287,38 @@ function honoLogger(options = {}) {
|
|
|
154
287
|
const formatOption = options.format ?? "combined";
|
|
155
288
|
const skip = options.skip ?? (() => false);
|
|
156
289
|
const logRequest = options.logRequest ?? false;
|
|
290
|
+
const contextOptions = normalizeRequestContextOptions(options.context);
|
|
157
291
|
const formatFn = typeof formatOption === "string" ? predefinedFormats[formatOption] : formatOption;
|
|
158
292
|
const logMethod = logger[level].bind(logger);
|
|
159
293
|
return (0, hono_factory.createMiddleware)(async (c, next) => {
|
|
160
294
|
const startTime = Date.now();
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
295
|
+
const honoContext = c;
|
|
296
|
+
const handleRequest = async (requestContextState$1) => {
|
|
297
|
+
const requestContext = requestContextState$1.context;
|
|
298
|
+
if (logRequest) {
|
|
299
|
+
if (!skip(honoContext)) {
|
|
300
|
+
const result$1 = withRequestLogContext(formatFn(honoContext, 0), requestContext);
|
|
301
|
+
if (typeof result$1 === "string") logMethod(result$1, requestContext);
|
|
302
|
+
else logMethod("{method} {url}", result$1);
|
|
303
|
+
}
|
|
304
|
+
await next();
|
|
305
|
+
applyResponseHeaders(honoContext, requestContextState$1);
|
|
306
|
+
return;
|
|
166
307
|
}
|
|
167
308
|
await next();
|
|
309
|
+
applyResponseHeaders(honoContext, requestContextState$1);
|
|
310
|
+
if (skip(honoContext)) return;
|
|
311
|
+
const responseTime = Date.now() - startTime;
|
|
312
|
+
const result = withRequestLogContext(formatFn(honoContext, responseTime), requestContext);
|
|
313
|
+
if (typeof result === "string") logMethod(result, requestContext);
|
|
314
|
+
else logMethod("{method} {url} {status} - {responseTime} ms", result);
|
|
315
|
+
};
|
|
316
|
+
if (contextOptions == null) {
|
|
317
|
+
await handleRequest({ context: {} });
|
|
168
318
|
return;
|
|
169
319
|
}
|
|
170
|
-
await
|
|
171
|
-
|
|
172
|
-
const responseTime = Date.now() - startTime;
|
|
173
|
-
const result = formatFn(c, responseTime);
|
|
174
|
-
if (typeof result === "string") logMethod(result);
|
|
175
|
-
else logMethod("{method} {url} {status} - {responseTime} ms", result);
|
|
320
|
+
const requestContextState = await buildRequestContext(honoContext, contextOptions);
|
|
321
|
+
await (0, __logtape_logtape.withContext)(requestContextState.context, () => handleRequest(requestContextState));
|
|
176
322
|
});
|
|
177
323
|
}
|
|
178
324
|
|
package/dist/mod.d.cts
CHANGED
|
@@ -48,6 +48,63 @@ interface RequestLogProperties {
|
|
|
48
48
|
/** Referrer header value */
|
|
49
49
|
referrer: string | undefined;
|
|
50
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Request fields that can be added to the implicit request context.
|
|
53
|
+
* @since 2.2.0
|
|
54
|
+
*/
|
|
55
|
+
type RequestContextField = "requestId" | "method" | "url" | "path" | "userAgent" | "remoteAddr" | "referrer";
|
|
56
|
+
/**
|
|
57
|
+
* Options for extracting, generating, and propagating a request ID.
|
|
58
|
+
* @since 2.2.0
|
|
59
|
+
*/
|
|
60
|
+
interface RequestIdOptions {
|
|
61
|
+
/**
|
|
62
|
+
* The property name used in implicit context and request log records.
|
|
63
|
+
* @default "requestId"
|
|
64
|
+
*/
|
|
65
|
+
readonly property?: string;
|
|
66
|
+
/**
|
|
67
|
+
* Incoming request headers to inspect in order.
|
|
68
|
+
* @default ["x-request-id"]
|
|
69
|
+
*/
|
|
70
|
+
readonly headerNames?: readonly string[];
|
|
71
|
+
/**
|
|
72
|
+
* Response header that receives the resolved request ID.
|
|
73
|
+
* Set to `false` to disable response header propagation.
|
|
74
|
+
* @default "x-request-id"
|
|
75
|
+
*/
|
|
76
|
+
readonly responseHeader?: string | false;
|
|
77
|
+
/**
|
|
78
|
+
* Generates a request ID when no incoming header is present.
|
|
79
|
+
* @default crypto.randomUUID()
|
|
80
|
+
*/
|
|
81
|
+
readonly generate?: () => string;
|
|
82
|
+
/**
|
|
83
|
+
* Normalizes an incoming request ID. Return `null` to reject the value and
|
|
84
|
+
* keep looking for another header or generate a new ID.
|
|
85
|
+
*/
|
|
86
|
+
readonly normalize?: (value: string) => string | null;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Options for request-scoped implicit context.
|
|
90
|
+
* @since 2.2.0
|
|
91
|
+
*/
|
|
92
|
+
interface RequestContextOptions {
|
|
93
|
+
/**
|
|
94
|
+
* Enables request ID extraction, generation, and response propagation.
|
|
95
|
+
* @default true
|
|
96
|
+
*/
|
|
97
|
+
readonly requestId?: boolean | RequestIdOptions;
|
|
98
|
+
/**
|
|
99
|
+
* Fields to add to the implicit context.
|
|
100
|
+
* @default ["requestId"]
|
|
101
|
+
*/
|
|
102
|
+
readonly include?: readonly RequestContextField[];
|
|
103
|
+
/**
|
|
104
|
+
* Adds application-specific fields to the implicit request context.
|
|
105
|
+
*/
|
|
106
|
+
readonly enrich?: (c: HonoContext) => Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
107
|
+
}
|
|
51
108
|
/**
|
|
52
109
|
* Options for configuring the Hono LogTape middleware.
|
|
53
110
|
* @since 1.3.0
|
|
@@ -101,6 +158,18 @@ interface HonoLogTapeOptions {
|
|
|
101
158
|
* @default false
|
|
102
159
|
*/
|
|
103
160
|
readonly logRequest?: boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Enables request-scoped implicit context and request ID correlation.
|
|
163
|
+
*
|
|
164
|
+
* When set to `true`, the middleware reads the `x-request-id` header,
|
|
165
|
+
* generates one when it is absent, writes it to the `x-request-id` response
|
|
166
|
+
* header, and adds `requestId` to all LogTape records emitted while handling
|
|
167
|
+
* the request.
|
|
168
|
+
*
|
|
169
|
+
* @default false
|
|
170
|
+
* @since 2.2.0
|
|
171
|
+
*/
|
|
172
|
+
readonly context?: boolean | RequestContextOptions;
|
|
104
173
|
}
|
|
105
174
|
/**
|
|
106
175
|
* Creates Hono middleware for HTTP request logging using LogTape.
|
|
@@ -158,5 +227,5 @@ interface HonoLogTapeOptions {
|
|
|
158
227
|
declare function honoLogger(options?: HonoLogTapeOptions): MiddlewareHandler;
|
|
159
228
|
//# sourceMappingURL=mod.d.ts.map
|
|
160
229
|
//#endregion
|
|
161
|
-
export { FormatFunction, HonoContext, HonoLogTapeOptions, LogLevel, PredefinedFormat, RequestLogProperties, honoLogger };
|
|
230
|
+
export { FormatFunction, HonoContext, HonoLogTapeOptions, LogLevel, PredefinedFormat, RequestContextField, RequestContextOptions, RequestIdOptions, RequestLogProperties, honoLogger };
|
|
162
231
|
//# sourceMappingURL=mod.d.cts.map
|
package/dist/mod.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.cts","names":[],"sources":["../src/mod.ts"],"sourcesContent":[],"mappings":";;;;;;AAeA;AAMA;AAUA;;;;AAGoB;AAMH,UAzBA,WAAA,SAAoB,OAyBA,CAAA,GAAA,EAAA,GAAA,EAAA,GAAA,CAAA,CAAA,CAuBrC
|
|
1
|
+
{"version":3,"file":"mod.d.cts","names":[],"sources":["../src/mod.ts"],"sourcesContent":[],"mappings":";;;;;;AAeA;AAMA;AAUA;;;;AAGoB;AAMH,UAzBA,WAAA,SAAoB,OAyBA,CAAA,GAAA,EAAA,GAAA,EAAA,GAAA,CAAA,CAAA,CAuBrC;AAaA;AAqCA;;;AAW8B,KAvGlB,gBAAA,GAuGkB,UAAA,GAAA,QAAA,GAAA,KAAA,GAAA,OAAA,GAAA,MAAA;;;;;AAOU;AAOxC;;;AA0BoB,KArIR,cAAA,GAqIQ,CAAA,CAAA,EApIf,WAoIe,EAAA,YAAA,EAAA,MAAA,EAAA,GAAA,MAAA,GAlIN,MAkIM,CAAA,MAAA,EAAA,OAAA,CAAA;;;;AAuCgC;AAkXpC,UArhBC,oBAAA,CAqhBS;EAAA;EAAA,MACf,EAAA,MAAA;EAAuB;EACd,GAAA,EAAA,MAAA;;;;;;;;;;;;;;;;;;KAhgBR,mBAAA;;;;;UAaK,gBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAqCA,qBAAA;;;;;iCAKgB;;;;;8BAMH;;;;wBAMvB,gBACA,0BAA0B,QAAQ;;;;;;UAOxB,kBAAA;;;;;;;;;;mBAWE;;;;;;;;;;;;;;oBAeC,mBAAmB;;;;;;;;;;;;;;sBAejB;;;;;;;;;;;;;;;;;;;;;;+BAwBS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkXf,UAAA,WACL,qBACR"}
|
package/dist/mod.d.ts
CHANGED
|
@@ -48,6 +48,63 @@ interface RequestLogProperties {
|
|
|
48
48
|
/** Referrer header value */
|
|
49
49
|
referrer: string | undefined;
|
|
50
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Request fields that can be added to the implicit request context.
|
|
53
|
+
* @since 2.2.0
|
|
54
|
+
*/
|
|
55
|
+
type RequestContextField = "requestId" | "method" | "url" | "path" | "userAgent" | "remoteAddr" | "referrer";
|
|
56
|
+
/**
|
|
57
|
+
* Options for extracting, generating, and propagating a request ID.
|
|
58
|
+
* @since 2.2.0
|
|
59
|
+
*/
|
|
60
|
+
interface RequestIdOptions {
|
|
61
|
+
/**
|
|
62
|
+
* The property name used in implicit context and request log records.
|
|
63
|
+
* @default "requestId"
|
|
64
|
+
*/
|
|
65
|
+
readonly property?: string;
|
|
66
|
+
/**
|
|
67
|
+
* Incoming request headers to inspect in order.
|
|
68
|
+
* @default ["x-request-id"]
|
|
69
|
+
*/
|
|
70
|
+
readonly headerNames?: readonly string[];
|
|
71
|
+
/**
|
|
72
|
+
* Response header that receives the resolved request ID.
|
|
73
|
+
* Set to `false` to disable response header propagation.
|
|
74
|
+
* @default "x-request-id"
|
|
75
|
+
*/
|
|
76
|
+
readonly responseHeader?: string | false;
|
|
77
|
+
/**
|
|
78
|
+
* Generates a request ID when no incoming header is present.
|
|
79
|
+
* @default crypto.randomUUID()
|
|
80
|
+
*/
|
|
81
|
+
readonly generate?: () => string;
|
|
82
|
+
/**
|
|
83
|
+
* Normalizes an incoming request ID. Return `null` to reject the value and
|
|
84
|
+
* keep looking for another header or generate a new ID.
|
|
85
|
+
*/
|
|
86
|
+
readonly normalize?: (value: string) => string | null;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Options for request-scoped implicit context.
|
|
90
|
+
* @since 2.2.0
|
|
91
|
+
*/
|
|
92
|
+
interface RequestContextOptions {
|
|
93
|
+
/**
|
|
94
|
+
* Enables request ID extraction, generation, and response propagation.
|
|
95
|
+
* @default true
|
|
96
|
+
*/
|
|
97
|
+
readonly requestId?: boolean | RequestIdOptions;
|
|
98
|
+
/**
|
|
99
|
+
* Fields to add to the implicit context.
|
|
100
|
+
* @default ["requestId"]
|
|
101
|
+
*/
|
|
102
|
+
readonly include?: readonly RequestContextField[];
|
|
103
|
+
/**
|
|
104
|
+
* Adds application-specific fields to the implicit request context.
|
|
105
|
+
*/
|
|
106
|
+
readonly enrich?: (c: HonoContext) => Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
107
|
+
}
|
|
51
108
|
/**
|
|
52
109
|
* Options for configuring the Hono LogTape middleware.
|
|
53
110
|
* @since 1.3.0
|
|
@@ -101,6 +158,18 @@ interface HonoLogTapeOptions {
|
|
|
101
158
|
* @default false
|
|
102
159
|
*/
|
|
103
160
|
readonly logRequest?: boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Enables request-scoped implicit context and request ID correlation.
|
|
163
|
+
*
|
|
164
|
+
* When set to `true`, the middleware reads the `x-request-id` header,
|
|
165
|
+
* generates one when it is absent, writes it to the `x-request-id` response
|
|
166
|
+
* header, and adds `requestId` to all LogTape records emitted while handling
|
|
167
|
+
* the request.
|
|
168
|
+
*
|
|
169
|
+
* @default false
|
|
170
|
+
* @since 2.2.0
|
|
171
|
+
*/
|
|
172
|
+
readonly context?: boolean | RequestContextOptions;
|
|
104
173
|
}
|
|
105
174
|
/**
|
|
106
175
|
* Creates Hono middleware for HTTP request logging using LogTape.
|
|
@@ -158,5 +227,5 @@ interface HonoLogTapeOptions {
|
|
|
158
227
|
declare function honoLogger(options?: HonoLogTapeOptions): MiddlewareHandler;
|
|
159
228
|
//# sourceMappingURL=mod.d.ts.map
|
|
160
229
|
//#endregion
|
|
161
|
-
export { FormatFunction, HonoContext, HonoLogTapeOptions, LogLevel, PredefinedFormat, RequestLogProperties, honoLogger };
|
|
230
|
+
export { FormatFunction, HonoContext, HonoLogTapeOptions, LogLevel, PredefinedFormat, RequestContextField, RequestContextOptions, RequestIdOptions, RequestLogProperties, honoLogger };
|
|
162
231
|
//# 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":";;;;;;AAeA;AAMA;AAUA;;;;AAGoB;AAMH,UAzBA,WAAA,SAAoB,OAyBA,CAAA,GAAA,EAAA,GAAA,EAAA,GAAA,CAAA,CAAA,CAuBrC
|
|
1
|
+
{"version":3,"file":"mod.d.ts","names":[],"sources":["../src/mod.ts"],"sourcesContent":[],"mappings":";;;;;;AAeA;AAMA;AAUA;;;;AAGoB;AAMH,UAzBA,WAAA,SAAoB,OAyBA,CAAA,GAAA,EAAA,GAAA,EAAA,GAAA,CAAA,CAAA,CAuBrC;AAaA;AAqCA;;;AAW8B,KAvGlB,gBAAA,GAuGkB,UAAA,GAAA,QAAA,GAAA,KAAA,GAAA,OAAA,GAAA,MAAA;;;;;AAOU;AAOxC;;;AA0BoB,KArIR,cAAA,GAqIQ,CAAA,CAAA,EApIf,WAoIe,EAAA,YAAA,EAAA,MAAA,EAAA,GAAA,MAAA,GAlIN,MAkIM,CAAA,MAAA,EAAA,OAAA,CAAA;;;;AAuCgC;AAkXpC,UArhBC,oBAAA,CAqhBS;EAAA;EAAA,MACf,EAAA,MAAA;EAAuB;EACd,GAAA,EAAA,MAAA;;;;;;;;;;;;;;;;;;KAhgBR,mBAAA;;;;;UAaK,gBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAqCA,qBAAA;;;;;iCAKgB;;;;;8BAMH;;;;wBAMvB,gBACA,0BAA0B,QAAQ;;;;;;UAOxB,kBAAA;;;;;;;;;;mBAWE;;;;;;;;;;;;;;oBAeC,mBAAmB;;;;;;;;;;;;;;sBAejB;;;;;;;;;;;;;;;;;;;;;;+BAwBS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkXf,UAAA,WACL,qBACR"}
|
package/dist/mod.js
CHANGED
|
@@ -1,7 +1,66 @@
|
|
|
1
|
-
import { getLogger } from "@logtape/logtape";
|
|
1
|
+
import { getLogger, withContext } from "@logtape/logtape";
|
|
2
2
|
import { createMiddleware } from "hono/factory";
|
|
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(c, 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 = c.req.header(headerName);
|
|
45
|
+
if (headerValue == null) continue;
|
|
46
|
+
const normalized = normalize(headerValue);
|
|
47
|
+
if (normalized != null) {
|
|
48
|
+
const responseHeader$1 = options.responseHeader ?? defaultRequestIdHeader;
|
|
49
|
+
return {
|
|
50
|
+
property,
|
|
51
|
+
value: normalized,
|
|
52
|
+
responseHeader: responseHeader$1 === false ? void 0 : responseHeader$1
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const generated = (options.generate ?? generateRequestId)();
|
|
57
|
+
const responseHeader = options.responseHeader ?? defaultRequestIdHeader;
|
|
58
|
+
return {
|
|
59
|
+
property,
|
|
60
|
+
value: generated,
|
|
61
|
+
responseHeader: responseHeader === false ? void 0 : responseHeader
|
|
62
|
+
};
|
|
63
|
+
}
|
|
5
64
|
/**
|
|
6
65
|
* Get referrer from request headers.
|
|
7
66
|
*/
|
|
@@ -15,6 +74,15 @@ function getUserAgent(c) {
|
|
|
15
74
|
return c.req.header("user-agent");
|
|
16
75
|
}
|
|
17
76
|
/**
|
|
77
|
+
* Get remote address from X-Forwarded-For header.
|
|
78
|
+
*/
|
|
79
|
+
function getRemoteAddr(c) {
|
|
80
|
+
const forwarded = c.req.header("x-forwarded-for");
|
|
81
|
+
if (forwarded == null) return void 0;
|
|
82
|
+
const firstIp = forwarded.split(",")[0].trim();
|
|
83
|
+
return firstIp || void 0;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
18
86
|
* Get content length from response headers.
|
|
19
87
|
*/
|
|
20
88
|
function getContentLength(c) {
|
|
@@ -38,6 +106,71 @@ function buildProperties(c, responseTime) {
|
|
|
38
106
|
};
|
|
39
107
|
}
|
|
40
108
|
/**
|
|
109
|
+
* Build request context fields from a request.
|
|
110
|
+
*/
|
|
111
|
+
function buildIncludedContext(c, 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 = c.req.method;
|
|
119
|
+
break;
|
|
120
|
+
case "url":
|
|
121
|
+
context.url = c.req.url;
|
|
122
|
+
break;
|
|
123
|
+
case "path":
|
|
124
|
+
context.path = c.req.path;
|
|
125
|
+
break;
|
|
126
|
+
case "userAgent":
|
|
127
|
+
context.userAgent = getUserAgent(c);
|
|
128
|
+
break;
|
|
129
|
+
case "remoteAddr":
|
|
130
|
+
context.remoteAddr = getRemoteAddr(c);
|
|
131
|
+
break;
|
|
132
|
+
case "referrer":
|
|
133
|
+
context.referrer = getReferrer(c);
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
return context;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Build the implicit context for a request.
|
|
140
|
+
*/
|
|
141
|
+
async function buildRequestContext(c, options) {
|
|
142
|
+
const requestIdOptions = normalizeRequestIdOptions(options.requestId);
|
|
143
|
+
const resolvedRequestId = requestIdOptions == null ? void 0 : resolveRequestId(c, requestIdOptions);
|
|
144
|
+
const include = options.include ?? (resolvedRequestId == null ? [] : ["requestId"]);
|
|
145
|
+
const context = buildIncludedContext(c, resolvedRequestId, include);
|
|
146
|
+
if (options.enrich != null) Object.assign(context, await options.enrich(c));
|
|
147
|
+
const responseHeader = resolvedRequestId?.responseHeader == null ? void 0 : {
|
|
148
|
+
name: resolvedRequestId.responseHeader,
|
|
149
|
+
value: resolvedRequestId.value
|
|
150
|
+
};
|
|
151
|
+
return {
|
|
152
|
+
context,
|
|
153
|
+
responseHeader
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Apply deferred context response headers to the final Hono response.
|
|
158
|
+
*/
|
|
159
|
+
function applyResponseHeaders(c, requestContext) {
|
|
160
|
+
if (requestContext.responseHeader == null) return;
|
|
161
|
+
c.header(requestContext.responseHeader.name, requestContext.responseHeader.value);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Add request context fields to a request log result.
|
|
165
|
+
*/
|
|
166
|
+
function withRequestLogContext(result, context) {
|
|
167
|
+
if (typeof result === "string") return result;
|
|
168
|
+
return {
|
|
169
|
+
...result,
|
|
170
|
+
...context
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
41
174
|
* Combined format (Apache Combined Log Format).
|
|
42
175
|
* Returns all structured properties.
|
|
43
176
|
*/
|
|
@@ -153,25 +286,38 @@ function honoLogger(options = {}) {
|
|
|
153
286
|
const formatOption = options.format ?? "combined";
|
|
154
287
|
const skip = options.skip ?? (() => false);
|
|
155
288
|
const logRequest = options.logRequest ?? false;
|
|
289
|
+
const contextOptions = normalizeRequestContextOptions(options.context);
|
|
156
290
|
const formatFn = typeof formatOption === "string" ? predefinedFormats[formatOption] : formatOption;
|
|
157
291
|
const logMethod = logger[level].bind(logger);
|
|
158
292
|
return createMiddleware(async (c, next) => {
|
|
159
293
|
const startTime = Date.now();
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
294
|
+
const honoContext = c;
|
|
295
|
+
const handleRequest = async (requestContextState$1) => {
|
|
296
|
+
const requestContext = requestContextState$1.context;
|
|
297
|
+
if (logRequest) {
|
|
298
|
+
if (!skip(honoContext)) {
|
|
299
|
+
const result$1 = withRequestLogContext(formatFn(honoContext, 0), requestContext);
|
|
300
|
+
if (typeof result$1 === "string") logMethod(result$1, requestContext);
|
|
301
|
+
else logMethod("{method} {url}", result$1);
|
|
302
|
+
}
|
|
303
|
+
await next();
|
|
304
|
+
applyResponseHeaders(honoContext, requestContextState$1);
|
|
305
|
+
return;
|
|
165
306
|
}
|
|
166
307
|
await next();
|
|
308
|
+
applyResponseHeaders(honoContext, requestContextState$1);
|
|
309
|
+
if (skip(honoContext)) return;
|
|
310
|
+
const responseTime = Date.now() - startTime;
|
|
311
|
+
const result = withRequestLogContext(formatFn(honoContext, responseTime), requestContext);
|
|
312
|
+
if (typeof result === "string") logMethod(result, requestContext);
|
|
313
|
+
else logMethod("{method} {url} {status} - {responseTime} ms", result);
|
|
314
|
+
};
|
|
315
|
+
if (contextOptions == null) {
|
|
316
|
+
await handleRequest({ context: {} });
|
|
167
317
|
return;
|
|
168
318
|
}
|
|
169
|
-
await
|
|
170
|
-
|
|
171
|
-
const responseTime = Date.now() - startTime;
|
|
172
|
-
const result = formatFn(c, responseTime);
|
|
173
|
-
if (typeof result === "string") logMethod(result);
|
|
174
|
-
else logMethod("{method} {url} {status} - {responseTime} ms", result);
|
|
319
|
+
const requestContextState = await buildRequestContext(honoContext, contextOptions);
|
|
320
|
+
await withContext(requestContextState.context, () => handleRequest(requestContextState));
|
|
175
321
|
});
|
|
176
322
|
}
|
|
177
323
|
|
package/dist/mod.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","names":["c: HonoContext","responseTime: number","predefinedFormats: Record<PredefinedFormat, FormatFunction>","category: string | readonly string[]","options: HonoLogTapeOptions","formatFn: FormatFunction","result"],"sources":["../src/mod.ts"],"sourcesContent":["import { getLogger, type LogLevel } from \"@logtape/logtape\";\nimport { createMiddleware } from \"hono/factory\";\nimport type { Context, MiddlewareHandler } from \"hono\";\n\nexport type { LogLevel } from \"@logtape/logtape\";\n\n/**\n * Hono context interface exposed to custom formatters and skip callbacks.\n *\n * This matches the actual runtime object passed to the middleware, so custom\n * formatters can access context variables via methods like `c.get()` when\n * needed.\n * @since 1.3.0\n */\n// deno-lint-ignore no-explicit-any\nexport interface HonoContext extends Context<any, any, any> {}\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 c The Hono 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 c: HonoContext,\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 header value */\n contentLength: 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 Hono LogTape middleware.\n * @since 1.3.0\n */\nexport interface HonoLogTapeOptions {\n /**\n * The LogTape category to use for logging.\n * @default [\"hono\"]\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(honoLogger({\n * skip: (c) => c.req.path === \"/health\",\n * }));\n * ```\n *\n * @default () => false\n */\n readonly skip?: (c: HonoContext) => 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 */\nfunction getReferrer(c: HonoContext): string | undefined {\n return c.req.header(\"referrer\") || c.req.header(\"referer\");\n}\n\n/**\n * Get user agent from request headers.\n */\nfunction getUserAgent(c: HonoContext): string | undefined {\n return c.req.header(\"user-agent\");\n}\n\n/**\n * Get content length from response headers.\n */\nfunction getContentLength(c: HonoContext): string | undefined {\n const contentLength = c.res.headers.get(\"content-length\");\n if (contentLength === null) return undefined;\n return contentLength;\n}\n\n/**\n * Build structured log properties from context.\n */\nfunction buildProperties(\n c: HonoContext,\n responseTime: number,\n): RequestLogProperties {\n return {\n method: c.req.method,\n url: c.req.url,\n path: c.req.path,\n status: c.res.status,\n responseTime,\n contentLength: getContentLength(c),\n userAgent: getUserAgent(c),\n referrer: getReferrer(c),\n };\n}\n\n/**\n * Combined format (Apache Combined Log Format).\n * Returns all structured properties.\n */\nfunction formatCombined(\n c: HonoContext,\n responseTime: number,\n): Record<string, unknown> {\n return { ...buildProperties(c, responseTime) };\n}\n\n/**\n * Common format (Apache Common Log Format).\n * Like combined but without referrer and userAgent.\n */\nfunction formatCommon(\n c: HonoContext,\n responseTime: number,\n): Record<string, unknown> {\n const props = buildProperties(c, 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 c: HonoContext,\n responseTime: number,\n): string {\n const contentLength = getContentLength(c) ?? \"-\";\n return `${c.req.method} ${c.req.path} ${c.res.status} ${\n responseTime.toFixed(3)\n } ms - ${contentLength}`;\n}\n\n/**\n * Short format.\n * :method :url :status :res[content-length] - :response-time ms\n */\nfunction formatShort(\n c: HonoContext,\n responseTime: number,\n): string {\n const contentLength = getContentLength(c) ?? \"-\";\n return `${c.req.method} ${c.req.url} ${c.res.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 c: HonoContext,\n responseTime: number,\n): string {\n const contentLength = getContentLength(c) ?? \"-\";\n return `${c.req.method} ${c.req.path} ${c.res.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 Hono 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 *\n * @example Basic usage\n * ```typescript\n * import { Hono } from \"hono\";\n * import { configure, getConsoleSink } from \"@logtape/logtape\";\n * import { honoLogger } from \"@logtape/hono\";\n *\n * await configure({\n * sinks: { console: getConsoleSink() },\n * loggers: [\n * { category: [\"hono\"], sinks: [\"console\"], lowestLevel: \"info\" }\n * ],\n * });\n *\n * const app = new Hono();\n * app.use(honoLogger());\n *\n * app.get(\"/\", (c) => c.json({ hello: \"world\" }));\n *\n * export default app;\n * ```\n *\n * @example With custom options\n * ```typescript\n * app.use(honoLogger({\n * category: [\"myapp\", \"http\"],\n * level: \"debug\",\n * format: \"dev\",\n * skip: (c) => c.req.path === \"/health\",\n * }));\n * ```\n *\n * @example With custom format function\n * ```typescript\n * app.use(honoLogger({\n * format: (c, responseTime) => ({\n * method: c.req.method,\n * path: c.req.path,\n * status: c.res.status,\n * duration: responseTime,\n * }),\n * }));\n * ```\n *\n * @param options Configuration options for the middleware.\n * @returns Hono middleware function.\n * @since 1.3.0\n */\nexport function honoLogger(\n options: HonoLogTapeOptions = {},\n): MiddlewareHandler {\n const category = normalizeCategory(options.category ?? [\"hono\"]);\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 createMiddleware(async (c, next) => {\n const startTime = Date.now();\n\n // For immediate logging, log when request arrives\n if (logRequest) {\n if (!skip(c as unknown as HonoContext)) {\n const result = formatFn(c as unknown as HonoContext, 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(c as unknown as HonoContext)) return;\n\n const responseTime = Date.now() - startTime;\n const result = formatFn(c as unknown as HonoContext, 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":";;;;;;;AAyHA,SAAS,YAAYA,GAAoC;AACvD,QAAO,EAAE,IAAI,OAAO,WAAW,IAAI,EAAE,IAAI,OAAO,UAAU;AAC3D;;;;AAKD,SAAS,aAAaA,GAAoC;AACxD,QAAO,EAAE,IAAI,OAAO,aAAa;AAClC;;;;AAKD,SAAS,iBAAiBA,GAAoC;CAC5D,MAAM,gBAAgB,EAAE,IAAI,QAAQ,IAAI,iBAAiB;AACzD,KAAI,kBAAkB,KAAM;AAC5B,QAAO;AACR;;;;AAKD,SAAS,gBACPA,GACAC,cACsB;AACtB,QAAO;EACL,QAAQ,EAAE,IAAI;EACd,KAAK,EAAE,IAAI;EACX,MAAM,EAAE,IAAI;EACZ,QAAQ,EAAE,IAAI;EACd;EACA,eAAe,iBAAiB,EAAE;EAClC,WAAW,aAAa,EAAE;EAC1B,UAAU,YAAY,EAAE;CACzB;AACF;;;;;AAMD,SAAS,eACPD,GACAC,cACyB;AACzB,QAAO,EAAE,GAAG,gBAAgB,GAAG,aAAa,CAAE;AAC/C;;;;;AAMD,SAAS,aACPD,GACAC,cACyB;CACzB,MAAM,QAAQ,gBAAgB,GAAG,aAAa;CAC9C,MAAM,EAAE,UAAU,WAAW,WAAW,WAAY,GAAG,MAAM,GAAG;AAChE,QAAO;AACR;;;;;AAMD,SAAS,UACPD,GACAC,cACQ;CACR,MAAM,gBAAgB,iBAAiB,EAAE,IAAI;AAC7C,SAAQ,EAAE,EAAE,IAAI,OAAO,GAAG,EAAE,IAAI,KAAK,GAAG,EAAE,IAAI,OAAO,GACnD,aAAa,QAAQ,EAAE,CACxB,QAAQ,cAAc;AACxB;;;;;AAMD,SAAS,YACPD,GACAC,cACQ;CACR,MAAM,gBAAgB,iBAAiB,EAAE,IAAI;AAC7C,SAAQ,EAAE,EAAE,IAAI,OAAO,GAAG,EAAE,IAAI,IAAI,GAAG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GAA6B,aAAa;AAElE,aAAW,WAAW,SACpB,WAAU,OAAO;MAEjB,WAAU,+CAA+C,OAAO;CAEnE,EAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"mod.js","names":["options: boolean | RequestContextOptions | undefined","options: boolean | RequestIdOptions | undefined","value: string","c: HonoContext","options: RequestIdOptions","responseHeader","responseTime: number","resolvedRequestId: ResolvedRequestId | undefined","include: readonly RequestContextField[]","context: Record<string, unknown>","options: RequestContextOptions","requestContext: HonoRequestContextState","result: string | Record<string, unknown>","predefinedFormats: Record<PredefinedFormat, FormatFunction>","category: string | readonly string[]","options: HonoLogTapeOptions","formatFn: FormatFunction","requestContextState: HonoRequestContextState","requestContextState","result"],"sources":["../src/mod.ts"],"sourcesContent":["import { getLogger, type LogLevel, withContext } from \"@logtape/logtape\";\nimport { createMiddleware } from \"hono/factory\";\nimport type { Context, MiddlewareHandler } from \"hono\";\n\nexport type { LogLevel } from \"@logtape/logtape\";\n\n/**\n * Hono context interface exposed to custom formatters and skip callbacks.\n *\n * This matches the actual runtime object passed to the middleware, so custom\n * formatters can access context variables via methods like `c.get()` when\n * needed.\n * @since 1.3.0\n */\n// deno-lint-ignore no-explicit-any\nexport interface HonoContext extends Context<any, any, any> {}\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 c The Hono 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 c: HonoContext,\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 header value */\n contentLength: 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 c: HonoContext,\n ) => Record<string, unknown> | Promise<Record<string, unknown>>;\n}\n\n/**\n * Options for configuring the Hono LogTape middleware.\n * @since 1.3.0\n */\nexport interface HonoLogTapeOptions {\n /**\n * The LogTape category to use for logging.\n * @default [\"hono\"]\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(honoLogger({\n * skip: (c) => c.req.path === \"/health\",\n * }));\n * ```\n *\n * @default () => false\n */\n readonly skip?: (c: HonoContext) => 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\ninterface ResolvedRequestId {\n readonly property: string;\n readonly value: string;\n readonly responseHeader?: string;\n}\n\ninterface HonoRequestContextState {\n readonly context: Record<string, unknown>;\n readonly responseHeader?: {\n readonly name: string;\n readonly value: string;\n };\n}\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 c: HonoContext,\n options: RequestIdOptions,\n): ResolvedRequestId {\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 = c.req.header(headerName);\n if (headerValue == null) continue;\n const normalized = normalize(headerValue);\n if (normalized != null) {\n const responseHeader = options.responseHeader ?? defaultRequestIdHeader;\n return {\n property,\n value: normalized,\n responseHeader: responseHeader === false ? undefined : responseHeader,\n };\n }\n }\n const generated = (options.generate ?? generateRequestId)();\n const responseHeader = options.responseHeader ?? defaultRequestIdHeader;\n return {\n property,\n value: generated,\n responseHeader: responseHeader === false ? undefined : responseHeader,\n };\n}\n\n/**\n * Get referrer from request headers.\n */\nfunction getReferrer(c: HonoContext): string | undefined {\n return c.req.header(\"referrer\") || c.req.header(\"referer\");\n}\n\n/**\n * Get user agent from request headers.\n */\nfunction getUserAgent(c: HonoContext): string | undefined {\n return c.req.header(\"user-agent\");\n}\n\n/**\n * Get remote address from X-Forwarded-For header.\n */\nfunction getRemoteAddr(c: HonoContext): string | undefined {\n const forwarded = c.req.header(\"x-forwarded-for\");\n if (forwarded == null) return undefined;\n const firstIp = forwarded.split(\",\")[0].trim();\n return firstIp || undefined;\n}\n\n/**\n * Get content length from response headers.\n */\nfunction getContentLength(c: HonoContext): string | undefined {\n const contentLength = c.res.headers.get(\"content-length\");\n if (contentLength === null) return undefined;\n return contentLength;\n}\n\n/**\n * Build structured log properties from context.\n */\nfunction buildProperties(\n c: HonoContext,\n responseTime: number,\n): RequestLogProperties {\n return {\n method: c.req.method,\n url: c.req.url,\n path: c.req.path,\n status: c.res.status,\n responseTime,\n contentLength: getContentLength(c),\n userAgent: getUserAgent(c),\n referrer: getReferrer(c),\n };\n}\n\n/**\n * Build request context fields from a request.\n */\nfunction buildIncludedContext(\n c: HonoContext,\n resolvedRequestId: ResolvedRequestId | 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 = c.req.method;\n break;\n case \"url\":\n context.url = c.req.url;\n break;\n case \"path\":\n context.path = c.req.path;\n break;\n case \"userAgent\":\n context.userAgent = getUserAgent(c);\n break;\n case \"remoteAddr\":\n context.remoteAddr = getRemoteAddr(c);\n break;\n case \"referrer\":\n context.referrer = getReferrer(c);\n break;\n }\n }\n return context;\n}\n\n/**\n * Build the implicit context for a request.\n */\nasync function buildRequestContext(\n c: HonoContext,\n options: RequestContextOptions,\n): Promise<HonoRequestContextState> {\n const requestIdOptions = normalizeRequestIdOptions(options.requestId);\n const resolvedRequestId = requestIdOptions == null\n ? undefined\n : resolveRequestId(c, requestIdOptions);\n const include = options.include ??\n (resolvedRequestId == null ? [] : [\"requestId\"] as const);\n const context = buildIncludedContext(c, resolvedRequestId, include);\n if (options.enrich != null) Object.assign(context, await options.enrich(c));\n const responseHeader = resolvedRequestId?.responseHeader == null\n ? undefined\n : {\n name: resolvedRequestId.responseHeader,\n value: resolvedRequestId.value,\n };\n return { context, responseHeader };\n}\n\n/**\n * Apply deferred context response headers to the final Hono response.\n */\nfunction applyResponseHeaders(\n c: HonoContext,\n requestContext: HonoRequestContextState,\n): void {\n if (requestContext.responseHeader == null) return;\n c.header(\n requestContext.responseHeader.name,\n requestContext.responseHeader.value,\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 c: HonoContext,\n responseTime: number,\n): Record<string, unknown> {\n return { ...buildProperties(c, responseTime) };\n}\n\n/**\n * Common format (Apache Common Log Format).\n * Like combined but without referrer and userAgent.\n */\nfunction formatCommon(\n c: HonoContext,\n responseTime: number,\n): Record<string, unknown> {\n const props = buildProperties(c, 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 c: HonoContext,\n responseTime: number,\n): string {\n const contentLength = getContentLength(c) ?? \"-\";\n return `${c.req.method} ${c.req.path} ${c.res.status} ${\n responseTime.toFixed(3)\n } ms - ${contentLength}`;\n}\n\n/**\n * Short format.\n * :method :url :status :res[content-length] - :response-time ms\n */\nfunction formatShort(\n c: HonoContext,\n responseTime: number,\n): string {\n const contentLength = getContentLength(c) ?? \"-\";\n return `${c.req.method} ${c.req.url} ${c.res.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 c: HonoContext,\n responseTime: number,\n): string {\n const contentLength = getContentLength(c) ?? \"-\";\n return `${c.req.method} ${c.req.path} ${c.res.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 Hono 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 *\n * @example Basic usage\n * ```typescript\n * import { Hono } from \"hono\";\n * import { configure, getConsoleSink } from \"@logtape/logtape\";\n * import { honoLogger } from \"@logtape/hono\";\n *\n * await configure({\n * sinks: { console: getConsoleSink() },\n * loggers: [\n * { category: [\"hono\"], sinks: [\"console\"], lowestLevel: \"info\" }\n * ],\n * });\n *\n * const app = new Hono();\n * app.use(honoLogger());\n *\n * app.get(\"/\", (c) => c.json({ hello: \"world\" }));\n *\n * export default app;\n * ```\n *\n * @example With custom options\n * ```typescript\n * app.use(honoLogger({\n * category: [\"myapp\", \"http\"],\n * level: \"debug\",\n * format: \"dev\",\n * skip: (c) => c.req.path === \"/health\",\n * }));\n * ```\n *\n * @example With custom format function\n * ```typescript\n * app.use(honoLogger({\n * format: (c, responseTime) => ({\n * method: c.req.method,\n * path: c.req.path,\n * status: c.res.status,\n * duration: responseTime,\n * }),\n * }));\n * ```\n *\n * @param options Configuration options for the middleware.\n * @returns Hono middleware function.\n * @since 1.3.0\n */\nexport function honoLogger(\n options: HonoLogTapeOptions = {},\n): MiddlewareHandler {\n const category = normalizeCategory(options.category ?? [\"hono\"]);\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 createMiddleware(async (c, next) => {\n const startTime = Date.now();\n const honoContext = c as unknown as HonoContext;\n\n const handleRequest = async (\n requestContextState: HonoRequestContextState,\n ): Promise<void> => {\n const requestContext = requestContextState.context;\n // For immediate logging, log when request arrives\n if (logRequest) {\n if (!skip(honoContext)) {\n const result = withRequestLogContext(\n formatFn(honoContext, 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 applyResponseHeaders(honoContext, requestContextState);\n return;\n }\n\n // Log after response is sent\n await next();\n applyResponseHeaders(honoContext, requestContextState);\n\n if (skip(honoContext)) return;\n\n const responseTime = Date.now() - startTime;\n const result = withRequestLogContext(\n formatFn(honoContext, 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({ context: {} });\n return;\n }\n\n const requestContextState = await buildRequestContext(\n honoContext,\n contextOptions,\n );\n await withContext(\n requestContextState.context,\n () => handleRequest(requestContextState),\n );\n });\n}\n"],"mappings":";;;;AA8MA,MAAM,yBAAyB;;;;AAmB/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,SAAS,iBACPC,GACAC,SACmB;CACnB,MAAM,WAAW,QAAQ,YAAY;CACrC,MAAM,YAAY,QAAQ,aAAa;CACvC,MAAM,cAAc,QAAQ,eAAe,CAAC,sBAAuB;AACnE,MAAK,MAAM,cAAc,aAAa;EACpC,MAAM,cAAc,EAAE,IAAI,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AiB,WACrD,kBAAkB,gBAClB;CAEJ,MAAM,YAAY,OAAO,OAAO,KAAK,OAAO;AAE5C,QAAO,iBAAiB,OAAO,GAAG,SAAS;EACzC,MAAM,YAAY,KAAK,KAAK;EAC5B,MAAM,cAAc;EAEpB,MAAM,gBAAgB,OACpBC,0BACkB;GAClB,MAAM,iBAAiBC,sBAAoB;AAE3C,OAAI,YAAY;AACd,SAAK,KAAK,YAAY,EAAE;KACtB,MAAMC,WAAS,sBACb,SAAS,aAAa,EAAE,EACxB,eACD;AACD,gBAAWA,aAAW,SACpB,WAAUA,UAAQ,eAAe;SAEjC,WAAU,kBAAkBA,SAAO;IAEtC;AACD,UAAM,MAAM;AACZ,yBAAqB,aAAaD,sBAAoB;AACtD;GACD;AAGD,SAAM,MAAM;AACZ,wBAAqB,aAAaA,sBAAoB;AAEtD,OAAI,KAAK,YAAY,CAAE;GAEvB,MAAM,eAAe,KAAK,KAAK,GAAG;GAClC,MAAM,SAAS,sBACb,SAAS,aAAa,aAAa,EACnC,eACD;AAED,cAAW,WAAW,SACpB,WAAU,QAAQ,eAAe;OAEjC,WAAU,+CAA+C,OAAO;EAEnE;AAED,MAAI,kBAAkB,MAAM;AAC1B,SAAM,cAAc,EAAE,SAAS,CAAE,EAAE,EAAC;AACpC;EACD;EAED,MAAM,sBAAsB,MAAM,oBAChC,aACA,eACD;AACD,QAAM,YACJ,oBAAoB,SACpB,MAAM,cAAc,oBAAoB,CACzC;CACF,EAAC;AACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logtape/hono",
|
|
3
|
-
"version": "2.2.0-dev.
|
|
3
|
+
"version": "2.2.0-dev.686+61fa5e1a",
|
|
4
4
|
"description": "Hono adapter for LogTape logging library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"logging",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
],
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"hono": "^4.0.0",
|
|
58
|
-
"@logtape/logtape": "^2.2.0-dev.
|
|
58
|
+
"@logtape/logtape": "^2.2.0-dev.686+61fa5e1a"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@alinea/suite": "^0.6.3",
|