Avoiding "(null)" in log output for unset VCL variable


#1

In my log format string, I am using a VCL variable like resp.http.X-Foo. If that header is not set, (null) is output. To make parsing easier, I’d prefer if an empty string were output instead. Is that possible?


#2

I just came across the if() Fastly VCL extension. Could that be used here?

https://docs.fastly.com/guides/vcl/miscellaneous-VCL-extensions#if


#3

Hi Joe,

Yep! This would be a great scenario to use the if() extension.

You can add that directly into your logging format string, so it would look something like this:
%h %l %u %t %r %>s if(resp.http.X-Foo, resp.http.X-Foo, "")

Hopefully that helps!