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_basebackup/pg_recvlogical.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_basebackup/pg_recvlogical.c')
-rw-r--r-- | src/bin/pg_basebackup/pg_recvlogical.c | 60 |
1 files changed, 16 insertions, 44 deletions
diff --git a/src/bin/pg_basebackup/pg_recvlogical.c b/src/bin/pg_basebackup/pg_recvlogical.c index cc35d16f32a..b59ff23f612 100644 --- a/src/bin/pg_basebackup/pg_recvlogical.c +++ b/src/bin/pg_basebackup/pg_recvlogical.c @@ -193,10 +193,7 @@ OutputFsync(TimestampTz now) return true; if (fsync(outfd) != 0) - { - pg_log_fatal("could not fsync file \"%s\": %m", outfile); - exit(1); - } + pg_fatal("could not fsync file \"%s\": %m", outfile); return true; } @@ -780,18 +777,12 @@ main(int argc, char **argv) /* replication options */ case 'I': if (sscanf(optarg, "%X/%X", &hi, &lo) != 2) - { - pg_log_error("could not parse start position \"%s\"", optarg); - exit(1); - } + pg_fatal("could not parse start position \"%s\"", optarg); startpos = ((uint64) hi) << 32 | lo; break; case 'E': if (sscanf(optarg, "%X/%X", &hi, &lo) != 2) - { - pg_log_error("could not parse end position \"%s\"", optarg); - exit(1); - } + pg_fatal("could not parse end position \"%s\"", optarg); endpos = ((uint64) hi) << 32 | lo; break; case 'o': @@ -842,12 +833,8 @@ main(int argc, char **argv) break; default: - - /* - * getopt_long already emitted a complaint - */ - 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); } } @@ -859,8 +846,7 @@ main(int argc, char **argv) { 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); } @@ -870,64 +856,56 @@ main(int argc, char **argv) if (replication_slot == NULL) { pg_log_error("no slot specified"); - fprintf(stderr, _("Try \"%s --help\" for more information.\n"), - progname); + pg_log_error_hint("Try \"%s --help\" for more information.", progname); exit(1); } if (do_start_slot && outfile == NULL) { pg_log_error("no target file specified"); - fprintf(stderr, _("Try \"%s --help\" for more information.\n"), - progname); + pg_log_error_hint("Try \"%s --help\" for more information.", progname); exit(1); } if (!do_drop_slot && dbname == NULL) { pg_log_error("no database specified"); - fprintf(stderr, _("Try \"%s --help\" for more information.\n"), - progname); + pg_log_error_hint("Try \"%s --help\" for more information.", progname); exit(1); } if (!do_drop_slot && !do_create_slot && !do_start_slot) { pg_log_error("at least one action needs to be specified"); - fprintf(stderr, _("Try \"%s --help\" for more information.\n"), - progname); + pg_log_error_hint("Try \"%s --help\" for more information.", progname); exit(1); } if (do_drop_slot && (do_create_slot || do_start_slot)) { pg_log_error("cannot use --create-slot or --start together with --drop-slot"); - fprintf(stderr, _("Try \"%s --help\" for more information.\n"), - progname); + pg_log_error_hint("Try \"%s --help\" for more information.", progname); exit(1); } if (startpos != InvalidXLogRecPtr && (do_create_slot || do_drop_slot)) { pg_log_error("cannot use --create-slot or --drop-slot together with --startpos"); - fprintf(stderr, _("Try \"%s --help\" for more information.\n"), - progname); + pg_log_error_hint("Try \"%s --help\" for more information.", progname); exit(1); } if (endpos != InvalidXLogRecPtr && !do_start_slot) { pg_log_error("--endpos may only be specified with --start"); - fprintf(stderr, _("Try \"%s --help\" for more information.\n"), - progname); + pg_log_error_hint("Try \"%s --help\" for more information.", progname); exit(1); } if (two_phase && !do_create_slot) { pg_log_error("--two-phase may only be specified with --create-slot"); - fprintf(stderr, _("Try \"%s --help\" for more information.\n"), - progname); + pg_log_error_hint("Try \"%s --help\" for more information.", progname); exit(1); } @@ -958,10 +936,7 @@ main(int argc, char **argv) exit(1); if (db_name == NULL) - { - pg_log_error("could not establish database-specific replication connection"); - exit(1); - } + pg_fatal("could not establish database-specific replication connection"); /* * Set umask so that directories/files are created with the same @@ -1011,10 +986,7 @@ main(int argc, char **argv) exit(0); } else if (noloop) - { - pg_log_error("disconnected"); - exit(1); - } + pg_fatal("disconnected"); else { /* translator: check source for value for %d */ |