Varnishlog: show the hash() data in output

Image of Mattias Geniar

Mattias Geniar, April 03, 2018

Follow me on Twitter as @mattiasgeniar

Since Varnish 4.x and later, the default varnishlog output doesn’t show the vcl_hash() data anymore.

Your varnishlog will look like this:

-   VCL_call       HASH
-   VCL_return     lookup
-   Hit            103841868
-   VCL_call       HIT
-   VCL_return     deliver

If you’re debugging, this isn’t very useful.

To include the “old” behaviour of Varnish and add all the hash elements as well, start Varnish with the following extra parameter:

-p vsl_mask=+Hash

After a Varnish restart, this will procedure varnishlog output like this:

-   VCL_call       HASH
-   Hash           "/images/path/to/file.jpg%00"
-   Hash           "http%00"
-   Hash           "www.yoursite.tld%00"
-   Hash           "/images/path/to/file.jpg%00"
-   Hash           "www.yoursite.tld%00"
-   VCL_return     lookup
-   VCL_call       MISS

In this example, the hash included:

hash_data(req.url);
hash_data(req.http.X-Forwarded-Proto);
hash_data(req.http.host);
hash_data(req.http.Cookie);

The %00 are null characters to prevent cache-conflicts in case you have hash('123'); hash('456); vs. hash('1'); hash('23456');.



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.