Documentation Index
Fetch the complete documentation index at: https://mintlify.com/honojs/hono/llms.txt
Use this file to discover all available pages before exploring further.
Import
Usage
Options
Thelogger middleware accepts an optional print function:
Optional function for customized logging behavior. This function will be called with the formatted log message.
Signature
Examples
Basic usage
Custom print function
Log to file
Structured logging
Conditional logging
Apply to specific routes
Output Format
The logger produces two lines per request:- Incoming request:
--> METHOD PATH - Outgoing response:
<-- METHOD PATH STATUS DURATION
Examples
Status Code Colors
When color is enabled (supported terminal), status codes are color-coded:- 2xx (Success): Green
- 3xx (Redirect): Cyan
- 4xx (Client Error): Yellow
- 5xx (Server Error): Red
Behavior
- Logs incoming request before handler execution
- Logs outgoing response after handler completes
- Includes response status code and elapsed time
- Time is displayed in milliseconds for durations < 1 second
- Time is displayed in seconds (rounded) for durations >= 1 second
- Automatically detects color support in terminal
- Works with all HTTP methods
- Extracts path from full URL for cleaner logs