Trouble with generic logging snippet import
oekelly opened this issue · 2 comments
Hi Team,
Hoping somebody can give me a hand/point me in the correct direction; I'm having difficulty setting up a generic logging snippet with caddy-docker-proxy; the same snippet seems to work with caddy.
Here is the snippet I am creating with lables:
caddy_0.email: me@example.com
caddy_1: (common-log)
caddy_1.log:
caddy_1.log.output: file /var/log/caddy/{args[0]}.log
caddy_1.log.format: filter
caddy_1.log.format.request>headers>Cookie: delete
Which appears to parse correctly into a Caddyfile:
INF ts=1717112951.352321 logger=docker-proxy msg=New Caddyfile caddyfile={
email me@example.com
}
(common-log) {
log {
format filter {
request>headers>Cookie delete
}
output file /var/log/caddy/{args[0]}.log
}
}
I then import this snippet in a subsequent container:
labels:
caddy: whoami.example.com
caddy.reverse_proxy: "{{upstreams 80}}"
caddy.tls.dns: "cloudflare {env.CF_DNS_API_TOKEN}"
caddy.import: common-log whoami.example.com
And this causes the following error:
INF ts=1717112981.3718338 logger=docker-proxy msg=Process Caddyfile logs=[ERROR] Removing invalid block: parsing caddyfile tokens for 'log': unrecognized subdirective request>headers>Cookie, at Caddyfile:12 import chain ['Caddyfile:104 (import common-log)']
whoami.example.com {
import common-log whoami.example.com
reverse_proxy 172.19.0.15:80
tls {
dns cloudflare {env.CF_DNS_API_TOKEN}
}
}
I've copied and pasted this exact generated Caddyfile extract into a base Caddy container, and it seems to run & log requests exactly as expected.
Most likely I am doing something wrong, please point me in the right direction!
Prior to v2.8.0 you had to use a longer form for filters, with a fields
key in between.
log {
format filter {
fields {
request>headers>User-Agent delete
}
}
}
Your config should work as-is if you use the latest version of the image which has just been released ~4 hours ago.
Many thanks Francis, I was just about to report that it is possibly a difference between Caddy v2.8.0, and v2.7.6 which I am using in caddy-docker-proxy.
Super frustrating that the Caddy docs don't seem to support selecting between minor versions to pick these kind of spec changes.