From 9a374b77fb53e4cfbca121e4fa278a7d71bde7c4 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 8 Apr 2022 14:55:14 -0400 Subject: 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 --- src/bin/pg_dump/pg_backup_utils.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/bin/pg_dump/pg_backup_utils.h') diff --git a/src/bin/pg_dump/pg_backup_utils.h b/src/bin/pg_dump/pg_backup_utils.h index 6ebc3afee4a..5b1c51554da 100644 --- a/src/bin/pg_dump/pg_backup_utils.h +++ b/src/bin/pg_dump/pg_backup_utils.h @@ -31,6 +31,12 @@ extern void set_dump_section(const char *arg, int *dumpSections); extern void on_exit_nicely(on_exit_nicely_callback function, void *arg); extern void exit_nicely(int code) pg_attribute_noreturn(); -#define fatal(...) do { pg_log_error(__VA_ARGS__); exit_nicely(1); } while(0) +/* In pg_dump, we modify pg_fatal to call exit_nicely instead of exit */ +#undef pg_fatal +#define pg_fatal(...) do { \ + if (likely(__pg_log_level <= PG_LOG_ERROR)) \ + pg_log_generic(PG_LOG_ERROR, PG_LOG_PRIMARY, __VA_ARGS__); \ + exit_nicely(1); \ + } while(0) #endif /* PG_BACKUP_UTILS_H */ -- cgit v1.2.3