Replies: 2 comments
-
|
Here is what should work : |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
In case anyone's looking for a full solution including the request and response body, this is based on the Hono logger middleware: /**
* Logger middleware for development; based on Hono's default logger middleware
*/
export const devLoggerMiddleware = createMiddleware(async (c, next) => {
const { method, url, raw } = c.req
const path = url.slice(url.indexOf("/", 8))
console.debug("<--" /* Incoming */, method, path)
if (method === "POST" || method === "PUT" || method === "PATCH") {
try {
const requestBody = await raw.clone().json()
console.log("Request Body:", JSON.stringify(requestBody, null, 2))
} catch (e) {
console.log("Request Body (not JSON or empty):", await c.req.text())
}
}
const start = Date.now()
await next()
const time = (start: number) => {
const delta = Date.now() - start
return delta < 1e3 ? delta + "ms" : Math.round(delta / 1e3) + "s"
}
const originalResponse = c.res.clone()
const responseBody: any = await originalResponse.json()
console.debug("-->" /* Outgoing */, method, path, c.res.status, time(start))
console.debug(JSON.stringify(responseBody, null, 2))
}) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
Quick question. I'm making a small custom middleware (very similar to the logger middleware in the source files) that sends all API requests to Axiom for logging and monitoring.
I want to send the response body to Axiom, too, but can't seem to find a way to do it. Anyone know? Here is my current code (some stuff changed) for an example.
Thanks!
Tom.
Beta Was this translation helpful? Give feedback.
All reactions