varnishncsa -F flag custom log format

Daniel Carrillo daniel.carrillo at gmail.com
Sun May 27 12:29:14 CEST 2012


2012/5/26 Rowan @ Jetboy <rowan at jetboy.co.uk>:
> Running Varnish 3.02 rev. cbf1284 on Ubuntu Server 12.04 LTS x64:
>
>
>
> I can get varnishncsa writing to logs successfully with:
>
>
>
> VARNISHNCSA_ENABLED=1
>
> DAEMON_OPTS="-a \
>
>              -c \
>
>              -D \
>
>              -P ${PIDFILE} \
>
>              -w /var/log/varnish/hollywood.varnishncsa.log"
>
>
>
> in /etc/default/varnishncsa
>
>
>
> but I'm really struggling with the -F flag for custom log formats. I'm
> trying to achieve an Apache combined log format prefixed by the virtual
> host, which'd look something like this:
>
>
>
> %{Host}i %h %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-agent}i\"
>
>
>
> but all I'm managing to do is capture the %{Host}i bit in the logfile.
>
>
>
> There's an old thread on here about issues with spaces and escaping quotes,
> but the responses are all about setting the format on the command line,
> which I'm really trying to avoid. I've got to:
>
>
>
> VARNISHNCSA_ENABLED=1
>
> FORMAT="%{Host}i %h %l %u %t \"%r\" %s %b \"%{Referer}i\"
> \"%{User-agent}i\""
>
> DAEMON_OPTS="-a \
>
>              -c \
>
>              -D \
>
>              -F ${FORMAT} \
>
>              -P ${PIDFILE} \
>
>              -w /var/log/varnish/hollywood.varnishncsa.log"
>
>
>
> I've tried various permutations of single and double quotes, and the format
> both in and out of a variable. No luck so far. Can anyone help me out?

This one works for me:

LOG_FORMAT="%h %l %u %t \"%r\" %s %b \"%{Referer}i\"
\"%{User-agent}i\" %{Host}i %{Varnish:time_firstbyte}x"
DAEMON_OPTS="-c -a -w $logfile -D -P $pidfile -F '${LOG_FORMAT}'"

Please, note the single quotes in -F

Hope this help.



More information about the varnish-misc mailing list