mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
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/1173106.1600116625@sss.pgh.pa.us
This commit is contained in:
@ -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))
|
||||
{
|
||||
|
Reference in New Issue
Block a user