Haproxy not logging captured request headers with custom log format

Earlier i was not specifying a custom log format, and the captured request headers were getting printed fine. I wanted to log the unique-id-header, but could not find any way of doing so. So i copy pasted the log-format mentioned on http://haproxy.1wt.eu/download/1.5/doc/configuration.txt, and unique id started getting logged.

Unfortunately, now the captured request headers are not getting logged. The %hrl and %hsl are coming out as empty strings.

Very weird. Here is my config, plzz help :(

listen server
  bind *:80
  mode http

  option  httplog
  option  http-server-close
  no option logasap   # disable early logging of HTTP requests so that total transfer time is logged
  option  forwardfor
  capture request  header    X-Forwarded-For      len 500 
  capture request  header    Host                 len 500 
  capture request  header    X-Request-UID        len 500 
  rspadd  X-Haproxy-Backend:\ server

  # Generate the X-Haproxy-Unique-ID and log it to make it easy to track requests
  log-format %Ci:%Cp\ [id=%ID]\ [%t]\ %f\ %b/%s\ %Tq/%Tw/%Tc/%Tr/%Tt\ %st\ %B\ %cc\ %cs\ %tsc\ %ac/%fc/%bc/%sc/%rc\ %sq/%bq\ {%hrl}\ {%hsl}\ %{+Q}r
  unique-id-format %{+X}o\ %Ci:%Cp_%Fi:%Fp_%Ts_%rt:%pid
  unique-id-header X-Haproxy-Unique-ID

Here is the log i see:

Sep 13 17:28:57 localhost haproxy[11979]: 10.161.27.218:41592 
[id=0AA11BDA:A278_0AA15B71:0050_505217C5_0014:2ECB] [13/Sep/2012:17:28:37.567]
 server www-example-com-healthz/- 19998/0/2/1/+20001 200 +326
 - - ---- 10/10/1/1/0 0/0 {} {} 
"GET /testing/healthz?merchant=www.example.com&source=elb HTTP/1.1"

Note that %hrl and %hsl are empty strings :( How do i capture the request headers ??


Solution 1:

by default, this fields will show empty in the logs. In order to log headers and cookies, the capture parameters must be set in the frontend.

Here is how we can capture headers sent by the client in the HTTP request.

capture request header Referrer len 64
capture request header Content-Length len 10
capture request header User-Agent len 64

Solution 2:

Updated config, since some values are deprecated

    capture request  header    X-Request-UID        len 500
    #Generate the X-Haproxy-Unique-ID and log it to make it easy to track requests
    log-format %ci:%cp\ [id=%ID]\ [%t]\ %f\ %b/%s\ %Tq/%Tw/%Tc/%Tr/%Tt\ %ST\ %B\ %CC\ %CS\ %tsc\ %ac/%fc/%bc/%sc/%rc\ %sq/%bq\ {%hrl}\ {%hsl}\ %{+Q}r
    unique-id-format %{+X}o\ %ci:%cp_%fi:%fp_%Ts_%rt:%pid
    unique-id-header X-Haproxy-Unique-ID