feat(logging): add request logger middleware for improved request tracking
This commit is contained in:
@@ -2,6 +2,7 @@ import { Hono } from "hono";
|
|||||||
import { serveStatic } from "hono/bun";
|
import { serveStatic } from "hono/bun";
|
||||||
import { auth } from "./lib/auth";
|
import { auth } from "./lib/auth";
|
||||||
import { authMiddleware } from "./lib/auth-middleware";
|
import { authMiddleware } from "./lib/auth-middleware";
|
||||||
|
import { requestLogger } from "./lib/request-logger";
|
||||||
import { startQuoteJob } from "./modules/quotes/quote.job";
|
import { startQuoteJob } from "./modules/quotes/quote.job";
|
||||||
import quotesRouter from "./modules/quotes/quotes.routes";
|
import quotesRouter from "./modules/quotes/quotes.routes";
|
||||||
import expensesRouter from "./modules/expenses/expenses.routes";
|
import expensesRouter from "./modules/expenses/expenses.routes";
|
||||||
@@ -10,6 +11,8 @@ import { logger } from "./lib/logger";
|
|||||||
|
|
||||||
const app = new Hono();
|
const app = new Hono();
|
||||||
|
|
||||||
|
app.use("*", requestLogger);
|
||||||
|
|
||||||
app.get("/api/health", (c) => {
|
app.get("/api/health", (c) => {
|
||||||
return c.json({ status: "ok", timestamp: new Date().toISOString() });
|
return c.json({ status: "ok", timestamp: new Date().toISOString() });
|
||||||
});
|
});
|
||||||
|
|||||||
15
apps/backend/src/lib/request-logger.ts
Normal file
15
apps/backend/src/lib/request-logger.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import type { Context, Next } from "hono";
|
||||||
|
import { logger } from "./logger";
|
||||||
|
|
||||||
|
export async function requestLogger(c: Context, next: Next) {
|
||||||
|
const start = performance.now();
|
||||||
|
const method = c.req.method;
|
||||||
|
const path = c.req.path;
|
||||||
|
|
||||||
|
logger.info(`→ ${method} ${path}`);
|
||||||
|
|
||||||
|
await next();
|
||||||
|
|
||||||
|
const duration = (performance.now() - start).toFixed(2);
|
||||||
|
logger.info(`← ${method} ${path} ${duration}ms`);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user