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


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?


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



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!