Delete all but one request header from logs?

1. The problem I’m having:

I’d like to minimize log data. I don’t care about most of the request headers, but I do care about the user agent. I can suppress logging all request headers with

    format filter {
      wrap json
      fields {
        request>headers delete

That also removes the user agent. I could enumerate every possible header, or some significant portion thereof, and include lines to delete them, like so:

    format filter {
      wrap json
      fields {
        request>headers>Accept delete
        request>headers>Accept-Encoding delete
        request>headers>Accept-Language delete
        request>headers>Cache-Control delete
        request>headers>Connection delete
        request>headers>If-None-Match delete
        request>headers>Priority delete
        request>headers>Upgrade-Insecure-Requests delete

That’s time consuming, and playing whack-a-mole against a never-ending list.

Is there a way to say “delete all headers EXCEPT FOR these ones I want” ?

3. Caddy version:

v2.10.0 h1:fonubSaQKF1YANl8TXqGcn4IbIRUDdfAkpcsfI/vX5U=

  1. How I installed and ran Caddy:

a. System environment:

Linux skippy 6.8.0-90-generic #91-Ubuntu SMP PREEMPT_DYNAMIC Tue Nov 18 14:14:30 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

5. Links to relevant resources:

Not sure if this is what you’re looking for, but kind of a workaround:

	log {
		format filter {
			request>headers delete
			# resp_headers delete
		}
	}
	log_append User-Agent {http.request.header.User-Agent}

You’ll get something like this:

2026/01/21 22:04:29.491	INFO	http.log.access.log0	handled request	{"request": {"remote_ip": "127.0.0.1", "remote_port": "54127", "client_ip": "127.0.0.1", "proto": "HTTP/2.0", "method": "GET", "host": "example.com", "uri": "/", "tls": {"resumed": false, "version": 772, "cipher_suite": 4865, "proto": "h2", "server_name": "example.com"}}, "bytes_read": 0, "user_id": "", "duration": 0.000014916, "size": 2, "status": 200, "resp_headers": {"Server": ["Caddy"], "Alt-Svc": ["h3=\":443\"; ma=2592000"], "Content-Type": ["text/plain; charset=utf-8"]}, "User-Agent": "curl/8.17.0"}
4 Likes

Awesome. Thank you!

1 Like