pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter Eisentraut <peter@eisentraut.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Unified logging system for command-line programs
Date: Mon, 01 Apr 2019 18:25:56 +0000
Message-ID: <E1hB1d6-00051m-1s@gemulon.postgresql.org> (raw)

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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/cc8d41511721d25d557fc02a46c053c0a602fed0

Modified Files
--------------
doc/src/sgml/ref/clusterdb.sgml               |  11 +
doc/src/sgml/ref/createdb.sgml                |  11 +
doc/src/sgml/ref/createuser.sgml              |  11 +
doc/src/sgml/ref/dropdb.sgml                  |  11 +
doc/src/sgml/ref/dropuser.sgml                |  11 +
doc/src/sgml/ref/initdb.sgml                  |  11 +
doc/src/sgml/ref/pg_basebackup.sgml           |   6 +
doc/src/sgml/ref/pg_checksums.sgml            |  11 +
doc/src/sgml/ref/pg_controldata.sgml          |  11 +
doc/src/sgml/ref/pg_dump.sgml                 |  11 +
doc/src/sgml/ref/pg_dumpall.sgml              |  11 +
doc/src/sgml/ref/pg_isready.sgml              |   7 +
doc/src/sgml/ref/pg_receivewal.sgml           |   6 +
doc/src/sgml/ref/pg_recvlogical.sgml          |   7 +
doc/src/sgml/ref/pg_resetwal.sgml             |  17 ++
doc/src/sgml/ref/pg_restore.sgml              |  11 +
doc/src/sgml/ref/pg_rewind.sgml               |   7 +
doc/src/sgml/ref/pg_waldump.sgml              |  26 ++
doc/src/sgml/ref/psql-ref.sgml                |  11 +
doc/src/sgml/ref/reindexdb.sgml               |  11 +
doc/src/sgml/ref/vacuumdb.sgml                |  11 +
src/backend/access/transam/xlog.c             |   2 +-
src/backend/utils/misc/pg_controldata.c       |   8 +-
src/bin/initdb/initdb.c                       | 266 +++++++----------
src/bin/initdb/nls.mk                         |   5 +-
src/bin/pg_archivecleanup/Makefile            |   4 +-
src/bin/pg_archivecleanup/nls.mk              |   4 +-
src/bin/pg_archivecleanup/pg_archivecleanup.c |  53 ++--
src/bin/pg_basebackup/nls.mk                  |   5 +-
src/bin/pg_basebackup/pg_basebackup.c         | 412 ++++++++++----------------
src/bin/pg_basebackup/pg_receivewal.c         | 122 ++++----
src/bin/pg_basebackup/pg_recvlogical.c        | 147 ++++-----
src/bin/pg_basebackup/receivelog.c            | 204 ++++++-------
src/bin/pg_basebackup/streamutil.c            |  97 +++---
src/bin/pg_basebackup/walmethods.c            |  16 +-
src/bin/pg_checksums/Makefile                 |   4 +-
src/bin/pg_checksums/nls.mk                   |   4 +-
src/bin/pg_checksums/pg_checksums.c           |  72 +++--
src/bin/pg_controldata/Makefile               |   4 +-
src/bin/pg_controldata/pg_controldata.c       |  11 +-
src/bin/pg_ctl/Makefile                       |   4 +-
src/bin/pg_ctl/pg_ctl.c                       |   8 +-
src/bin/pg_dump/common.c                      | 124 +++-----
src/bin/pg_dump/compress_io.c                 |  46 +--
src/bin/pg_dump/nls.mk                        |  16 +-
src/bin/pg_dump/parallel.c                    |  62 ++--
src/bin/pg_dump/pg_backup_archiver.c          | 250 +++++++---------
src/bin/pg_dump/pg_backup_archiver.h          |  15 +-
src/bin/pg_dump/pg_backup_custom.c            |  94 +++---
src/bin/pg_dump/pg_backup_db.c                |  55 ++--
src/bin/pg_dump/pg_backup_directory.c         |  72 ++---
src/bin/pg_dump/pg_backup_null.c              |   4 +-
src/bin/pg_dump/pg_backup_tar.c               |  88 +++---
src/bin/pg_dump/pg_backup_utils.c             |  58 +---
src/bin/pg_dump/pg_backup_utils.h             |   6 +-
src/bin/pg_dump/pg_dump.c                     | 334 ++++++++++-----------
src/bin/pg_dump/pg_dump.h                     |   1 -
src/bin/pg_dump/pg_dump_sort.c                |  26 +-
src/bin/pg_dump/pg_dumpall.c                  | 125 ++++----
src/bin/pg_dump/pg_restore.c                  |  36 +--
src/bin/pg_dump/t/001_basic.pl                |  54 ++--
src/bin/pg_dump/t/002_pg_dump.pl              |  24 +-
src/bin/pg_resetwal/Makefile                  |   4 +-
src/bin/pg_resetwal/nls.mk                    |   4 +-
src/bin/pg_resetwal/pg_resetwal.c             | 175 +++++------
src/bin/pg_resetwal/t/002_corrupted.pl        |   4 +-
src/bin/pg_rewind/Makefile                    |   4 +-
src/bin/pg_rewind/copy_fetch.c                |  38 +--
src/bin/pg_rewind/datapagemap.c               |   5 +-
src/bin/pg_rewind/file_ops.c                  |  60 ++--
src/bin/pg_rewind/filemap.c                   |  34 +--
src/bin/pg_rewind/libpq_fetch.c               |  37 +--
src/bin/pg_rewind/logging.c                   |  73 +----
src/bin/pg_rewind/logging.h                   |  18 +-
src/bin/pg_rewind/nls.mk                      |   7 +-
src/bin/pg_rewind/parsexlog.c                 |  33 +--
src/bin/pg_rewind/pg_rewind.c                 |  85 +++---
src/bin/pg_rewind/pg_rewind.h                 |   1 -
src/bin/pg_rewind/timeline.c                  |  17 +-
src/bin/pg_test_fsync/Makefile                |   4 +-
src/bin/pg_test_fsync/pg_test_fsync.c         |  19 +-
src/bin/pg_upgrade/pg_upgrade.c               |   4 +-
src/bin/pg_waldump/Makefile                   |   3 +-
src/bin/pg_waldump/nls.mk                     |   6 +-
src/bin/pg_waldump/pg_waldump.c               |  71 ++---
src/bin/pgbench/pgbench.c                     |  23 +-
src/bin/psql/command.c                        | 157 +++++-----
src/bin/psql/common.c                         |  81 ++---
src/bin/psql/common.h                         |   2 -
src/bin/psql/copy.c                           |  42 ++-
src/bin/psql/crosstabview.c                   |  19 +-
src/bin/psql/describe.c                       |  75 ++---
src/bin/psql/help.c                           |   3 +-
src/bin/psql/input.c                          |  15 +-
src/bin/psql/large_obj.c                      |  15 +-
src/bin/psql/mainloop.c                       |  14 +-
src/bin/psql/nls.mk                           |   8 +-
src/bin/psql/psqlscanslash.l                  |  11 +-
src/bin/psql/startup.c                        |  50 +++-
src/bin/psql/tab-complete.c                   |   2 +-
src/bin/psql/variables.c                      |  11 +-
src/bin/psql/variables.h                      |   2 +-
src/bin/scripts/clusterdb.c                   |  20 +-
src/bin/scripts/common.c                      |  30 +-
src/bin/scripts/createdb.c                    |  22 +-
src/bin/scripts/createuser.c                  |  13 +-
src/bin/scripts/dropdb.c                      |  11 +-
src/bin/scripts/dropuser.c                    |  12 +-
src/bin/scripts/nls.mk                        |   6 +-
src/bin/scripts/pg_isready.c                  |  10 +-
src/bin/scripts/reindexdb.c                   |  46 +--
src/bin/scripts/vacuumdb.c                    |  67 ++---
src/common/controldata_utils.c                |  41 ++-
src/common/file_utils.c                       |  84 +++---
src/common/pgfnames.c                         |  31 +-
src/common/restricted_token.c                 |  23 +-
src/common/rmtree.c                           |  27 +-
src/fe_utils/Makefile                         |   2 +-
src/fe_utils/logging.c                        | 228 ++++++++++++++
src/fe_utils/psqlscan.l                       |   3 +-
src/include/common/controldata_utils.h        |   6 +-
src/include/common/file_utils.h               |  13 +-
src/include/common/restricted_token.h         |   4 +-
src/include/fe_utils/logging.h                |  95 ++++++
src/include/fe_utils/psqlscan.h               |   7 -
src/interfaces/ecpg/test/Makefile             |   2 +
src/nls-global.mk                             |   8 +
src/test/isolation/Makefile                   |   3 +-
src/test/perl/TestLib.pm                      |   1 +
src/test/regress/GNUmakefile                  |   4 +-
src/test/regress/pg_regress.c                 |   6 +-
src/tools/msvc/Mkvcbuild.pm                   |   8 +-
132 files changed, 2555 insertions(+), 2686 deletions(-)



view thread (3+ messages)  latest in thread

Message-ID: <E1hB1d6-00051m-1s@gemulon.postgresql.org>
Permalink:  ../E1hB1d6-00051m-1s@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1hB1d6-00051m-1s@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: peter@eisentraut.org
  Subject: Re: pgsql: Unified logging system for command-line programs
  In-Reply-To: <E1hB1d6-00051m-1s@gemulon.postgresql.org>
  References: <E1hB1d6-00051m-1s@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox