access-log.ts22 lines · main
1import type { MiddlewareHandler } from 'hono';
2
3import { log } from '../lib/logger.js';
4
5/**
6 * Access log — one line per request. Per CLAUDE.md §5.1 we never log IPs,
7 * emails, bodies, or query parameters. Path, method, status, duration, and
8 * the request id are the only fields.
9 */
10export const accessLog = (): MiddlewareHandler => async (c, next) => {
11 const start = performance.now();
12 await next();
13 const durationMs = Math.round((performance.now() - start) * 100) / 100;
14
15 log.info('request', {
16 reqId: c.get('requestId'),
17 method: c.req.method,
18 path: c.req.path,
19 status: c.res.status,
20 durationMs,
21 });
22};