Rename "logxxx" configuration file parameters to "log_xxx"

This is more consistent with other parameters and conforms to
the pattern used by PostgreSQL itself, which uses the prefix "log_"
for logging parameters.

A warning will be emitted if the old version of the parameter name
is detected.
This commit is contained in:
Ian Barwick
2017-07-03 10:28:56 +09:00
parent debe5a18c5
commit 34c746fcde
10 changed files with 81 additions and 45 deletions

View File

@@ -214,11 +214,11 @@ _parse_config(t_configuration_options *options, ItemList *error_list, ItemList *
/* /*
* log settings * log settings
* *
* note: the default for "loglevel" is set in log.c and does not need * note: the default for "log_level" is set in log.c and does not need
* to be initialised here * to be initialised here
*/ */
memset(options->logfacility, 0, sizeof(options->logfacility)); memset(options->log_facility, 0, sizeof(options->log_facility));
memset(options->logfile, 0, sizeof(options->logfile)); memset(options->log_file, 0, sizeof(options->log_file));
/* standby clone settings /* standby clone settings
* ----------------------- */ * ----------------------- */
@@ -348,12 +348,12 @@ _parse_config(t_configuration_options *options, ItemList *error_list, ItemList *
} }
/* log settings */ /* log settings */
else if (strcmp(name, "logfile") == 0) else if (strcmp(name, "log_file") == 0)
strncpy(options->logfile, value, MAXLEN); strncpy(options->log_file, value, MAXLEN);
else if (strcmp(name, "loglevel") == 0) else if (strcmp(name, "log_level") == 0)
strncpy(options->loglevel, value, MAXLEN); strncpy(options->log_level, value, MAXLEN);
else if (strcmp(name, "logfacility") == 0) else if (strcmp(name, "log_facility") == 0)
strncpy(options->logfacility, value, MAXLEN); strncpy(options->log_facility, value, MAXLEN);
/* standby clone settings */ /* standby clone settings */
else if (strcmp(name, "use_replication_slots") == 0) else if (strcmp(name, "use_replication_slots") == 0)
@@ -477,6 +477,24 @@ _parse_config(t_configuration_options *options, ItemList *error_list, ItemList *
_("parameter \"upstream_node\" has been renamed to \"upstream_node_id\"")); _("parameter \"upstream_node\" has been renamed to \"upstream_node_id\""));
known_parameter = false; known_parameter = false;
} }
else if (strcmp(name, "loglevel") == 0)
{
item_list_append(warning_list,
_("parameter \"loglevel\" has been enamed to \"log_level\""));
known_parameter = false;
}
else if (strcmp(name, "logfacility") == 0)
{
item_list_append(warning_list,
_("parameter \"logfacility\" has been enamed to \"log_facility\""));
known_parameter = false;
}
else if (strcmp(name, "logfile") == 0)
{
item_list_append(warning_list,
_("parameter \"logfile\" has been enamed to \"log_file\""));
known_parameter = false;
}
else else
{ {
known_parameter = false; known_parameter = false;

View File

@@ -59,9 +59,9 @@ typedef struct
int replication_type; int replication_type;
/* log settings */ /* log settings */
char loglevel[MAXLEN]; char log_level[MAXLEN];
char logfacility[MAXLEN]; char log_facility[MAXLEN];
char logfile[MAXLEN]; char log_file[MAXLEN];
/* standby clone settings */ /* standby clone settings */
bool use_replication_slots; bool use_replication_slots;

View File

@@ -22,3 +22,19 @@ Changed command line options
configuration file option `monitoring_history`. This enables the configuration file option `monitoring_history`. This enables the
setting to be changed without having to modify system service files. setting to be changed without having to modify system service files.
Removed configuration file options
----------------------------------
- `upstream_node`: see note about `--upstream-node-id` above.
Logging changes
---------------
- Following configuration file parameters have been renamed for consistency
with other parameters (and conform to the pattern used by PostgreSQL itself,
which uses the prefix `log_` for logging parameters):
- `loglevel` has been renamed to `log_level`
- `logfile` has been renamed to `log_file`
- `logfacility` has been renamed to `log_facility`
- default value for `log_level` is `INFO` rather than `NOTICE`.

35
log.c
View File

@@ -29,7 +29,7 @@ __attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 0)));
int log_type = REPMGR_STDERR; int log_type = REPMGR_STDERR;
int log_level = LOG_NOTICE; int log_level = LOG_NOTICE;
int last_log_level = LOG_NOTICE; int last_log_level = LOG_INFO;
int verbose_logging = false; int verbose_logging = false;
int terse_logging = false; int terse_logging = false;
/* /*
@@ -156,8 +156,8 @@ log_verbose(int level, const char *fmt, ...)
bool bool
logger_init(t_configuration_options *opts, const char *ident) logger_init(t_configuration_options *opts, const char *ident)
{ {
char *level = opts->loglevel; char *level = opts->log_level;
char *facility = opts->logfacility; char *facility = opts->log_facility;
int l; int l;
int f; int f;
@@ -167,7 +167,7 @@ logger_init(t_configuration_options *opts, const char *ident)
#endif #endif
#ifdef REPMGR_DEBUG #ifdef REPMGR_DEBUG
printf("Logger initialisation (Level: %s, Facility: %s)\n", level, facility); printf("logger initialisation (Level: %s, Facility: %s)\n", level, facility);
#endif #endif
if (!ident) if (!ident)
@@ -179,13 +179,13 @@ logger_init(t_configuration_options *opts, const char *ident)
{ {
l = detect_log_level(level); l = detect_log_level(level);
#ifdef REPMGR_DEBUG #ifdef REPMGR_DEBUG
printf("Assigned level for logger: %d\n", l); printf("assigned level for logger: %d\n", l);
#endif #endif
if (l >= 0) if (l >= 0)
log_level = l; log_level = l;
else else
stderr_log_warning(_("Invalid log level \"%s\" (available values: DEBUG, INFO, NOTICE, WARNING, ERR, ALERT, CRIT or EMERG)\n"), level); stderr_log_warning(_("invalid log level \"%s\" (available values: DEBUG, INFO, NOTICE, WARNING, ERR, ALERT, CRIT or EMERG)\n"), level);
} }
/* /*
@@ -200,19 +200,19 @@ logger_init(t_configuration_options *opts, const char *ident)
f = detect_log_facility(facility); f = detect_log_facility(facility);
#ifdef REPMGR_DEBUG #ifdef REPMGR_DEBUG
printf("Assigned facility for logger: %d\n", f); printf("assigned facility for logger: %d\n", f);
#endif #endif
if (f == 0) if (f == 0)
{ {
/* No syslog requested, just stderr */ /* No syslog requested, just stderr */
#ifdef REPMGR_DEBUG #ifdef REPMGR_DEBUG
printf(_("Use stderr for logging\n")); printf(_("using stderr for logging\n"));
#endif #endif
} }
else if (f == -1) else if (f == -1)
{ {
stderr_log_warning(_("Cannot detect log facility %s (use any of LOCAL0, LOCAL1, ..., LOCAL7, USER or STDERR)\n"), facility); stderr_log_warning(_("cannot detect log facility %s (use any of LOCAL0, LOCAL1, ..., LOCAL7, USER or STDERR)\n"), facility);
} }
#ifdef HAVE_SYSLOG #ifdef HAVE_SYSLOG
else else
@@ -230,11 +230,11 @@ logger_init(t_configuration_options *opts, const char *ident)
setlogmask(LOG_UPTO(log_level)); setlogmask(LOG_UPTO(log_level));
openlog(ident, LOG_CONS | LOG_PID | LOG_NDELAY, syslog_facility); openlog(ident, LOG_CONS | LOG_PID | LOG_NDELAY, syslog_facility);
stderr_log_notice(_("Setup syslog (level: %s, facility: %s)\n"), level, facility); stderr_log_notice(_("setup syslog (level: %s, facility: %s)\n"), level, facility);
} }
#endif #endif
if (*opts->logfile) if (*opts->log_file)
{ {
FILE *fd; FILE *fd;
@@ -243,17 +243,18 @@ logger_init(t_configuration_options *opts, const char *ident)
* the ether and the user won't know what's going on. * the ether and the user won't know what's going on.
*/ */
fd = fopen(opts->logfile, "a"); fd = fopen(opts->log_file, "a");
if (fd == NULL) if (fd == NULL)
{ {
stderr_log_error(_("Unable to open specified logfile '%s' for writing: %s\n"), opts->logfile, strerror(errno)); stderr_log_error(_("unable to open specified log file '%s' for writing: %s\n"),
opts->log_file, strerror(errno));
stderr_log_error(_("Terminating\n")); stderr_log_error(_("Terminating\n"));
exit(ERR_BAD_CONFIG); exit(ERR_BAD_CONFIG);
} }
fclose(fd); fclose(fd);
stderr_log_notice(_("Redirecting logging output to '%s'\n"), opts->logfile); stderr_log_notice(_("redirecting logging output to '%s'\n"), opts->log_file);
fd = freopen(opts->logfile, "a", stderr); fd = freopen(opts->log_file, "a", stderr);
/* /*
* It's possible freopen() may still fail due to e.g. a race condition; * It's possible freopen() may still fail due to e.g. a race condition;
@@ -262,8 +263,8 @@ logger_init(t_configuration_options *opts, const char *ident)
*/ */
if (fd == NULL) if (fd == NULL)
{ {
printf(_("Unable to open specified logfile %s for writing: %s\n"), opts->logfile, strerror(errno)); printf(_("unable to open specified log file %s for writing: %s\n"), opts->log_file, strerror(errno));
printf(_("Terminating\n")); printf(_("terminating\n"));
exit(ERR_BAD_CONFIG); exit(ERR_BAD_CONFIG);
} }
} }

View File

@@ -32,7 +32,7 @@ typedef struct
bool wait; bool wait;
/* logging options */ /* logging options */
char loglevel[MAXLEN]; /* overrides setting in repmgr.conf */ char log_level[MAXLEN]; /* overrides setting in repmgr.conf */
bool log_to_file; bool log_to_file;
bool terse; bool terse;
bool verbose; bool verbose;

View File

@@ -399,7 +399,7 @@ main(int argc, char **argv)
int detected_log_level = detect_log_level(optarg); int detected_log_level = detect_log_level(optarg);
if (detected_log_level != -1) if (detected_log_level != -1)
{ {
strncpy(runtime_options.loglevel, optarg, MAXLEN); strncpy(runtime_options.log_level, optarg, MAXLEN);
} }
else else
{ {
@@ -701,9 +701,9 @@ main(int argc, char **argv)
/* Some configuration file items can be overriden by command line options */ /* Some configuration file items can be overriden by command line options */
/* Command-line parameter -L/--log-level overrides any setting in config file*/ /* Command-line parameter -L/--log-level overrides any setting in config file*/
if (*runtime_options.loglevel != '\0') if (*runtime_options.log_level != '\0')
{ {
strncpy(config_file_options.loglevel, runtime_options.loglevel, MAXLEN); strncpy(config_file_options.log_level, runtime_options.log_level, MAXLEN);
} }
/* /*

View File

@@ -70,13 +70,14 @@
# This is mainly intended for those cases when `repmgr` is executed directly # This is mainly intended for those cases when `repmgr` is executed directly
# by `repmgrd`. # by `repmgrd`.
#loglevel=NOTICE # Log level: possible values are DEBUG, INFO, NOTICE, #log_level=INFO # Log level: possible values are DEBUG, INFO, NOTICE,
# WARNING, ERROR, ALERT, CRIT or EMERG # WARNING, ERROR, ALERT, CRIT or EMERG
#logfacility=STDERR # Logging facility: possible values are STDERR or - for #log_facility=STDERR # Logging facility: possible values are STDERR, or for
# Syslog integration - one of LOCAL0, LOCAL1, ..., LOCAL7, USER # syslog integration, one of LOCAL0, LOCAL1, ..., LOCAL7, USER
#log_file='' # stderr can be redirected to an arbitrary file:
#logfile='' # stderr can be redirected to an arbitrary file:
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Event notification settings # Event notification settings

View File

@@ -8,4 +8,4 @@ upstream_node_id=2
node_name='node1' node_name='node1'
use_replication_slots = true use_replication_slots = true
conninfo = 'host=127.0.0.1 dbname=repmgr user=repmgr port=5501 connect_timeout=2' conninfo = 'host=127.0.0.1 dbname=repmgr user=repmgr port=5501 connect_timeout=2'
loglevel = 'DEBUG' log_level = 'DEBUG'

View File

@@ -5,4 +5,4 @@ upstream_node_id=1
node_name='node2' node_name='node2'
use_replication_slots = true use_replication_slots = true
conninfo = 'host=127.0.0.1 dbname=repmgr user=repmgr port=5501 connect_timeout=2' conninfo = 'host=127.0.0.1 dbname=repmgr user=repmgr port=5501 connect_timeout=2'
loglevel = 'DEBUG' log_level = 'DEBUG'

View File

@@ -102,7 +102,7 @@ main(int argc, char **argv)
{ {
int optindex; int optindex;
int c; int c;
char cli_loglevel[MAXLEN] = ""; char cli_log_level[MAXLEN] = "";
bool cli_monitoring_history = false; bool cli_monitoring_history = false;
RecordStatus record_status; RecordStatus record_status;
@@ -199,10 +199,10 @@ main(int argc, char **argv)
/* -L/--log-level */ /* -L/--log-level */
case 'L': case 'L':
{ {
int detected_cli_loglevel = detect_log_level(optarg); int detected_cli_log_level = detect_log_level(optarg);
if (detected_cli_loglevel != -1) if (detected_cli_log_level != -1)
{ {
strncpy(cli_loglevel, optarg, MAXLEN); strncpy(cli_log_level, optarg, MAXLEN);
} }
else else
{ {
@@ -253,9 +253,9 @@ main(int argc, char **argv)
/* Some configuration file items can be overriden by command line options */ /* Some configuration file items can be overriden by command line options */
/* Command-line parameter -L/--log-level overrides any setting in config file*/ /* Command-line parameter -L/--log-level overrides any setting in config file*/
if (*cli_loglevel != '\0') if (*cli_log_level != '\0')
{ {
strncpy(config_file_options.loglevel, cli_loglevel, MAXLEN); strncpy(config_file_options.log_level, cli_log_level, MAXLEN);
} }
/* /*