BUG/MEDIUM: log: don't ignore disabled node's options

In 3f2e8d0ed ("MEDIUM: log: lf_* build helpers now take a ctx argument")
I made a mistake, because starting with this commit it is no longer
possible from a node to disable global logformat options.
The result is that when an option is set globally, it cannot be disabled
anymore.

For instance, it is not possible to do this anymore:
  log-format "%{+X}o %{-X}Ts"

The original intent was to prevent encoding options from being
disabled once enabled globally, because when encoding is enabled globally
we start the object enumeration right away (ie: in CBOR and JSON we
announce dynamic map, and for each node we announce the key..), thus it
doesn't make sense to mix encoding types there, unless encoding is only
used per-node, in which case only the value gets encoded, thus it remains
possible to print a value in JSON/CBOR-compatible format while the next
one shouldn't be printed as-is.

Thus, to restore the original behavior, slightly change the logic in
lf_buildctx_prepare() so that only global encoding options take the
precedence over node's options (instead of all options).

No backport needed.
This commit is contained in:
Aurelien DARRAGON 2024-04-30 17:52:44 +02:00
parent 41d7e82e0f
commit 12d08cf912

View File

@ -1814,25 +1814,29 @@ static inline void lf_buildctx_prepare(struct lf_buildctx *ctx,
int g_options,
const struct logformat_node *node)
{
ctx->options = g_options;
ctx->typecast = SMP_T_SAME; /* default */
if (node) {
/* per-node options are only considered if not already set
* globally
/* per-node encoding options cannot be disabled if already
* enabled globally
*
* Also, ignore LOG_OPT_BIN since it is a global-only option
*
* Finally, ensure we don't mix encoding types, global setting
* Also, ensure we don't mix encoding types, global setting
* prevails over per-node one.
*
* Finally, ignore LOG_OPT_BIN since it is a global-only option
*/
if (g_options & LOG_OPT_ENCODE)
if (g_options & LOG_OPT_ENCODE) {
ctx->options = (g_options & LOG_OPT_ENCODE);
ctx->options |= (node->options & ~(LOG_OPT_BIN | LOG_OPT_ENCODE));
}
else
ctx->options |= (node->options & ~LOG_OPT_BIN);
ctx->options = (node->options & ~LOG_OPT_BIN);
/* consider node's typecast setting */
ctx->typecast = node->typecast;
}
else {
ctx->options = g_options;
ctx->typecast = SMP_T_SAME; /* default */
}
/* encoding is incompatible with HTTP option, so it is ignored
* if HTTP option is set