zwoop commented on code in PR #13018:
URL: https://github.com/apache/trafficserver/pull/13018#discussion_r3030427518


##########
doc/admin-guide/logging/formatting.en.rst:
##########
@@ -314,8 +314,54 @@ prior to the log field's name, as so::
     Format = '%<{User-agent}cqh>'
 
 The above would insert the User Agent string from the client request headers
-into your log entry (or a blank string if no such header was present, or it did
-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
+the log to use the first header that exists among n headers. For example::
+
+    Format = '%<{x-primary-id}cqh??{x-secondary-id}cqh??{x-tertiary-id}cqh>'
+
+|TS| evaluates the candidates from left to right and logs the first header that
+exists. If none of the headers exist, |TS| logs ``-`` by default. A header that
+exists but has an empty value is considered present, so |TS| logs the empty
+value instead of falling back. So in the example above, the value of
+x-primary-id of the client request is logged if it exists, otherwise the value
+of x-secondary-id is logged if it exists, otherwise ``-`` is logged if neither
+of the headers is present.
+
+The final log field in the chain can be a non-header log field whose value
+specifies the final fallback in the chian. This symbol is used only after all

Review Comment:
   Typo, chian -> chain



##########
src/proxy/logging/LogFormat.cc:
##########
@@ -475,6 +501,41 @@ LogFormat::parse_symbol_string(const char *symbol_string, 
LogFieldList *field_li
              "')' in %s",
              symbol);
       }
+    } else if (LogFieldFallback::has_fallback(symbol)) {
+      Dbg(dbg_ctl_log_format, "Field fallback symbol: %s", symbol);
+      std::string parse_error;
+      auto        parsed = LogFieldFallback::parse(symbol, parse_error);
+      if (parsed.has_value()) {
+        std::unique_ptr<LogField> fallback_field;
+        bool                      valid_fallback = true;
+
+        if (parsed->fallback_symbol.has_value()) {
+          std::string fallback_symbol = *parsed->fallback_symbol;
+          std::string field_symbol    = fallback_symbol;

Review Comment:
   Do we really need two copies here for the string?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to