Custom logging format

Is it possible to format access logs to include certain fields. For example, upstream connect time, upstream response time, request body, etc

To manipulate the log output you’d be looking at format modules: log (Caddyfile directive) — Caddy Documentation.

GitHub - caddyserver/transform-encoder: Log encoder module for custom log formats is a non-standard module you can use to arbitrarily define your log format by templating cherry-picked values from the JSON encoder.

Off the top of my head, I don’t think any of your three examples are available. In particular, my understanding is that request body logging is not feasible as it would require Caddy to buffer all responses at a massive performance hit.

1 Like

Actually those can be added with log_append with the placeholders from reverse_proxy (can be shortcut with {rp.*} in the Caddyfile)

log_append proxy_duration {rp.upstream.duration_ms}

But I agree logging the request body is a bad idea, because that requires buffering the request body in Caddy instead of streaming it to the upstream, harming performance.

2 Likes

Thanks! The timings are the most important thing. Being able to log the request body to troubleshoot issues (knowing what the actual request is) is helpful to be able to enable but not have logging all the time.