mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
19 lines
590 B
TypeScript
19 lines
590 B
TypeScript
import { MiddlewareHandler } from '@hono/hono';
|
|
import { logi } from '@soapbox/logi';
|
|
|
|
export const logiMiddleware: MiddlewareHandler = async (c, next) => {
|
|
const { method } = c.req;
|
|
const { pathname } = new URL(c.req.url);
|
|
|
|
logi({ level: 'info', ns: 'ditto.http.request', method, pathname });
|
|
|
|
const start = new Date();
|
|
|
|
await next();
|
|
|
|
const end = new Date();
|
|
const duration = (end.getTime() - start.getTime()) / 1000;
|
|
const level = c.res.status >= 500 ? 'error' : 'info';
|
|
|
|
logi({ level, ns: 'ditto.http.response', method, pathname, status: c.res.status, duration });
|
|
};
|