I found another way to modify logging to be able to log the data I need.
E.g.
Configure in the frontend
log-format “${HAPROXY_HTTP_LOG_FMT} limit:%{+Q}[var(txn.test)] agent:%{+Q}[var(txn.ua)] backend:%{+Q}[var(txn.back)] path:%{+Q}[var(txn.path)]”
Then use the next statement in the frontend or the backend.
http-request set-var(txn.ua) hdr(user-agent)