Overview
Caddy’s logging system is:- Zero-allocation - High performance in terms of memory and CPU time
- Structured - Built on top of Uber’s Zap logging library
- Flexible - Multiple logs with different outputs and filters
- Filterable - Filter by level and module/logger names
Configuration
Basic Logging Structure
Log Encoders
Encoders determine how log entries are formatted.Console Encoder
Module ID:caddy.logging.encoders.console
Encodes log entries in a human-readable format.
The key name for the log message. Default:
msgThe key name for the log level. Default:
levelThe key name for the timestamp. Default:
tsThe key name for the logger name. Default:
loggerThe key name for the caller information. Default:
callerThe key name for stack traces. Default:
stacktraceThe character(s) to use for line endings. Default:
\nTime format for timestamps. Options:
unix_seconds_float- Unix timestamp as float (default)unix_milli_float- Unix timestamp in milliseconds as floatunix_nano- Unix timestamp in nanosecondsiso8601- ISO8601 formatrfc3339- RFC3339 formatrfc3339_nano- RFC3339 with nanosecondswall- Wall clock time (2006/01/02 15:04:05)wall_milli- Wall clock with millisecondswall_nano- Wall clock with nanosecondscommon_log- Common log format (02/Jan/2006:15:04:05 -0700)- Custom Go time layout string
Use local timezone instead of UTC. Default:
falseFormat for durations:
s,second,seconds- Seconds (default)ns,nano,nanos- Nanosecondsms,milli,millis- Millisecondsstring- String representation
Format for log levels:
lower- lowercase (default)upper- UPPERCASEcolor- Color-coded (console only)
JSON Encoder
Module ID:caddy.logging.encoders.json
Encodes log entries as JSON. Accepts the same configuration parameters as the console encoder.
Log Writers
Writers determine where log output is sent.File Writer
Module ID:caddy.logging.writers.file
Writes logs to files with automatic rotation.
Path to the log file
File permissions mode (octal). Default:
0600Directory permissions mode. Options:
- Octal string (e.g.,
0755) inherit- Copy nearest parent directory permissionsfrom_file- Derive from file mode (e.g., 0644 → 0755)
0700Enable log rotation. Default:
trueMaximum log file size in megabytes before rotation. Default:
100Time interval for log rotation (e.g.,
24h, 1h30m)Minutes of each hour to rotate logs. Example:
[0, 30] rotates at xx:00 and xx:30Times of day to rotate logs. Example:
["00:00", "12:00"] rotates at midnight and noonCompression algorithm for rotated files:
gzip(default)zstdnone
Use local time in rotated filenames. Default:
falseMaximum number of rolled log files to keep. Default:
10Maximum number of days to keep rolled log files. Default:
90Go time format for rotated filenames. Default:
2006-01-02T15-04-05.000Network Writer
Module ID:caddy.logging.writers.net
Writes logs to a network socket. If the connection fails, logs are dumped to stderr.
Network address to connect to (e.g.,
localhost:514, syslog.example.com:514)Timeout for connecting to the socket
Allow connection errors when first opening the writer. Logs will go to stderr until connection succeeds. Default:
falseStandard Writers
Standard output writers are built-in and require no configuration.
- stdout -
caddy.logging.writers.stdout- Writes to standard output - stderr -
caddy.logging.writers.stderr- Writes to standard error (default) - discard -
caddy.logging.writers.discard- Discards all logs
Log Filters
Filters manipulate or redact log fields.Delete Filter
Module ID:caddy.logging.encoders.filter.delete
Deletes a log field entirely.
Hash Filter
Module ID:caddy.logging.encoders.filter.hash
Replaces field value with first 4 bytes of SHA-256 hash.
Replace Filter
Module ID:caddy.logging.encoders.filter.replace
Replacement value
IP Mask Filter
Module ID:caddy.logging.encoders.filter.ip_mask
Masks IP addresses to protect privacy.
IPv4 CIDR subnet size for masking (e.g.,
16 masks last two octets)IPv6 CIDR subnet size for masking
Query Filter
Module ID:caddy.logging.encoders.filter.query
Filters query parameters from URLs.
List of actions to apply to query parameters:
type:replace,hash, ordeleteparameter: Query parameter namevalue: Replacement value (forreplacetype)
Cookie Filter
Module ID:caddy.logging.encoders.filter.cookie
Filters cookies from HTTP headers.
List of actions to apply to cookies:
type:replace,hash, ordeletename: Cookie namevalue: Replacement value (forreplacetype)
Regexp Filter
Module ID:caddy.logging.encoders.filter.regexp
Replaces content matching a regular expression.
Regular expression pattern
Replacement value
Rename Filter
Module ID:caddy.logging.encoders.filter.rename
New field name
Log Levels
Available log levels (from lowest to highest priority):DEBUG- Detailed debugging informationINFO- General informational messages (default)WARN- Warning messagesERROR- Error messagesPANIC- Panic-level messagesFATAL- Fatal messages (causes program termination)
Custom Logs
Define multiple logs with different configurations:Logger names to include (e.g.,
["admin.api", "http.handlers"])Logger names to exclude (e.g.,
["http.log.access"])Sampling
Enable log sampling to improve performance on high-load servers:Sampling window duration. Default:
1sNumber of entries to log within each interval. Default:
100After
first entries, keep 1 in this many entries. Default: 100