diff --git a/app/server/app.ts b/app/server/app.ts index 6c55f566..d121bf02 100644 --- a/app/server/app.ts +++ b/app/server/app.ts @@ -1,8 +1,8 @@ import { Scalar } from "@scalar/hono-api-reference"; +import type { Context, Next } from "hono"; import { Hono } from "hono"; import { bodyLimit } from "hono/body-limit"; import { cors } from "hono/cors"; -import { logger as honoLogger } from "hono/logger"; import { secureHeaders } from "hono/secure-headers"; import { rateLimiter } from "hono-rate-limiter"; import { openAPIRouteHandler } from "hono-openapi"; @@ -21,6 +21,20 @@ import { config } from "./core/config"; import { auth } from "~/server/lib/auth"; import { db } from "./db/db"; +const requestLogger = async (c: Context, next: Next) => { + const method = c.req.method; + const path = c.req.path; + const start = performance.now(); + + logger.debug(`<-- ${method} ${path}`); + + try { + await next(); + } finally { + logger.debug(`--> ${method} ${path} ${c.res.status} ${Math.round(performance.now() - start)}ms`); + } +}; + const generalDescriptor = (app: Hono) => openAPIRouteHandler(app, { documentation: { @@ -49,7 +63,7 @@ export const createApp = () => { if (config.environment === "production") { app.use(secureHeaders()); - app.use(honoLogger()); + app.use(requestLogger); } app.use(