I'm using Varnish 3.0.2 on a Debian Wheezy system. I'd like to be able to set custom headers and have their contents appear in the request logs. However, although I know the headers are being set and passed to the back end, their contents don't seem to be visible to varnishncsa
.
In my vcl_recv
I have
set req.http.X-my-header = "blahblah";
and, for testing, this is my custom format string for varnishncsa
:
'%{X-my-header}i'
I should see blahblah
in the log for each request. However, all I get is -
. It seems that my header isn't being passed through to varnishncsa
.
How can I include my custom headers in my logs?
I just ran into this issue and this was the top result when searching for it, so I'll post my solution/workaround here for future reference :)
varnishncsa
can log values set bystd.log("key:value")
in VCL 1. I used this to log my custom header. Using your example, add this in yourvcl_recv
:Then use the following somewhere in your logformat string for
varnishncsa
(mind the x in stead of the i after the header name):I think there's a bug in Varnish Book when it comes to explaining how to log headers. Try this: