diff options
author | Tom Lane | 2022-04-08 18:55:14 +0000 |
---|---|---|
committer | Tom Lane | 2022-04-08 18:55:14 +0000 |
commit | 9a374b77fb53e4cfbca121e4fa278a7d71bde7c4 (patch) | |
tree | 6591af757bd9df12549279b4b87f01e0ce98bd79 /src/common/logging.c | |
parent | 5c431c7fb327e1abc70b7a197650f8d45fd5bede (diff) |
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/common/logging.c')
-rw-r--r-- | src/common/logging.c | 60 |
1 files changed, 35 insertions, 25 deletions
diff --git a/src/common/logging.c b/src/common/logging.c index 9a076bb8128..18d6669f276 100644 --- a/src/common/logging.c +++ b/src/common/logging.c @@ -151,6 +151,9 @@ pg_logging_init(const char *argv0) } } +/* + * Change the logging flags. + */ void pg_logging_config(int new_flags) { @@ -194,17 +197,19 @@ pg_logging_set_locus_callback(void (*cb) (const char **filename, uint64 *lineno) } void -pg_log_generic(enum pg_log_level level, const char *pg_restrict fmt,...) +pg_log_generic(enum pg_log_level level, enum pg_log_part part, + const char *pg_restrict fmt,...) { va_list ap; va_start(ap, fmt); - pg_log_generic_v(level, fmt, ap); + pg_log_generic_v(level, part, fmt, ap); va_end(ap); } void -pg_log_generic_v(enum pg_log_level level, const char *pg_restrict fmt, va_list ap) +pg_log_generic_v(enum pg_log_level level, enum pg_log_part part, + const char *pg_restrict fmt, va_list ap) { int save_errno = errno; const char *filename = NULL; @@ -232,7 +237,8 @@ pg_log_generic_v(enum pg_log_level level, const char *pg_restrict fmt, va_list a fmt = _(fmt); - if (!(log_flags & PG_LOG_FLAG_TERSE) || filename) + if (part == PG_LOG_PRIMARY && + (!(log_flags & PG_LOG_FLAG_TERSE) || filename)) { if (sgr_locus) fprintf(stderr, ANSI_ESCAPE_FMT, sgr_locus); @@ -251,30 +257,34 @@ pg_log_generic_v(enum pg_log_level level, const char *pg_restrict fmt, va_list a if (!(log_flags & PG_LOG_FLAG_TERSE)) { - switch (level) + switch (part) { - case PG_LOG_FATAL: - if (sgr_error) - fprintf(stderr, ANSI_ESCAPE_FMT, sgr_error); - fprintf(stderr, _("fatal: ")); - if (sgr_error) - fprintf(stderr, ANSI_ESCAPE_RESET); - break; - case PG_LOG_ERROR: - if (sgr_error) - fprintf(stderr, ANSI_ESCAPE_FMT, sgr_error); - fprintf(stderr, _("error: ")); - if (sgr_error) - fprintf(stderr, ANSI_ESCAPE_RESET); + case PG_LOG_PRIMARY: + switch (level) + { + case PG_LOG_ERROR: + if (sgr_error) + fprintf(stderr, ANSI_ESCAPE_FMT, sgr_error); + fprintf(stderr, _("error: ")); + if (sgr_error) + fprintf(stderr, ANSI_ESCAPE_RESET); + break; + case PG_LOG_WARNING: + if (sgr_warning) + fprintf(stderr, ANSI_ESCAPE_FMT, sgr_warning); + fprintf(stderr, _("warning: ")); + if (sgr_warning) + fprintf(stderr, ANSI_ESCAPE_RESET); + break; + default: + break; + } break; - case PG_LOG_WARNING: - if (sgr_warning) - fprintf(stderr, ANSI_ESCAPE_FMT, sgr_warning); - fprintf(stderr, _("warning: ")); - if (sgr_warning) - fprintf(stderr, ANSI_ESCAPE_RESET); + case PG_LOG_DETAIL: + fprintf(stderr, _("detail: ")); break; - default: + case PG_LOG_HINT: + fprintf(stderr, _("hint: ")); break; } } |