From: Eero Tamminen Date: Fri, 15 Dec 2023 18:18:54 +0000 (+0100) Subject: format_json: Move conditional error logging to a separate function. X-Git-Tag: 6.0.0-rc0~18^2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dd1b96b03b5476d71ece4f34717c4dc69a50d9cf;p=thirdparty%2Fcollectd.git format_json: Move conditional error logging to a separate function. This reduces the amount of duplicate code being generated. Co-authored-by: Florian Forster --- diff --git a/src/utils/format_json/open_telemetry.c b/src/utils/format_json/open_telemetry.c index 5f0af1e50..1e45f144a 100644 --- a/src/utils/format_json/open_telemetry.c +++ b/src/utils/format_json/open_telemetry.c @@ -30,13 +30,18 @@ #include +static void log_yajl_gen_error(int line, const char *fname, int status) { + if (strncmp(fname, "yajl_gen_", strlen("yajl_gen_")) != 0) { + return; + } + ERROR("open_telemetry.c:%d: %s failed with status %d", line, fname, status); +} + #define CHECK(f) \ do { \ int status = (f); \ if (status != 0) { \ - if (strncmp(#f, "yajl_gen_", strlen("yajl_gen_")) == 0) { \ - ERROR("format_json: %s failed with status %d", #f, status); \ - } \ + log_yajl_gen_error(__LINE__, #f, status); \ return status; \ } \ } while (0)