diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2022-04-08 14:55:14 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2022-04-08 14:55:14 -0400 |
commit | 9a374b77fb53e4cfbca121e4fa278a7d71bde7c4 (patch) | |
tree | 6591af757bd9df12549279b4b87f01e0ce98bd79 /src/bin/pg_verifybackup/pg_verifybackup.c | |
parent | 5c431c7fb327e1abc70b7a197650f8d45fd5bede (diff) | |
download | postgresql-9a374b77fb53e4cfbca121e4fa278a7d71bde7c4.tar.gz postgresql-9a374b77fb53e4cfbca121e4fa278a7d71bde7c4.zip |
Improve frontend error logging style.
Get rid of the separate "FATAL" log level, as it was applied
so inconsistently as to be meaningless. This mostly involves
s/pg_log_fatal/pg_log_error/g.
Create a macro pg_fatal() to handle the common use-case of
pg_log_error() immediately followed by exit(1). Various
modules had already invented either this or equivalent macros;
standardize on pg_fatal() and apply it where possible.
Invent the ability to add "detail" and "hint" messages to a
frontend message, much as we have long had in the backend.
Except where rewording was needed to convert existing coding
to detail/hint style, I have (mostly) resisted the temptation
to change existing message wording.
Patch by me. Design and patch reviewed at various stages by
Robert Haas, Kyotaro Horiguchi, Peter Eisentraut and
Daniel Gustafsson.
Discussion: https://postgr.es/m/1363732.1636496441@sss.pgh.pa.us
Diffstat (limited to 'src/bin/pg_verifybackup/pg_verifybackup.c')
-rw-r--r-- | src/bin/pg_verifybackup/pg_verifybackup.c | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/src/bin/pg_verifybackup/pg_verifybackup.c b/src/bin/pg_verifybackup/pg_verifybackup.c index 05cb520c117..6671a841502 100644 --- a/src/bin/pg_verifybackup/pg_verifybackup.c +++ b/src/bin/pg_verifybackup/pg_verifybackup.c @@ -252,8 +252,8 @@ main(int argc, char **argv) canonicalize_path(wal_directory); break; default: - fprintf(stderr, _("Try \"%s --help\" for more information.\n"), - progname); + /* getopt_long already emitted a complaint */ + pg_log_error_hint("Try \"%s --help\" for more information.", progname); exit(1); } } @@ -261,9 +261,8 @@ main(int argc, char **argv) /* Get backup directory name */ if (optind >= argc) { - pg_log_fatal("no backup directory specified"); - fprintf(stderr, _("Try \"%s --help\" for more information.\n"), - progname); + pg_log_error("no backup directory specified"); + pg_log_error_hint("Try \"%s --help\" for more information.", progname); exit(1); } context.backup_directory = pstrdup(argv[optind++]); @@ -272,10 +271,9 @@ main(int argc, char **argv) /* Complain if any arguments remain */ if (optind < argc) { - pg_log_fatal("too many command-line arguments (first is \"%s\")", + pg_log_error("too many command-line arguments (first is \"%s\")", argv[optind]); - fprintf(stderr, _("Try \"%s --help\" for more information.\n"), - progname); + pg_log_error_hint("Try \"%s --help\" for more information.", progname); exit(1); } @@ -294,17 +292,13 @@ main(int argc, char **argv) if (find_my_exec(argv[0], full_path) < 0) strlcpy(full_path, progname, sizeof(full_path)); + if (ret == -1) - pg_log_fatal("The program \"%s\" is needed by %s but was not found in the\n" - "same directory as \"%s\".\n" - "Check your installation.", - "pg_waldump", "pg_verifybackup", full_path); + pg_fatal("program \"%s\" is needed by %s but was not found in the same directory as \"%s\"", + "pg_waldump", "pg_verifybackup", full_path); else - pg_log_fatal("The program \"%s\" was found by \"%s\"\n" - "but was not the same version as %s.\n" - "Check your installation.", - "pg_waldump", full_path, "pg_verifybackup"); - exit(1); + pg_fatal("program \"%s\" was found by \"%s\" but was not the same version as %s", + "pg_waldump", full_path, "pg_verifybackup"); } } @@ -449,7 +443,7 @@ report_manifest_error(JsonManifestParseContext *context, const char *fmt,...) va_list ap; va_start(ap, fmt); - pg_log_generic_v(PG_LOG_FATAL, gettext(fmt), ap); + pg_log_generic_v(PG_LOG_ERROR, PG_LOG_PRIMARY, gettext(fmt), ap); va_end(ap); exit(1); @@ -840,7 +834,7 @@ report_backup_error(verifier_context *context, const char *pg_restrict fmt,...) va_list ap; va_start(ap, fmt); - pg_log_generic_v(PG_LOG_ERROR, gettext(fmt), ap); + pg_log_generic_v(PG_LOG_ERROR, PG_LOG_PRIMARY, gettext(fmt), ap); va_end(ap); context->saw_any_error = true; @@ -857,7 +851,7 @@ report_fatal_error(const char *pg_restrict fmt,...) va_list ap; va_start(ap, fmt); - pg_log_generic_v(PG_LOG_FATAL, gettext(fmt), ap); + pg_log_generic_v(PG_LOG_ERROR, PG_LOG_PRIMARY, gettext(fmt), ap); va_end(ap); exit(1); |