]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: log: skip custom logformat_node name if empty
authorAurelien DARRAGON <adarragon@haproxy.com>
Thu, 25 Apr 2024 07:50:14 +0000 (09:50 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Fri, 26 Apr 2024 16:39:31 +0000 (18:39 +0200)
Reminder:

Since 3.0-dev4, we can optionally give a name to logformat nodes:

  log-format "%(custom_name1)B %(custom_name2)[str(value)]"

But we may also optionally set the expected node type by appending
':type' after the name, type being either sint,str or bool, like this:

  log-format "%(string_as_int:sint)[str(14)]"

However, it is currently not possible to provide a type without providing
a name that is a least 1 char long. But it could be useful to provide a
type without setting a name, like this, for typecasting purposes only:

  log-format "%(:sint)[bool(true)]"

Thus in order to allow this usage, don't set node->name if node name is
not at least 1 character long. By doing so, node->name will remain NULL
and will not be considered, but the typecast setting will.

src/log.c

index 4abe30c9694e37ed46b7a7506f6970ad8b24e8d3..32da3f706c6dc0151f3797794348aaa97ccf143d 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -421,7 +421,7 @@ static int parse_logformat_tag(char *arg, int arg_len, char *name, int name_len,
                        node->type = LOG_FMT_TAG;
                        node->tag = &logformat_tags[j];
                        node->typecast = typecast;
-                       if (name)
+                       if (name && name_len)
                                node->name = my_strndup(name, name_len);
                        node->options = lf_expr->nodes.options;
                        if (arg_len) {
@@ -523,7 +523,7 @@ static int add_sample_to_logformat_list(char *text, char *name, int name_len, in
                memprintf(err, "out of memory error");
                goto error_free;
        }
-       if (name)
+       if (name && name_len)
                node->name = my_strndup(name, name_len);
        node->type = LOG_FMT_EXPR;
        node->typecast = typecast;