From cebb1249aa81acd98581dac0c016807fe0fce01f Mon Sep 17 00:00:00 2001 From: Ian Barwick Date: Tue, 25 Feb 2020 15:25:59 +0900 Subject: [PATCH] Convert printed "WARNING" messages to logging output In a couple of places ("cluster show" and "service status") we printed connection status errors as a "WARNING" to stdout, followed by a log HINT, but the latter was ineffective unless the configured log level happened to match the level of the most recently emitted log line (which will most likely be DEBUG). Convert the printed WARNING lines to an actual log WARNING, to make the behaviour of this output behave as expected. --- repmgr-action-cluster.c | 17 ++++++++++++++--- repmgr-action-service.c | 15 +++++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/repmgr-action-cluster.c b/repmgr-action-cluster.c index b4de8721..2c81a5fd 100644 --- a/repmgr-action-cluster.c +++ b/repmgr-action-cluster.c @@ -336,14 +336,25 @@ do_cluster_show(void) /* emit any warnings */ if (warnings.head != NULL && runtime_options.terse == false && runtime_options.output_mode != OM_CSV) { - ItemListCell *cell = NULL; - printf(_("\nWARNING: following issues were detected\n")); + ItemListCell *cell = NULL; + PQExpBufferData warning; + + initPQExpBuffer(&warning); + + appendPQExpBufferStr(&warning, + _("following issues were detected\n")); for (cell = warnings.head; cell; cell = cell->next) { - printf(_(" - %s\n"), cell->string); + appendPQExpBuffer(&warning, + _(" - %s\n"), cell->string); } + puts(""); + log_warning("%s", warning.data); + + termPQExpBuffer(&warning); + if (runtime_options.verbose == false && connection_error_found == true) { log_hint(_("execute with --verbose option to see connection error messages")); diff --git a/repmgr-action-service.c b/repmgr-action-service.c index f8f537e1..b8ea46a1 100644 --- a/repmgr-action-service.c +++ b/repmgr-action-service.c @@ -357,11 +357,22 @@ do_service_status(void) { ItemListCell *cell = NULL; - printf(_("\nWARNING: following issues were detected\n")); + PQExpBufferData warning; + + initPQExpBuffer(&warning); + + appendPQExpBufferStr(&warning, + _("following issues were detected\n")); + for (cell = warnings.head; cell; cell = cell->next) { - printf(_(" - %s\n"), cell->string); + appendPQExpBuffer(&warning, + _(" - %s\n"), cell->string); } + puts(""); + log_warning("%s", warning.data); + + termPQExpBuffer(&warning); if (runtime_options.verbose == false && connection_error_found == true) {