Skip to main content
Mizu uses Go’s 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:
Structured logging writes key-value pairs:
Structured logs are easier to search, filter, and analyze with tools like Elasticsearch, Loki, or CloudWatch.

Built-in request logging

When you create a Mizu app, request logging is enabled by default:
Each request produces a log entry like:

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:
All handlers and middleware will use this logger via c.Logger().

Request ID tracking

The logger middleware automatically generates or propagates a request ID for each request. This helps trace requests across services.
The request ID is:
  1. Read from the incoming request header (if present)
  2. Generated automatically (if not present)
  3. Added to the response headers
  4. 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.