Skip to content

Add log field fallbacks#13018

Open
bneradt wants to merge 2 commits intoapache:masterfrom
bneradt:log_field_fallback
Open

Add log field fallbacks#13018
bneradt wants to merge 2 commits intoapache:masterfrom
bneradt:log_field_fallback

Conversation

@bneradt
Copy link
Copy Markdown
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.

Copy link
Copy Markdown
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.

@bryancall bryancall requested a review from serrislew March 23, 2026 22:16
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.
This also allows overriding the default static fallback from `-` to
some user-specified quoted string literal.
@bneradt bneradt force-pushed the log_field_fallback branch from 6e96396 to 373cc22 Compare March 31, 2026 22:50
@zwoop zwoop self-requested a review March 31, 2026 23:26
zwoop
zwoop previously approved these changes Apr 1, 2026
Copy link
Copy Markdown
Contributor

@zwoop zwoop left a comment

Choose a reason for hiding this comment

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

Yeah, looks good. I'm ok deferring "general log tag support" for future additions. One could imagine for example a logging of X-Client-IP with a fallback to the connection remote IP log field.

like

Client-IP:%<{X-Client-IP}cqh??chi>

or some such.

@bneradt bneradt requested a review from zwoop April 2, 2026 21:10
@bneradt bneradt changed the title Add log field header fallbacks Add log field fallbacks Apr 2, 2026
zwoop
zwoop previously approved these changes Apr 2, 2026

if (parsed->fallback_symbol.has_value()) {
std::string fallback_symbol = *parsed->fallback_symbol;
std::string field_symbol = fallback_symbol;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we really need two copies here for the string?

The previous header fallback implementation only allowed
header fields in the chain. This adds support for a final
non-header log field (e.g., chi, cqup) as the fallback
term, letting users write expressions like
%<{x-remote-ip}cqh??chi>.

Rename LogHeaderFallback to LogFieldFallback to reflect the
broader scope. Update documentation, unit tests, and the
end-to-end autest.
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.

4 participants