Access Logs - pass custom headers

Hi There!

Does anyone know how to pass custom headers to the Traefik access log? The doc says I can apply customised CLF format. But it doesn't seem that I can inject custom headers into the log. I'd like to pass CF-IPCountry and CF-IPCity from Cloudflare to the traefik logs for further processing by Elastic. In Nginx I can define a variable by passing any Header value to it. And then define custom log format with that variable.

And BTW, I haven't even tried yet If I can force Traefik to pass any headers other than X-Forwarded...

I would interpret the docs that you can only add fields to the JSON format, guess you need to try.

@bluepuma77 there's a predefined list of headers that you can 'keep'. Don't think I can put anything else there.

You could keep the headers in JSON and use something like jq to format it to CLF on the fly.

@bluepuma77 the issue is not about the format. But rather about what you can place in there. I don't seem to find a way to include headers other than those mentioned in the "Available Fields" list.

Our config seems to keep all headers:

accesslog:
  filepath: /var/log/traefik-access.log
  bufferingsize: 10
  format: json
  fields:
    defaultmode: keep
    headers:
      defaultmode: keep
1 Like