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
*
* 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
*/
memset(options->logfacility, 0, sizeof(options->logfacility));
memset(options->logfile, 0, sizeof(options->logfile));
memset(options->log_facility, 0, sizeof(options->log_facility));
memset(options->log_file, 0, sizeof(options->log_file));
/* standby clone settings
* ----------------------- */
@@ -348,12 +348,12 @@ _parse_config(t_configuration_options *options, ItemList *error_list, ItemList *
}
/* log settings */
else if (strcmp(name, "logfile") == 0)
strncpy(options->logfile, value, MAXLEN);
else if (strcmp(name, "loglevel") == 0)
strncpy(options->loglevel, value, MAXLEN);
else if (strcmp(name, "logfacility") == 0)
strncpy(options->logfacility, value, MAXLEN);
else if (strcmp(name, "log_file") == 0)
strncpy(options->log_file, value, MAXLEN);
else if (strcmp(name, "log_level") == 0)
strncpy(options->log_level, value, MAXLEN);
else if (strcmp(name, "log_facility") == 0)
strncpy(options->log_facility, value, MAXLEN);
/* standby clone settings */
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\""));
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
{
known_parameter = false;

View File

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

View File

@@ -22,3 +22,19 @@ Changed command line options
configuration file option `monitoring_history`. This enables the
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_level = LOG_NOTICE;
int last_log_level = LOG_NOTICE;
int last_log_level = LOG_INFO;
int verbose_logging = false;
int terse_logging = false;
/*
@@ -156,8 +156,8 @@ log_verbose(int level, const char *fmt, ...)
bool
logger_init(t_configuration_options *opts, const char *ident)
{
char *level = opts->loglevel;
char *facility = opts->logfacility;
char *level = opts->log_level;
char *facility = opts->log_facility;
int l;
int f;
@@ -167,7 +167,7 @@ logger_init(t_configuration_options *opts, const char *ident)
#endif
#ifdef REPMGR_DEBUG
printf("Logger initialisation (Level: %s, Facility: %s)\n", level, facility);
printf("logger initialisation (Level: %s, Facility: %s)\n", level, facility);
#endif
if (!ident)
@@ -179,13 +179,13 @@ logger_init(t_configuration_options *opts, const char *ident)
{
l = detect_log_level(level);
#ifdef REPMGR_DEBUG
printf("Assigned level for logger: %d\n", l);
printf("assigned level for logger: %d\n", l);
#endif
if (l >= 0)
log_level = l;
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);
#ifdef REPMGR_DEBUG
printf("Assigned facility for logger: %d\n", f);
printf("assigned facility for logger: %d\n", f);
#endif
if (f == 0)
{
/* No syslog requested, just stderr */
#ifdef REPMGR_DEBUG
printf(_("Use stderr for logging\n"));
printf(_("using stderr for logging\n"));
#endif
}
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
else
@@ -230,11 +230,11 @@ logger_init(t_configuration_options *opts, const char *ident)
setlogmask(LOG_UPTO(log_level));
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
if (*opts->logfile)
if (*opts->log_file)
{
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.
*/
fd = fopen(opts->logfile, "a");
fd = fopen(opts->log_file, "a");
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"));
exit(ERR_BAD_CONFIG);
}
fclose(fd);
stderr_log_notice(_("Redirecting logging output to '%s'\n"), opts->logfile);
fd = freopen(opts->logfile, "a", stderr);
stderr_log_notice(_("redirecting logging output to '%s'\n"), opts->log_file);
fd = freopen(opts->log_file, "a", stderr);
/*
* 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)
{
printf(_("Unable to open specified logfile %s for writing: %s\n"), opts->logfile, strerror(errno));
printf(_("Terminating\n"));
printf(_("unable to open specified log file %s for writing: %s\n"), opts->log_file, strerror(errno));
printf(_("terminating\n"));
exit(ERR_BAD_CONFIG);
}
}

View File

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

View File

@@ -399,7 +399,7 @@ main(int argc, char **argv)
int detected_log_level = detect_log_level(optarg);
if (detected_log_level != -1)
{
strncpy(runtime_options.loglevel, optarg, MAXLEN);
strncpy(runtime_options.log_level, optarg, MAXLEN);
}
else
{
@@ -701,9 +701,9 @@ main(int argc, char **argv)
/* Some configuration file items can be overriden by command line options */
/* 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
# 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
#logfacility=STDERR # Logging facility: possible values are STDERR or - for
# Syslog integration - one of LOCAL0, LOCAL1, ..., LOCAL7, USER
#log_facility=STDERR # Logging facility: possible values are STDERR, or for
# 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

View File

@@ -8,4 +8,4 @@ upstream_node_id=2
node_name='node1'
use_replication_slots = true
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'
use_replication_slots = true
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 c;
char cli_loglevel[MAXLEN] = "";
char cli_log_level[MAXLEN] = "";
bool cli_monitoring_history = false;
RecordStatus record_status;
@@ -199,10 +199,10 @@ main(int argc, char **argv)
/* -L/--log-level */
case 'L':
{
int detected_cli_loglevel = detect_log_level(optarg);
if (detected_cli_loglevel != -1)
int detected_cli_log_level = detect_log_level(optarg);
if (detected_cli_log_level != -1)
{
strncpy(cli_loglevel, optarg, MAXLEN);
strncpy(cli_log_level, optarg, MAXLEN);
}
else
{
@@ -253,9 +253,9 @@ main(int argc, char **argv)
/* Some configuration file items can be overriden by command line options */
/* 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);
}
/*