wiki:VCLExampleSyslog

To log to syslog in VCL, you can simply use:

	C{
		#include <syslog.h>
        }C

        sub vcl_something {
                C{
		        syslog(LOG_INFO, "Something happened at VCL line XX.");
	        }C
        }

Notice that the #include cannot be done inside a VCL function.

Another example that uses VCL variables:

	C{
		syslog(LOG_ERR, "Spurious response from backend: xid %s request %s %s \"%s\" %d \"%s\" \"%s\"", VRT_r_req_xid(sp), VRT_r_req_request(sp), VRT_GetHdr(sp, HDR_REQ, "\005host:"), VRT_r_req_url(sp), VRT_r_obj_status(sp), VRT_r_obj_response(sp), VRT_GetHdr(sp, HDR_OBJ, "\011Location:"));
	}C

To find the C variable names used in VCL, simply run varnishd -C -f <yourvclfile> (ie: varnishd -C -f /etc/varnish/default.vcl).