Add -L/--log-level command line option to repmgr

Overrides any setting in the config file. This will replace the
-v/--verbose option.
This commit is contained in:
Ian Barwick
2015-11-13 20:54:58 +09:00
parent d62aaeedd0
commit e0cbdd5b31
4 changed files with 32 additions and 6 deletions

4
log.c
View File

@@ -39,7 +39,6 @@
/* #define REPMGR_DEBUG */
static int detect_log_level(const char *level);
static int detect_log_facility(const char *facility);
int log_type = REPMGR_STDERR;
@@ -217,7 +216,7 @@ logger_min_verbose(int minimum)
log_level = minimum;
}
static int
int
detect_log_level(const char *level)
{
if (!strcmp(level, "DEBUG"))
@@ -247,7 +246,6 @@ detect_log_facility(const char *facility)
if (!strncmp(facility, "LOCAL", 5) && strlen(facility) == 6)
{
local = atoi(&facility[5]);
switch (local)

5
log.h
View File

@@ -112,12 +112,15 @@ __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
#endif
int detect_log_level(const char *level);
/* Logger initialisation and shutdown */
bool logger_shutdown(void);
bool logger_init(t_configuration_options * opts, const char *ident,
const char *level, const char *facility);
bool logger_shutdown(void);
void logger_min_verbose(int minimum);
void log_hint(const char *fmt, ...);

View File

@@ -151,6 +151,7 @@ main(int argc, char **argv)
{"pg_bindir", required_argument, NULL, 'b'},
{"rsync-only", no_argument, NULL, 'r'},
{"fast-checkpoint", no_argument, NULL, 'c'},
{"log-level", required_argument, NULL, 'L'},
{"initdb-no-pwprompt", no_argument, NULL, 1},
{"check-upstream-config", no_argument, NULL, 2},
{"recovery-min-apply-delay", required_argument, NULL, 3},
@@ -174,7 +175,7 @@ main(int argc, char **argv)
/* Prevent getopt_long() from printing an error message */
opterr = 0;
while ((c = getopt_long(argc, argv, "?Vd:h:p:U:S:D:l:f:R:w:k:FWIvb:r:c", long_options,
while ((c = getopt_long(argc, argv, "?Vd:h:p:U:S:D:l:f:R:w:k:FWIvb:r:c:L:", long_options,
&optindex)) != -1)
{
/*
@@ -256,6 +257,22 @@ main(int argc, char **argv)
case 'c':
runtime_options.fast_checkpoint = true;
break;
case 'L':
{
int detected_log_level = detect_log_level(optarg);
if (detected_log_level != -1)
{
strncpy(runtime_options.loglevel, optarg, MAXLEN);
}
else
{
PQExpBufferData invalid_log_level;
initPQExpBuffer(&invalid_log_level);
appendPQExpBuffer(&invalid_log_level, _("Invalid log level \"%s\" provided"), optarg);
error_list_append(&cli_errors, invalid_log_level.data);
}
break;
}
case 1:
runtime_options.initdb_no_pwprompt = true;
break;
@@ -496,6 +513,12 @@ main(int argc, char **argv)
* logging to troubleshoot problems.
*/
/* Command-line parameter -L/--log-level overrides any setting in config file*/
if(*runtime_options.loglevel != '\0')
{
strncpy(options.loglevel, runtime_options.loglevel, MAXLEN);
}
logger_init(&options, progname(), options.loglevel, options.logfacility);
if (runtime_options.verbose)
logger_min_verbose(LOG_INFO);
@@ -2524,6 +2547,7 @@ help(void)
printf(_(" -R, --remote-user=USERNAME database server username for rsync\n"));
printf(_(" -F, --force force potentially dangerous operations to happen\n"));
printf(_(" --check-upstream-config verify upstream server configuration\n"));
printf(_(" -L, --log-level set log level (overrides configuration file)\n"));
printf(_("\n"));
printf(_("Command-specific configuration options:\n"));
printf(_(" -c, --fast-checkpoint (standby clone) force fast checkpoint\n"));

View File

@@ -82,6 +82,7 @@ typedef struct
bool ignore_external_config_files;
char masterport[MAXLEN];
char localport[MAXLEN];
char loglevel[MAXLEN];
/* parameter used by CLUSTER CLEANUP */
int keep_history;
@@ -91,7 +92,7 @@ typedef struct
char recovery_min_apply_delay[MAXLEN];
} t_runtime_options;
#define T_RUNTIME_OPTIONS_INITIALIZER { "", "", "", "", "", "", "", DEFAULT_WAL_KEEP_SEGMENTS, false, false, false, false, false, false, false, false, "", "", 0, "", "" }
#define T_RUNTIME_OPTIONS_INITIALIZER { "", "", "", "", "", "", "", DEFAULT_WAL_KEEP_SEGMENTS, false, false, false, false, false, false, false, false, "", "", "", 0, "", "" }
extern char repmgr_schema[MAXLEN];