User Guide

http.errors

errors allows you to set custom error pages and enable error logging.

Without this middleware, error responses (HTTP status >= 400) are not logged and the client receives a plaintext error message.

Using an error log, the text of each error will be recorded so you can determine what is going wrong without exposing those details to the clients. With error pages, you can present custom error messages and instruct your visitor what to do. When you specify custom error pages, error logging is automatically enabled.

Syntax

errors [logfile]

To specify custom error pages, open a block:

errors [logfile] { code file rotate_size mb rotate_age days rotate_keep count rotate_compress }

Log Destination

The log destination can be one of a few things:

The default log destination is stderr.

Log Rolling

Logs have the potential to fill the disk. To mitigate this, error 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 errors to stderr:

errors

Log errors to a custom file in the parent directory:

errors ../error.log

Log errors and serve custom error pages:

errors { 404 404.html # Not Found 500 500.html # Internal Server Error }

Log errors to custom log file and serve custom error pages:

errors ../error.log { 404 404.html # Not Found 500 500.html # Internal Server Error }

Define a default, catch-all error page:

errors { * default_error.html }

Make errors visible to the client (for debugging only):

errors visible

Customize error log rolling:

errors { 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 }

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!