import { Context, Next } from "@oak/oak"; export async function requestLogger(ctx: Context, next: Next): Promise { const start = Date.now(); await next(); const ms = Date.now() - start; const status = ctx.response.status; const method = ctx.request.method; const url = ctx.request.url.pathname; const color = status >= 500 ? "\x1b[31m" : status >= 400 ? "\x1b[33m" : "\x1b[32m"; const reset = "\x1b[0m"; console.log(`${color}${status}${reset} ${method} ${url} - ${ms}ms`); }