]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
write_log plugin: remove trailing newlines in the Graphite format.
authorFlorian Forster <octo@google.com>
Fri, 1 Dec 2023 10:31:58 +0000 (11:31 +0100)
committerFlorian Forster <octo@google.com>
Fri, 1 Dec 2023 10:31:58 +0000 (11:31 +0100)
The `INFO()` log macro will add a newline, which was leading to empty lines
being printed.

src/write_log.c

index 31183ebbf5d4e79c10301cca72f85ac34149c340..dc01d097cc850d84c338b29f40cc14aa71827611 100644 (file)
@@ -55,10 +55,17 @@ static int wl_write_graphite(metric_family_t const *fam) {
     int status = format_graphite(&buf, m, prefix, suffix, escape_char, flags);
     if (status != 0) {
       ERROR("write_log plugin: format_graphite failed: %d", status);
-    } else {
-      INFO("%s", buf.ptr);
+      strbuf_reset(&buf);
+      continue;
+    }
+
+    /* trim newlines emitted by format_graphite() */
+    while (buf.pos > 0 && isspace(buf.ptr[buf.pos-1])) {
+      buf.pos--;
+      buf.ptr[buf.pos] = 0;
     }
 
+    INFO("%s", buf.ptr);
     strbuf_reset(&buf);
   }