diff options
author | Tom Lane | 2020-09-17 16:52:18 +0000 |
---|---|---|
committer | Tom Lane | 2020-09-17 16:52:18 +0000 |
commit | 99175141c9254318e5894ac30b9fdb622612acda (patch) | |
tree | 2afcbc8352aca1296a371c41cc7d3a2a2ccecb3a /src/common/logging.c | |
parent | b7f2dd959a5082540adbeee1dea0c0b1c154374f (diff) |
Improve common/logging.c's support for multiple verbosity levels.
Instead of hard-wiring specific verbosity levels into the option
processing of client applications, invent pg_logging_increase_verbosity()
and encourage clients to implement --verbose by calling that. Then,
the common convention that more -v's gets you more verbosity just works.
In particular, this allows resurrection of the debug-grade messages that
have long existed in pg_dump and its siblings. They were unreachable
before this commit due to lack of a way to select PG_LOG_DEBUG logging
level. (It appears that they may have been unreachable for some time
before common/logging.c was introduced, too, so I'm not specifically
blaming cc8d41511 for the oversight. One reason for thinking that is
that it's now apparent that _allocAH()'s message needs a null-pointer
guard. Testing might have failed to reveal that before 96bf88d52.)
Discussion: https://postgr.es/m/[email protected]
Diffstat (limited to 'src/common/logging.c')
-rw-r--r-- | src/common/logging.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/common/logging.c b/src/common/logging.c index 6a3a437a34b..d9632fffc8a 100644 --- a/src/common/logging.c +++ b/src/common/logging.c @@ -157,12 +157,30 @@ pg_logging_config(int new_flags) log_flags = new_flags; } +/* + * pg_logging_init sets the default log level to INFO. Programs that prefer + * a different default should use this to set it, immediately afterward. + */ void pg_logging_set_level(enum pg_log_level new_level) { __pg_log_level = new_level; } +/* + * Command line switches such as --verbose should invoke this. + */ +void +pg_logging_increase_verbosity(void) +{ + /* + * The enum values are chosen such that we have to decrease __pg_log_level + * in order to become more verbose. + */ + if (__pg_log_level > PG_LOG_NOTSET + 1) + __pg_log_level--; +} + void pg_logging_set_pre_callback(void (*cb) (void)) { |