Logging variable in request


#1

I’m currently using vcl_log to log values from vcl_recv. I basically create an HTTP header (e.g. set req.http.X-Foo-Bar = value;) in vcl_recv and then read it in vcl_log while generating the log message. The problem with this approach is that you can bloat the request sent to the origin since now those headers are included in the request.

Is there a way better way to log stuff from vcl_recv without the need to create a useless HTTP header?


#2

Hi @alex,

Two ways you can do this:

  1. Set req.http.SOMETHING in recv, unset the header in miss and pass, once it has been transferred onto bereq, ie. unset bereq.http.SOMETHING, which will preserve the req.http version for later inspection in vcl_log.
  2. Emit your log event directly from recv, using an explicit log statement. You can emit log data from any VCL function, not just vcl_log.

#3

Thanks a lot, @triblondon!

Went for option 1 since I guess logging in vcl_recv and vcl_recv for the same request would produce 2 logs entries.