404s not logged as expected

I’m running Caddy 0.10.14 on Ubuntu 18.04. I have a Caddyfile like:

www.example.com {
  root /var/www/html
  log /var/log/access.log
  errors /var/log/error.log {
    * error.html

I am expecting 404 and other errors to be logged at /var/log/error.log per the config. Instead, 404s show up in /var/log/access.log, like:

w.x.y.z - - [28/Apr/2018:20:07:58 +0000] "GET /oops HTTP/2.0" 404 735

I’ve also tried changing the error directive to be more specific, like:

errors /var/log/error.log {
  404 error.html

That doesn’t change the outcome.

Any thoughts?

Response status codes are not errors per-se, they are logged to the access log. They are for the clients. Errors is reserved for server-side errors, like problems in middlewares.


That makes sense, and I can understand the split between client and server errors.

I would argue the current behavior is not very intuitive. Especially coming from nginx where 404s are logged to error.log by default. I think the bigger issue here is that the config suggests the opposite of what happens:

errors error.log {
  404 404.html

I think if you ask most people to parse that (who are not familiar with Caddy), they’d come to the conclusion that 404s would be included in the error.log.

https://caddyserver.com/docs/errors doesn’t currently address this behavior, and near the top where it talks about logging “error responses (HTTP status >= 400)” to the error log, it suggests (to me) 404 will be logged.

I’m guessing the behavior won’t be changing at this point, so I’d humbly suggest clarification in the doc, perhaps just a sentence or two similar to your reply above would help others out.

Thanks for Caddy and thanks for hearing me out.

1 Like

I can try to clarify the docs, that’s true. Thanks for the feedback!

But yeah, we won’t really be changing it. It does make sense, even though we do it a little differently than nginx (that’s partly the point).

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.