Add log_hint() function for logging hints

There are a few places where additional hints are written as log
output, usually LOG_NOTICE. Create an explicit function to provide
hints in a standardized manner; by storing the log level of the
previous logger call, we can ensure the hint is only displayed when
the log message itself would be.

Part of an ongoing effort to better control repmgr's logging output.
This commit is contained in:
Ian Barwick
2015-11-13 14:29:11 +09:00
parent ea01d1d30b
commit ae84041a4e
4 changed files with 30 additions and 11 deletions

18
log.c
View File

@@ -44,7 +44,7 @@ static int detect_log_facility(const char *facility);
int log_type = REPMGR_STDERR;
int log_level = LOG_NOTICE;
int last_log_level = LOG_NOTICE;
void
stderr_log_with_level(const char *level_name, int level, const char *fmt, ...)
@@ -54,6 +54,12 @@ stderr_log_with_level(const char *level_name, int level, const char *fmt, ...)
char buff[100];
va_list ap;
/*
* Store the requested level so that if there's a subsequent
* log_hint(), we can suppress that if appropriate.
*/
last_log_level = level;
if (log_level >= level)
{
time(&t);
@@ -69,6 +75,16 @@ stderr_log_with_level(const char *level_name, int level, const char *fmt, ...)
}
}
void
log_hint(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
stderr_log_with_level("HINT", last_log_level, fmt, ap);
va_end(ap);
}
bool
logger_init(t_configuration_options * opts, const char *ident, const char *level, const char *facility)