]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: log: make log-format expressions completely usable outside of req/resp
authorWilly Tarreau <w@1wt.eu>
Fri, 3 Sep 2021 06:53:29 +0000 (08:53 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 3 Sep 2021 09:01:48 +0000 (11:01 +0200)
The log-format strings are usable at plenty of places, but the expressions
using %[] were restricted to request or response context and nothing else.
This prevents from using them from the config context or the CLI, let's
relax this.

src/log.c

index 18040627ec97f293430d9d0483187827765c49c5..5cae18293d9eb2e9cde871f6a7cd688d8e00b804 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -2075,8 +2075,13 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t
                                key = NULL;
                                if (tmp->options & LOG_OPT_REQ_CAP)
                                        key = sample_fetch_as_type(be, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, tmp->expr, SMP_T_STR);
+
                                if (!key && (tmp->options & LOG_OPT_RES_CAP))
                                        key = sample_fetch_as_type(be, sess, s, SMP_OPT_DIR_RES|SMP_OPT_FINAL, tmp->expr, SMP_T_STR);
+
+                               if (!key && !(tmp->options & (LOG_OPT_REQ_CAP|LOG_OPT_RES_CAP))) // cfg, cli
+                                       key = sample_fetch_as_type(be, sess, s, SMP_OPT_FINAL, tmp->expr, SMP_T_STR);
+
                                if (tmp->options & LOG_OPT_HTTP)
                                        ret = lf_encode_chunk(tmplog, dst + maxsize,
                                                              '%', http_encode_map, key ? &key->data.u.str : &empty, tmp);