Open
Conversation
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.
Contributor
There was a problem hiding this comment.
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 singleLogField. - 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 |
There was a problem hiding this comment.
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Allow custom log formats to fall back between header fields with
?:so configs can log a secondary header when the primary one isabsent. This keeps the feature in the existing
%<...>syntax andpreserves 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.