slog package for structured logging. Every request gets logged automatically, and you can add custom log messages anywhere in your handlers.
What is structured logging?
Traditional logging writes plain text:Built-in request logging
When you create a Mizu app, request logging is enabled by default:Logging in handlers
Access the logger from the context to add your own log messages:Log levels
Configuring the logger
Logger middleware options
Configure the built-in request logger:Log modes
Custom logger
Replace the default logger with your own:c.Logger().
Request ID tracking
The logger middleware automatically generates or propagates a request ID for each request. This helps trace requests across services.- Read from the incoming request header (if present)
- Generated automatically (if not present)
- Added to the response headers
- Included in all log entries
Example output
Development mode (text)
Production mode (JSON)
Summary
Next steps
Error Handling
Handle and log errors effectively.
Middleware
Add cross-cutting logging behavior.