Skip to content

Instantly share code, notes, and snippets.

@haproxytechblog
Last active October 16, 2019 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haproxytechblog/fd1b3691893183dac7151c213fc9950d to your computer and use it in GitHub Desktop.
Save haproxytechblog/fd1b3691893183dac7151c213fc9950d to your computer and use it in GitHub Desktop.
HAProxy Log Customization
defaults
log-format "<format-string>"
log-format "%{+Q}r"
# Outputs: "GET / HTTP/1.1"
log-format "%{+X}Ts"
# Outputs: 5C5342A0
log-format "%{+E}HQ"
# Outputs: ?myparam=[some_brackets\]
log-format "%{+E,+Q}HQ"
# Outputs: "?myparam=[some_brackets\]"
log-format "%ci:%cp [%t] %ft %b/%s %Tw/%Tc/%Tt %B %ts %ac/%fc/%bc/%sc/%rc %sq/%bq"
log-format "%ci:%cp [%tr] %ft %b/%s %TR/%Tw/%Tc/%Tr/%Ta %ST %B %CC %CS %tsc %ac/%fc/%bc/%sc/%rc %sq/%bq %hr %hs %{+Q}r"
log-format "%{+Q}o %{-Q}ci - - [%trg] %r %ST %B \"\" \"\" %cp %ms %ft %b %s %TR %Tw %Tc %Tr %Ta %tsc %ac %fc %bc %sc %rc %sq %bq %CC %CS %hrl %hsl"
log-format "%ci:%cp %si:%sp %HU %ST"
# Outputs: 192.168.50.1:56428 127.0.0.1:80 / 304
log-format "%{+Q}o\ client_address = %ci, client_port = %cp, server_address = %si, server_port = %sp path, = %HU, status = %ST"
# Outputs: client_address = "192.168.50.1", client_port = 56479, server_address = "127.0.0.1", server_port = 8080, path = "/", status = 304
http-request capture req.hdr(Host) len 10
http-request capture req.hdr(Cookie) len 20
log-format "%[capture.req.hdr(0)] %{+Q}[capture.req.hdr(1)]"
# Outputs: example.com "MyCookie=abc123"
http-request set-var(txn.MyVar) str("My Value")
log-format "%{+Q}[var(txn.MyVar)]"
# Outputs: "My Value"
log-format "%ci:%cp [%tr] %ft %b/%s %TR/%Tw/%Tc/%Tr/%Ta %ST %B %CC %CS %tsc %ac/%fc/%bc/%sc/%rc %sq/%bq %hr %hs %{+Q}r %[http_first_req]"
# Outputs: 192.168.50.1:53547 [16/Oct/2019:13:52:09.226] fe_main be_servers/s1 0/0/1/2/3 200 465 - - ---- 2/1/0/0/0 0/0 "GET / HTTP/1.1" 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment