Skip to content

Add log field header fallbacks#13018

Open
bneradt wants to merge 1 commit intoapache:masterfrom
bneradt:log_field_fallback
Open

Add log field header fallbacks#13018
bneradt wants to merge 1 commit intoapache:masterfrom
bneradt:log_field_fallback

Conversation

@bneradt
Copy link
Contributor

@bneradt bneradt commented Mar 23, 2026

Allow custom log formats to fall back between header fields with
?: so configs can log a secondary header when the primary one is
absent. This keeps the feature in the existing %<...> syntax and
preserves the current distinction between missing and empty values.

Store fallback chains as a single log field so the selected header
still uses normal escaping and its own slice settings. Update the
logging admin guide and extend the logging AuTest coverage for
primary, secondary, and missing header cases.

Allow custom log formats to fall back between header fields with
`?:` so configs can log a secondary header when the primary one is
absent. This keeps the feature in the existing `%<...>` syntax and
preserves the current distinction between missing and empty values.

Store fallback chains as a single log field so the selected header
still uses normal escaping and its own slice settings. Update the
logging admin guide and extend the logging AuTest coverage for
primary, secondary, and missing header cases.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for chaining HTTP header log fields with a fallback operator (?:) inside the existing %<{...}...> header-field syntax, so custom log formats can use a secondary header when the primary one is absent while preserving the “missing vs empty” behavior.

Changes:

  • Add parsing and runtime support for header-field fallback chains (e.g. %<{a}cqh?:{b}cqh>), storing the chain as a single LogField.
  • Extend logging marshalling/unmarshalling to select the first present header at runtime and apply per-candidate slicing/escaping.
  • Update admin documentation and extend AuTest coverage/gold output for primary/secondary/missing header cases.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/proxy/logging/LogFormat.cc Parses ?: fallback chains and constructs a single LogField representing the chain.
include/proxy/logging/LogField.h Adds HeaderField representation and LogField constructor/helpers for fallback chains.
src/proxy/logging/LogField.cc Implements fallback selection + marshal/unmarshal behavior using the chosen candidate’s slice/escaping.
include/proxy/logging/LogAccess.h Adds has_http_header_field() API used to decide which candidate is present.
src/proxy/logging/LogAccess.cc Implements header_for_container() mapping and has_http_header_field() lookup logic.
tests/gold_tests/logging/log-field.test.py Extends the test to send primary/secondary headers and validate fallback behavior.
tests/gold_tests/logging/gold/field-test.gold Updates expected log output to include the new Request-ID field and fallback results.
doc/admin-guide/logging/formatting.en.rst Documents header fallback chain syntax, semantics, and per-candidate slicing.

not contain a value).
into your log entry (or ``-`` if no such header was present).

Header fields can also be chained with a fallback operator, `?:`, when you want
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inline markup for the fallback operator uses single backticks (?:), which in reStructuredText is interpreted text and can render unexpectedly / trigger Sphinx warnings. Use a literal (double-backtick) inline code block (?:) for consistency with the surrounding literals (e.g., -).

Suggested change
Header fields can also be chained with a fallback operator, `?:`, when you want
Header fields can also be chained with a fallback operator, ``?:``, when you want

Copilot uses AI. Check for mistakes.
@bryancall bryancall requested a review from serrislew March 23, 2026 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants