MINOR: log: indicate it when some unreliable sample fetches are logged

If a log-format involves some sample fetches that may not be present at
the logging instant, we can now report a warning.

Note that this is done both for log-format and for add-header and carefully
respects the original fetch keyword's capabilities.
diff --git a/include/proto/log.h b/include/proto/log.h
index 08a9a1b..86b4185 100644
--- a/include/proto/log.h
+++ b/include/proto/log.h
@@ -70,7 +70,7 @@
  * Variable name are preceded by % and composed by characters [a-zA-Z0-9]* : %varname
  * You can set arguments using { } : %{many arguments}varname
  */
-void parse_logformat_string(const char *str, struct proxy *curproxy, struct list *list_format, int options);
+void parse_logformat_string(const char *str, struct proxy *curproxy, struct list *list_format, int options, int cap);
 /*
  * Displays the message on stderr with the date and pid. Overrides the quiet
  * mode during startup.
diff --git a/src/cfgparse.c b/src/cfgparse.c
index a0178e6..6b27c24 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -6518,10 +6518,12 @@
 		}
 
 		if (curproxy->logformat_string)
-			parse_logformat_string(curproxy->logformat_string, curproxy, &curproxy->logformat, LOG_OPT_MANDATORY);
+			parse_logformat_string(curproxy->logformat_string, curproxy, &curproxy->logformat, LOG_OPT_MANDATORY,
+					       SMP_VAL_FE_LOG_END);
 
 		if (curproxy->uniqueid_format_string)
-			parse_logformat_string(curproxy->uniqueid_format_string, curproxy, &curproxy->format_unique_id, 0);
+			parse_logformat_string(curproxy->uniqueid_format_string, curproxy, &curproxy->format_unique_id, 0,
+					       (proxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR);
 
 		/* first, we will invert the servers list order */
 		newsrv = NULL;
diff --git a/src/log.c b/src/log.c
index 45cc67e..25dda04 100644
--- a/src/log.c
+++ b/src/log.c
@@ -309,7 +309,7 @@
  * success. At the moment, sample converters are not yet supported but fetch arguments
  * should work.
  */
-void add_sample_to_logformat_list(char *text, char *arg, int arg_len, struct proxy *curpx, struct list *list_format, int options)
+void add_sample_to_logformat_list(char *text, char *arg, int arg_len, struct proxy *curpx, struct list *list_format, int options, int cap)
 {
 	char *cmd[2];
 	struct sample_expr *expr;
@@ -335,12 +335,16 @@
 		node->arg = my_strndup(arg, arg_len);
 		parse_logformat_var_args(node->arg, node);
 	}
-	if (expr->fetch->val & SMP_VAL_REQUEST)
+	if (expr->fetch->val & cap & SMP_VAL_REQUEST)
 		node->options |= LOG_OPT_REQ_CAP; /* fetch method is request-compatible */
 
-	if (expr->fetch->val & SMP_VAL_RESPONSE)
+	if (expr->fetch->val & cap & SMP_VAL_RESPONSE)
 		node->options |= LOG_OPT_RES_CAP; /* fetch method is response-compatible */
 
+	if (!(expr->fetch->val & cap))
+		Warning("log-format: sample fetch <%s> may not be reliably used %s because it needs '%s' which is not available here.\n",
+			text, cap == SMP_VAL_FE_LOG_END ? "with 'log-format'" : "here", sample_src_names(expr->fetch->use));
+
 	/* check if we need to allocate an hdr_idx struct for HTTP parsing */
 	/* Note, we may also need to set curpx->to_log with certain fetches */
 	if (expr->fetch->use & SMP_USE_HTTP_ANY)
@@ -363,8 +367,9 @@
  *  curproxy: the proxy affected
  *  list_format: the destination list
  *  options: LOG_OPT_* to force on every node
+ *  cap: all SMP_VAL_* flags supported by the consumer
  */
-void parse_logformat_string(const char *fmt, struct proxy *curproxy, struct list *list_format, int options)
+void parse_logformat_string(const char *fmt, struct proxy *curproxy, struct list *list_format, int options, int cap)
 {
 	char *sp, *str, *backfmt; /* start pointer for text parts */
 	char *arg = NULL; /* start pointer for args */
@@ -473,7 +478,7 @@
 				parse_logformat_var(arg, arg_len, var, var_len, curproxy, list_format, &options);
 				break;
 			case LF_STEXPR:
-				add_sample_to_logformat_list(var, arg, arg_len, curproxy, list_format, options);
+				add_sample_to_logformat_list(var, arg, arg_len, curproxy, list_format, options, cap);
 				break;
 			case LF_TEXT:
 			case LF_SEPARATOR:
diff --git a/src/proto_http.c b/src/proto_http.c
index 3696557..56d8dd6 100644
--- a/src/proto_http.c
+++ b/src/proto_http.c
@@ -8139,7 +8139,8 @@
 		rule->arg.hdr_add.name = strdup(args[cur_arg]);
 		rule->arg.hdr_add.name_len = strlen(rule->arg.hdr_add.name);
 		LIST_INIT(&rule->arg.hdr_add.fmt);
-		parse_logformat_string(args[cur_arg + 1], proxy, &rule->arg.hdr_add.fmt, 0);
+		parse_logformat_string(args[cur_arg + 1], proxy, &rule->arg.hdr_add.fmt, 0,
+				       (proxy->cap & PR_CAP_FE) ? SMP_VAL_FE_HRQ_HDR : SMP_VAL_BE_HRQ_HDR);
 		cur_arg += 2;
 	} else if (strcmp(args[0], "redirect") == 0) {
 		struct redirect_rule *redir;