()
| 1 | import type { MiddlewareHandler } from 'hono'; |
| 2 | |
| 3 | export const logger = (): MiddlewareHandler => { |
| 4 | return async function logger(c, next) { |
| 5 | await next(); |
| 6 | c.req.matchedRoutes.forEach(({ handler, method, path }, i) => { |
| 7 | const name = |
| 8 | handler.name || |
| 9 | (handler.length < 2 ? '[handler]' : '[middleware]'); |
| 10 | console.log( |
| 11 | method, |
| 12 | ' ', |
| 13 | path, |
| 14 | ' '.repeat(Math.max(10 - path.length, 0)), |
| 15 | name, |
| 16 | i === c.req.routeIndex ? '<- respond from here' : '' |
| 17 | ); |
| 18 | }); |
| 19 | }; |
| 20 | }; |