Separate log-format for tcp and http on hybrid frontend

Custom log-format option can be set per frontend basis, but acceptable format variables depends on mode.
For tcp frontends with ability to upgrade to http (either by tcp-request content switch-mode http or by choosing http backend) only single log-format allowed with no http-specific varables (%tr, %Ta…).

So far my solution is to use universal tcp-specific log-format with attempt to emulate http-specific items by variables:

frontend fe
    mode tcp

    # HTTP specific format example (disallowed)
    log-format "%tr %f %b/%s %ci:%cp %fi:%fp %TR/%Tw/%Tc/%Tr/%Ta %ac/%fc/%bc/%sc/%rc %sq/%bq %U|%B %ts %ST %HV %HM %HU"
    # [not] universal format example
    log-format "%t %f %b/%s %ci:%cp %fi:%fp -/%Tw/%Tc/-/%Tt %ac/%fc/%bc/%sc/%rc %sq/%bq %U|%B %ts %[var(txn.status_code)] %[var(txn.proto)] %[var(txn.method)] %[var(txn.uri)]"

    tcp-request content switch-mode http if HTTP
    # For non-http protocols these vars set by lua
    http-after-response set-var(txn.status_code) status
    http-after-response set-var(txn.proto) capture.req.ver
    http-after-response set-var(txn.method) capture.req.method
    http-after-response set-var(txn.uri) capture.req.uri

    use_backend be-http if HTTP
    default_backend be-tcp

Still I’ve not found a way to set txn. variables to the exact value of log format vars, e.g. construction like this does not work:

    http-after-response set-var( %tr

Is it better way to support http-specific log-format for hybrid tcp backend?

1 Like