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:
parent
b7f2dd959a
commit
99175141c9
|
@ -594,6 +594,8 @@ PostgreSQL documentation
|
||||||
<application>pg_dump</application> to output detailed object
|
<application>pg_dump</application> to output detailed object
|
||||||
comments and start/stop times to the dump file, and progress
|
comments and start/stop times to the dump file, and progress
|
||||||
messages to standard error.
|
messages to standard error.
|
||||||
|
Repeating the option causes additional debug-level messages
|
||||||
|
to appear on standard error.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
|
@ -202,7 +202,9 @@ PostgreSQL documentation
|
||||||
Specifies verbose mode. This will cause
|
Specifies verbose mode. This will cause
|
||||||
<application>pg_dumpall</application> to output start/stop
|
<application>pg_dumpall</application> to output start/stop
|
||||||
times to the dump file, and progress messages to standard error.
|
times to the dump file, and progress messages to standard error.
|
||||||
It will also enable verbose output in <application>pg_dump</application>.
|
Repeating the option causes additional debug-level messages
|
||||||
|
to appear on standard error.
|
||||||
|
The option is also passed down to <application>pg_dump</application>.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
|
@ -483,7 +483,12 @@ PostgreSQL documentation
|
||||||
<term><option>--verbose</option></term>
|
<term><option>--verbose</option></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Specifies verbose mode.
|
Specifies verbose mode. This will cause
|
||||||
|
<application>pg_restore</application> to output detailed object
|
||||||
|
comments and start/stop times to the output file, and progress
|
||||||
|
messages to standard error.
|
||||||
|
Repeating the option causes additional debug-level messages
|
||||||
|
to appear on standard error.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
|
@ -302,7 +302,7 @@ main(int argc, char **argv)
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
case 'd': /* Debug mode */
|
case 'd': /* Debug mode */
|
||||||
pg_logging_set_level(PG_LOG_DEBUG);
|
pg_logging_increase_verbosity();
|
||||||
break;
|
break;
|
||||||
case 'n': /* Dry-Run mode */
|
case 'n': /* Dry-Run mode */
|
||||||
dryrun = true;
|
dryrun = true;
|
||||||
|
|
|
@ -2278,7 +2278,8 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
|
||||||
{
|
{
|
||||||
ArchiveHandle *AH;
|
ArchiveHandle *AH;
|
||||||
|
|
||||||
pg_log_debug("allocating AH for %s, format %d", FileSpec, fmt);
|
pg_log_debug("allocating AH for %s, format %d",
|
||||||
|
FileSpec ? FileSpec : "(stdio)", fmt);
|
||||||
|
|
||||||
AH = (ArchiveHandle *) pg_malloc0(sizeof(ArchiveHandle));
|
AH = (ArchiveHandle *) pg_malloc0(sizeof(ArchiveHandle));
|
||||||
|
|
||||||
|
|
|
@ -512,7 +512,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
case 'v': /* verbose */
|
case 'v': /* verbose */
|
||||||
g_verbose = true;
|
g_verbose = true;
|
||||||
pg_logging_set_level(PG_LOG_INFO);
|
pg_logging_increase_verbosity();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'w':
|
case 'w':
|
||||||
|
|
|
@ -283,7 +283,7 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
verbose = true;
|
verbose = true;
|
||||||
pg_logging_set_level(PG_LOG_INFO);
|
pg_logging_increase_verbosity();
|
||||||
appendPQExpBufferStr(pgdumpopts, " -v");
|
appendPQExpBufferStr(pgdumpopts, " -v");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -245,7 +245,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
case 'v': /* verbose */
|
case 'v': /* verbose */
|
||||||
opts->verbose = 1;
|
opts->verbose = 1;
|
||||||
pg_logging_set_level(PG_LOG_INFO);
|
pg_logging_increase_verbosity();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'w':
|
case 'w':
|
||||||
|
|
|
@ -181,7 +181,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
debug = true;
|
debug = true;
|
||||||
pg_logging_set_level(PG_LOG_DEBUG);
|
pg_logging_increase_verbosity();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'D': /* -D or --target-pgdata */
|
case 'D': /* -D or --target-pgdata */
|
||||||
|
|
|
@ -5522,7 +5522,7 @@ main(int argc, char **argv)
|
||||||
pgport = pg_strdup(optarg);
|
pgport = pg_strdup(optarg);
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
pg_logging_set_level(PG_LOG_DEBUG);
|
pg_logging_increase_verbosity();
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
benchmarking_option_set = true;
|
benchmarking_option_set = true;
|
||||||
|
|
|
@ -157,12 +157,30 @@ pg_logging_config(int new_flags)
|
||||||
log_flags = 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
|
void
|
||||||
pg_logging_set_level(enum pg_log_level new_level)
|
pg_logging_set_level(enum pg_log_level new_level)
|
||||||
{
|
{
|
||||||
__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
|
void
|
||||||
pg_logging_set_pre_callback(void (*cb) (void))
|
pg_logging_set_pre_callback(void (*cb) (void))
|
||||||
{
|
{
|
||||||
|
|
|
@ -66,6 +66,7 @@ extern enum pg_log_level __pg_log_level;
|
||||||
void pg_logging_init(const char *argv0);
|
void pg_logging_init(const char *argv0);
|
||||||
void pg_logging_config(int new_flags);
|
void pg_logging_config(int new_flags);
|
||||||
void pg_logging_set_level(enum pg_log_level new_level);
|
void pg_logging_set_level(enum pg_log_level new_level);
|
||||||
|
void pg_logging_increase_verbosity(void);
|
||||||
void pg_logging_set_pre_callback(void (*cb) (void));
|
void pg_logging_set_pre_callback(void (*cb) (void));
|
||||||
void pg_logging_set_locus_callback(void (*cb) (const char **filename, uint64 *lineno));
|
void pg_logging_set_locus_callback(void (*cb) (const char **filename, uint64 *lineno));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue