Skip to main content

Logging Configuration

Caddy provides zero-allocation, high-performance structured logging using Zap. Logs can be customized with different outputs, encoders, and filters.

Default Logging

By default, Caddy logs to stderr at INFO level:

Log Configuration

Custom Log Output

Log Levels

Available log levels (from most to least verbose):
  • DEBUG - Detailed debugging information
  • INFO - General informational messages (default)
  • WARN - Warning messages
  • ERROR - Error messages
  • PANIC - Panic messages (causes panic)
  • FATAL - Fatal messages (causes exit)
Use environment variables for dynamic log levels: level {$LOG_LEVEL}

Log Encoders

JSON Encoder

Structured JSON output:

Console Encoder

Human-readable output:

Custom Format

Log Writers

File Writer

Network Writer

Send logs over the network:

Standard Streams

Discard

Disable logging:

Log Filtering

Include Specific Modules

Only log from specific modules:

Exclude Modules

Filter out specific modules:

Complex Filtering

Combine include and exclude:
When both include and exclude are set, longer namespaces have priority. The lists must be mutually exclusive superset/subset pairs.

HTTP Access Logs

Configure access logs per site:

Access Log Fields

Customize which fields to log:

Sampling

Reduce log volume on high-traffic servers:
Sampling logs the first N entries per interval, then 1 in M thereafter. This drastically reduces log volume while preserving representative samples.

Caller Information

Include file and line numbers in logs:

Multiple Logs

Configure different logs for different purposes:

Sink Log

Configure the sink for stdlib logger output:
The sink captures logs from Go’s standard library logger, used by dependencies not built specifically for Caddy.

Complete Example

Log Module Names

Common logger names for filtering:
  • http - All HTTP-related logs
  • http.log.access - HTTP access logs
  • http.handlers.* - HTTP handler logs
  • http.handlers.reverse_proxy - Reverse proxy logs
  • http.handlers.file_server - File server logs
  • admin - Admin endpoint logs
  • admin.api - Admin API logs
  • tls - TLS/certificate logs
  • tls.issuance - Certificate issuance logs

Best Practices

Verbose logging (DEBUG level) can impact performance and generate large volumes of logs. Use sparingly in production.