import type { NextFunction, Request, Response } from 'express'; import { logger } from '../config/logger'; export function requestLogger( req: Request, res: Response, next: NextFunction, ): void { const started = process.hrtime.bigint(); res.once('finish', () => { const elapsedMs = Number(process.hrtime.bigint() - started) / 1_000_000; logger.info( { request_id: res.locals.requestId, method: req.method, path: req.path, status: res.statusCode, duration_ms: Math.round(elapsedMs * 100) / 100, }, 'request completed', ); }); next(); }