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
| Level | Method | When to use |
|---|---|---|
| Debug | c.Logger().Debug() | Detailed info for debugging |
| Info | c.Logger().Info() | Normal operations |
| Warn | c.Logger().Warn() | Something unexpected but recoverable |
| Error | c.Logger().Error() | Something failed |
Configuring the logger
Logger middleware options
Configure the built-in request logger:Log modes
| Mode | Output | Use case |
|---|---|---|
mizu.Auto | Text for terminals, JSON otherwise | Default - adapts automatically |
mizu.Dev | Human-readable text | Local development |
mizu.Prod | JSON | Production log aggregators |
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)
Complete example
Summary
| Feature | How |
|---|---|
| Log in handler | c.Logger().Info("message", "key", value) |
| Log levels | Debug, Info, Warn, Error |
| Configure format | mizu.Logger(mizu.LoggerOptions{Mode: mizu.Prod}) |
| Custom logger | app.SetLogger(myLogger) |
| Request ID | Automatic with RequestIDHeader option |