@kalutskii/foundation 0.7.4 → 0.7.5
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/dist/index.js +11 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -108,6 +108,15 @@ import { blue as blue2, bold, dim as dim2, white as white2 } from "kleur/colors"
|
|
|
108
108
|
var honoLoggingHandler = async (c, next) => {
|
|
109
109
|
const requestUrl = new URL(c.req.url);
|
|
110
110
|
const searchParams = requestUrl.searchParams.toString();
|
|
111
|
+
const body = c.req.header("content-type")?.includes("multipart/form-data") ? (
|
|
112
|
+
// If the request is multipart/form-data, we avoid reading the body
|
|
113
|
+
// to prevent consuming the stream, and instead log a placeholder.
|
|
114
|
+
"[multipart]"
|
|
115
|
+
) : (
|
|
116
|
+
// Otherwise, we read the request body as text and normalize whitespace.
|
|
117
|
+
(await c.req.raw.clone().text()).replaceAll(/\s+/g, " ").trim()
|
|
118
|
+
);
|
|
119
|
+
const bodyPreview = body.length > 100 ? `${body.slice(0, 50)}\u2026${body.slice(-50)}` : body;
|
|
111
120
|
const startTime = performance.now();
|
|
112
121
|
await next();
|
|
113
122
|
const duration = Math.round(performance.now() - startTime);
|
|
@@ -116,7 +125,8 @@ var honoLoggingHandler = async (c, next) => {
|
|
|
116
125
|
const coloredTime = dim2(`${duration}ms`.padStart(6));
|
|
117
126
|
const coloredPath = white2(c.req.path.padEnd(44));
|
|
118
127
|
const coloredSearchParams = searchParams ? dim2(` (${searchParams})`) : "";
|
|
119
|
-
|
|
128
|
+
const coloredBody = bodyPreview ? dim2(` ${bodyPreview}`) : "";
|
|
129
|
+
log.info(`${coloredMethod} ${coloredStatus} ${coloredTime} ${coloredPath}${coloredSearchParams}${coloredBody}`, "hono");
|
|
120
130
|
};
|
|
121
131
|
|
|
122
132
|
// src/hono/hono.respond.ts
|