User Guide

http.log

log enables request logging. The request log is also known from some vernaculars as an access log.

Syntax

With no arguments, an access log is written to access.log in the common log format for all requests:

log

Customize the log file location:

log file

To restrict this log to certain requests or to change the log format:

log path file [format]

Large log files are rolled automatically. You can customize log rolling or other things by opening a block:

log path file [format] { rotate_size mb rotate_age days rotate_keep count rotate_compress ipmask ipv4_mask [ipv6_mask] except paths... }

Log Format

You can specify a custom log format with any placeholder values. Log supports both request and response placeholders.

Currently there are two predefined formats.

Log Destination

The log destination can be one of a few things:

Log Rolling

Logs have the potential to fill the disk. To mitigate this, request logs are rotated ("rolled") automatically according to this default configuration:

rotate_size 100 # Rotate a log when it reaches 100 MB rotate_age 14 # Keep rotated log files for 14 days rotate_keep 10 # Keep at most 10 rotated log files rotate_compress # Compress rotated log files in gzip format

You can specify these subdirectives to customize log rolling.

Examples

Log all requests to access.log:

log

Log all requests to stdout:

log stdout

Custom log format:

log / stdout "{proto} Request: {method} {path}"

Predefined format:

log / stdout "{combined}"

With rotation:

log requests.log { rotate_size 50 # Rotate after 50 MB rotate_age 90 # Keep rotated files for 90 days rotate_keep 20 # Keep at most 20 log files rotate_compress # Compress rotated log files in gzip format }

To mask (anonymize) IPv4 addresses and IPv6 addresses down to a couple octets:

log requests.log { ipmask 255.255.0.0 ffff:ffff:ffff:ff00:: }

Need help with this feature?

Join us in the Caddy forum, where the open source community gathers to share their knowledge.

Does your company use Caddy?

Purchase a commercial license to use Caddy with your business and for basic email support, along with other benefits!