postgresql/src/backend/utils
Peter Eisentraut cc8d415117 Unified logging system for command-line programs
This unifies the various ad hoc logging (message printing, error
printing) systems used throughout the command-line programs.

Features:

- Program name is automatically prefixed.

- Message string does not end with newline.  This removes a common
  source of inconsistencies and omissions.

- Additionally, a final newline is automatically stripped, simplifying
  use of PQerrorMessage() etc., another common source of mistakes.

- I converted error message strings to use %m where possible.

- As a result of the above several points, more translatable message
  strings can be shared between different components and between
  frontends and backend, without gratuitous punctuation or whitespace
  differences.

- There is support for setting a "log level".  This is not meant to be
  user-facing, but can be used internally to implement debug or
  verbose modes.

- Lazy argument evaluation, so no significant overhead if logging at
  some level is disabled.

- Some color in the messages, similar to gcc and clang.  Set
  PG_COLOR=auto to try it out.  Some colors are predefined, but can be
  customized by setting PG_COLORS.

- Common files (common/, fe_utils/, etc.) can handle logging much more
  simply by just using one API without worrying too much about the
  context of the calling program, requiring callbacks, or having to
  pass "progname" around everywhere.

- Some programs called setvbuf() to make sure that stderr is
  unbuffered, even on Windows.  But not all programs did that.  This
  is now done centrally.

Soft goals:

- Reduces vertical space use and visual complexity of error reporting
  in the source code.

- Encourages more deliberate classification of messages.  For example,
  in some cases it wasn't clear without analyzing the surrounding code
  whether a message was meant as an error or just an info.

- Concepts and terms are vaguely aligned with popular logging
  frameworks such as log4j and Python logging.

This is all just about printing stuff out.  Nothing affects program
flow (e.g., fatal exits).  The uses are just too varied to do that.
Some existing code had wrappers that do some kind of print-and-exit,
and I adapted those.

I tried to keep the output mostly the same, but there is a lot of
historical baggage to unwind and special cases to consider, and I
might not always have succeeded.  One significant change is that
pg_rewind used to write all error messages to stdout.  That is now
changed to stderr.

Reviewed-by: Donald Dong <xdong@csumb.edu>
Reviewed-by: Arthur Zakirov <a.zakirov@postgrespro.ru>
Discussion: https://www.postgresql.org/message-id/flat/6a609b43-4f57-7348-6480-bd022f924310@2ndquadrant.com
2019-04-01 20:01:35 +02:00
..
adt Throw error in jsonb_path_match() when result is not single boolean 2019-04-01 18:09:20 +03:00
cache Generated columns 2019-03-30 08:15:57 +01:00
error Update copyright for 2019 2019-01-02 12:44:25 -05:00
fmgr Change function call information to be variable length. 2019-01-26 14:17:52 -08:00
hash Move hash_any prototype from access/hash.h to utils/hashutils.h 2019-03-11 13:17:50 -03:00
init Update HINT for pre-existing shared memory block. 2019-03-31 19:32:48 -07:00
mb More unconstify use 2019-02-13 11:50:16 +01:00
misc Unified logging system for command-line programs 2019-04-01 20:01:35 +02:00
mmgr Fix inconsistent out-of-memory error reporting in dsa.c. 2019-02-25 11:11:40 +13:00
resowner Enable parallel query with SERIALIZABLE isolation. 2019-03-15 17:47:04 +13:00
sort Make heap TID a tiebreaker nbtree index column. 2019-03-20 10:04:01 -07:00
time Mark correctly initial slot snapshots with MVCC type when built 2019-02-20 12:31:07 +09:00
.gitignore Rearrange makefile rules for running Gen_fmgrtab.pl. 2018-05-03 17:54:18 -04:00
errcodes.txt Partial implementation of SQL/JSON path language 2019-03-16 12:16:48 +03:00
Gen_dummy_probes.pl Update copyright for 2019 2019-01-02 12:44:25 -05:00
Gen_dummy_probes.sed Update copyright for 2019 2019-01-02 12:44:25 -05:00
Gen_fmgrtab.pl Use Getopt::Long for catalog scripts 2019-02-12 12:22:08 -03:00
generate-errcodes.pl Update copyright for 2019 2019-01-02 12:44:25 -05:00
Makefile Use Getopt::Long for catalog scripts 2019-02-12 12:22:08 -03:00
probes.d Update copyright for 2019 2019-01-02 12:44:25 -05:00