MINOR: log: postpone conversion for sample expressions in sess_build_logline()

In sess_build_logline(), for sample expression nodes, instead of directly
calling sample_fetch_as_type(... SMP_T_STR), let's first process the
sample using sample_process(), and then proceed with the conversion to
str if required.

Doing so will allow us to implement type casting and preserving logic.
This commit is contained in:
Aurelien DARRAGON 2024-04-25 16:20:11 +02:00
parent 84963fb743
commit fb8b47fed8

View File

@ -3218,15 +3218,23 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t
break;
case LOG_FMT_EXPR: // sample expression, may be request or response
{
int type;
key = NULL;
if (ctx.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);
key = sample_process(be, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, tmp->expr, NULL);
if (!key && (ctx.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);
key = sample_process(be, sess, s, SMP_OPT_DIR_RES|SMP_OPT_FINAL, tmp->expr, NULL);
if (!key && !(ctx.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);
key = sample_process(be, sess, s, SMP_OPT_FINAL, tmp->expr, NULL);
type = SMP_T_STR; // default
if (key && !sample_convert(key, type))
key = NULL;
if (ctx.options & LOG_OPT_HTTP)
ret = lf_encode_chunk(tmplog, dst + maxsize,
@ -3241,6 +3249,7 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t
goto out;
tmplog = ret;
break;
}
}
if (tmp->type != LOG_FMT_TAG)