Logging and request ids — Middleware · Hono

Give every request a log line, an id that follows it from the client through the handler to the response, and a JSON body a human can read when asked.

What you will learn

Read the theory for Logging and request ids

All Middleware lessons

All Hono courses

loading types…

What you'll learn

  • Log every request and response with logger(), and route the lines somewhere with its print function
  • Tag every request with requestId(): reuse the id a client sent, generate one otherwise, expose it on the response and on the context
  • Prettify JSON on demand with prettyJSON() and its ?pretty query