From: Florian Forster Date: Fri, 1 Dec 2023 10:31:58 +0000 (+0100) Subject: write_log plugin: remove trailing newlines in the Graphite format. X-Git-Tag: 6.0.0-rc0~41^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dcd1a7498fb9a3d864e37c0add3a10b378136619;p=thirdparty%2Fcollectd.git write_log plugin: remove trailing newlines in the Graphite format. The `INFO()` log macro will add a newline, which was leading to empty lines being printed. --- diff --git a/src/write_log.c b/src/write_log.c index 31183ebbf..dc01d097c 100644 --- a/src/write_log.c +++ b/src/write_log.c @@ -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); }