Logging Varnish variables to a file

First published on July 31, 2014

Much of the documentation regarding Varnish logging is around varnishlog (makes sense, considering the name), which parses the Varnish request and response logs from system memory. However, what about when you’re building or troubleshooting your VCL configuration file and want to dump specific variables or messages to a file? This is not widely documented but quite easy to do.

The key function is std.syslog. In order to use that function, you simply have to enable the std (standard) Varnish module, which is the only built-in “vmod” and is thus natively available and doesn’t have to be compiled.

To enable the std module, simply put this at the top of your VCL file:

import std;

Then, you can use it in any of the VCL functions like this:

std.syslog( 180, "VARNISH: Invalid cookie found." );

Or, add in some variables to your log message:

std.syslog( 180, "VARNISH: beresp.ttl is " + beresp.ttl );

This will log the message to general system messages log, which is often at /var/log/messages on Linux operating systems. The first parameter, which is 180 in the examples above, is the priority value.


Speak your mind

To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word