diff --git a/HISTORY b/HISTORY index fb643deb..1c826f02 100644 --- a/HISTORY +++ b/HISTORY @@ -8,6 +8,7 @@ repmgr: "node check" and "node status" returns non-zero value if an issue encountered (Ian) repmgr: add CSV output mode to "cluster event"; GitHub #471 (Ian) + repmgr: add -q/--quiet option to suppress non-error output; GitHub #468 (Ian) repmgr: "node status" returns non-zero value if an issue encountered (Ian) repmgrd: create a PID file by default; GitHub #457 (Ian) repmgrd: daemonize process by default; GitHub #458 (Ian) diff --git a/doc/appendix-release-notes.sgml b/doc/appendix-release-notes.sgml index 63f147eb..16f1c737 100644 --- a/doc/appendix-release-notes.sgml +++ b/doc/appendix-release-notes.sgml @@ -66,6 +66,13 @@ + + + repmgr: add option to suppress non-error + output. (GitHub #468). + + + repmgr cluster show, diff --git a/log.c b/log.c index afaf02be..cff3b946 100644 --- a/log.c +++ b/log.c @@ -329,6 +329,13 @@ logger_set_terse(void) } +void +logger_set_level(int new_log_level) +{ + log_level = new_log_level; +} + + void logger_set_min_level(int min_log_level) { @@ -336,6 +343,7 @@ logger_set_min_level(int min_log_level) log_level = min_log_level; } + int detect_log_level(const char *level) { diff --git a/log.h b/log.h index fa232656..df6b89d4 100644 --- a/log.h +++ b/log.h @@ -129,6 +129,7 @@ bool logger_shutdown(void); void logger_set_verbose(void); void logger_set_terse(void); void logger_set_min_level(int min_log_level); +void logger_set_level(int new_log_level); void log_detail(const char *fmt,...) diff --git a/repmgr-client-global.h b/repmgr-client-global.h index 767d7ec4..6b20f9d9 100644 --- a/repmgr-client-global.h +++ b/repmgr-client-global.h @@ -47,6 +47,7 @@ typedef struct /* logging options */ char log_level[MAXLEN]; /* overrides setting in repmgr.conf */ bool log_to_file; + bool quiet; bool terse; bool verbose; @@ -138,7 +139,7 @@ typedef struct /* general configuration options */ \ "", false, false, "", false, false, \ /* logging options */ \ - "", false, false, false, \ + "", false, false, false, false, \ /* output options */ \ false, false, false, \ /* database connection options */ \ diff --git a/repmgr-client.c b/repmgr-client.c index 3bd82b64..8b620dac 100644 --- a/repmgr-client.c +++ b/repmgr-client.c @@ -182,7 +182,7 @@ main(int argc, char **argv) /* Make getopt emitting errors */ opterr = 1; - while ((c = getopt_long(argc, argv, "?Vb:f:FwWd:h:p:U:R:S:D:ck:L:tvC:", long_options, + while ((c = getopt_long(argc, argv, "?Vb:f:FwWd:h:p:U:R:S:D:ck:L:qtvC:", long_options, &optindex)) != -1) { /* @@ -574,6 +574,12 @@ main(int argc, char **argv) logger_output_mode = OM_DAEMON; break; + + /* --quiet */ + case 'q': + runtime_options.quiet = true; + break; + /* --terse */ case 't': runtime_options.terse = true; @@ -1116,6 +1122,17 @@ main(int argc, char **argv) logger_set_min_level(LOG_INFO); } + /* + * If -q/--quiet supplied, suppress any non-ERROR log output. + * This overrides everything else; we'll leave it up to the user to deal with the + * consequences of e.g. running --dry-run together with -q/--quiet. + */ + if (runtime_options.quiet == true) + { + logger_set_level(LOG_ERROR); + } + + /* * Node configuration information is not needed for all actions, with @@ -1934,6 +1951,7 @@ do_help(void) printf(_(" --dry-run show what would happen for action, but don't execute it\n")); printf(_(" -L, --log-level set log level (overrides configuration file; default: NOTICE)\n")); printf(_(" --log-to-file log to file (or logging facility) defined in repmgr.conf\n")); + printf(_(" -q, --quiet suppress all log output apart from errors\n")); printf(_(" -t, --terse don't display detail, hints and other non-critical output\n")); printf(_(" -v, --verbose display additional log output (useful for debugging)\n")); diff --git a/repmgr-client.h b/repmgr-client.h index 19d64fb2..714a560c 100644 --- a/repmgr-client.h +++ b/repmgr-client.h @@ -126,6 +126,7 @@ static struct option long_options[] = /* logging options */ {"log-level", required_argument, NULL, 'L'}, {"log-to-file", no_argument, NULL, OPT_LOG_TO_FILE}, + {"quiet", no_argument, NULL, 'q'}, {"terse", no_argument, NULL, 't'}, {"verbose", no_argument, NULL, 'v'},