From 3b2203c38cb6e6bd66d94223758c7ce36208c218 Mon Sep 17 00:00:00 2001 From: Greg Smith Date: Wed, 23 Feb 2011 05:29:29 -0500 Subject: [PATCH] Make verbose command line option useful on top of the new logging infrastructure. --- config.c | 8 ++++++-- log.c | 11 +++++++++++ log.h | 1 + repmgr.c | 22 +++++++++++++++++----- 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/config.c b/config.c index f1b980b5..92094ff2 100644 --- a/config.c +++ b/config.c @@ -30,10 +30,14 @@ parse_config(const char* config_file, t_configuration_options* options) FILE *fp = fopen (config_file, "r"); + /* + * Since some commands don't require a config file at all, not + * having one isn't necessarily a problem. + */ if (fp == NULL) { - fprintf(stderr, _("Could not find configuration file '%s'\n"), config_file); - exit(ERR_BAD_CONFIG); + fprintf(stderr, _("Did not find the configuration file '%s', continuing\n"), config_file); + return; } /* Initialize */ diff --git a/log.c b/log.c index c458628f..d9e5ed35 100644 --- a/log.c +++ b/log.c @@ -130,6 +130,17 @@ bool logger_shutdown(void) return true; } +/* + * Set a minimum logging level. Intended for command line verbosity + * options, which might increase requested logging over what's specified + * in the regular configuration file. + */ +void logger_min_verbose(int minimum) +{ + if (log_level < minimum) + log_level = minimum; +} + int detect_log_level(const char* level) { if (!strcmp(level, "DEBUG")) diff --git a/log.h b/log.h index 4a439912..16df5ecd 100644 --- a/log.h +++ b/log.h @@ -111,6 +111,7 @@ /* Logger initialisation and shutdown */ bool logger_shutdown(void); bool logger_init(const char* ident, const char* level, const char* facility); +void logger_min_verbose(int minimum); extern int log_type; extern int log_level; diff --git a/repmgr.c b/repmgr.c index 2f0e2523..f12770ba 100644 --- a/repmgr.c +++ b/repmgr.c @@ -211,7 +211,7 @@ main(int argc, char **argv) { if (runtime_options.host[0]) { - log_err(_("Conflicting parameters you can't use -h while providing a node separately.\n")); + log_err(_("Conflicting parameters: you can't use -h while providing a node separately.\n")); usage(); exit(ERR_BAD_CONFIG); } @@ -224,7 +224,7 @@ main(int argc, char **argv) case 0: break; default: - log_err(_("%s: too many command-line arguments (first is \"%s\")\n"), + log_err(_("%s: too many command-line arguments (first extra is \"%s\")\n"), progname, argv[optind + 1]); usage(); exit(ERR_BAD_CONFIG); @@ -243,7 +243,7 @@ main(int argc, char **argv) strncpy(runtime_options.dbname, DEFAULT_DBNAME, MAXLEN); } - /* Read the configuration file: repmgr.conf */ + /* Read the configuration file, normally repmgr.conf */ if (!runtime_options.config_file[0]) strncpy(runtime_options.config_file, DEFAULT_CONFIG_FILE, MAXLEN); @@ -261,7 +261,17 @@ main(int argc, char **argv) keywords[5] = NULL; values[5] = NULL; + /* + * Initialize the logger. If verbose command line parameter was + * input, make sure that the log level is at least INFO. This + * is mainly useful for STANDBY CLONE. That doesn't require a + * configuration file where a logging level might be specified + * at, but it often requires detailed logging to troubleshoot + * problems. + */ logger_init(progname, options.loglevel, options.logfacility); + if (runtime_options.verbose) + logger_min_verbose(LOG_INFO); /* * Node configuration information is not needed for all actions, @@ -592,7 +602,6 @@ do_standby_register(void) exit(ERR_BAD_CONFIG); } - /* Now register the standby */ if (runtime_options.force) { @@ -724,6 +733,7 @@ do_standby_clone(void) values[1] = runtime_options.masterport; /* We need to connect to check configuration and start a backup */ + log_info(_("%s connecting to master database\n"), progname); conn = PQconnectdbParams(keywords, values, true); if (!conn) { @@ -733,6 +743,7 @@ do_standby_clone(void) } /* primary should be v9 or better */ + log_info(_("%s connected to master, checking its state\n"), progname); pg_version(conn, master_version); if (strcmp(master_version, "") == 0) { @@ -1562,7 +1573,8 @@ check_parameters_for_action(const int action) { log_notice("Only command line parameters for the connection " "to the master are used when issuing a STANDBY CLONE command. " - "The passed configuration file is neither required nor used\n"); + "The passed configuration file is neither required nor used for " + "its node configuration portions\n\n"); } /* * To clone a master into a standby we need connection parameters