From 80344babd7c669519df9ecfe106f5ceee35944f7 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Thu, 5 Nov 2015 16:14:36 +0200 Subject: [PATCH] Log manager additions. Changes related to the replacement of the notion of logfiles with the notion of syslog priorities. --- log_manager/log_manager.cc | 139 +++++++++++++++++++++++++++++++++++++ log_manager/log_manager.h | 5 ++ 2 files changed, 144 insertions(+) diff --git a/log_manager/log_manager.cc b/log_manager/log_manager.cc index 7444cb393..979a29815 100644 --- a/log_manager/log_manager.cc +++ b/log_manager/log_manager.cc @@ -2989,3 +2989,142 @@ void logmanager_enable_maxscalelog(int val) { do_maxscalelog = val; } + + +/** + * Explicitly ensure that all pending log messages are flushed. + * + * @return 0 if the flushing was successfully initiated, otherwise -1. + * + * Note that the return value only indicates whether the flushing was + * successfully initiated, not whether the actual flushing has been + * performed. + */ +int mxs_log_flush() +{ + return skygw_log_flush(LOGFILE_ERROR); +} + +/** + * Rotate the log-file. That is, close the current one and create a new one + * with a larger sequence number. + * + * @return 0 if the rotating was successfully initiated, otherwise -1. + * + * Note that the return value only indicates whether the rotating was + * successfully initiated, not whether the actual rotation has been + * performed. + */ +int mxs_log_rotate() +{ + return skygw_log_rotate(LOGFILE_ERROR); +} + +static bool convert_priority_to_file(int priority, logfile_id_t* idp, const char** textp) +{ + bool converted = true; + + *idp = (logfile_id_t) -1; + *textp = NULL; + + switch (priority) + { + case LOG_DEBUG: + *idp = LOGFILE_DEBUG; + break; + case LOG_INFO: + *idp = LOGFILE_TRACE; + break; + case LOG_NOTICE: + *idp = LOGFILE_MESSAGE; + break; + case LOG_ERR: + *idp = LOGFILE_ERROR; + break; + case LOG_WARNING: + *textp = "LOG_WARNING"; + break; + case LOG_CRIT: + *textp = "LOG_CRIT"; + break; + case LOG_ALERT: + *textp = "LOG_ALERT"; + break; + case LOG_EMERG: + *textp = "LOG_EMERG"; + break; + default: + converted = false; + } + + return converted; +} + +/** + * Enable a particular syslog priority. + * + * @param priority One of the LOG_ERR etc. constants from sys/syslog.h. + * @return 0 if the priority was valid, -1 otherwise. + */ +int mxs_log_enable_priority(int priority) +{ + int rv = -1; + logfile_id_t id; + const char* text; + + if (convert_priority_to_file(priority, &id, &text)) + { + if (!text) + { + rv = skygw_log_enable(id); + } + else + { + // TODO: Change to warning when available. + MXS_DEBUG("Attempt to enable syslog priority %s, which is not available yet.", text); + rv = 0; + } + } + else + { + MXS_ERROR("Attempt to enable unknown syslog priority: %d", priority); + } + + return rv; +} + +/** + * Disable a particular syslog priority. + * + * @param priority One of the LOG_ERR etc. constants from sys/syslog.h. + * + * Note that there is no hierarchy. That is, disabling a priority of + * high importance, such as LOG_ERR, does not automatically disable + * all lower prioritys. + */ +int mxs_log_disable_priority(int priority) +{ + int rv = -1; + logfile_id_t id; + const char* text; + + if (convert_priority_to_file(priority, &id, &text)) + { + if (!text) + { + rv = skygw_log_disable(id); + } + else + { + // TODO: Change to warning when available. + MXS_DEBUG("Attempt to enable syslog priority %s, which is not available.", text); + rv = 0; + } + } + else + { + MXS_ERROR("Attempt to enable unknown syslog priority: %d", priority); + } + + return rv; +} diff --git a/log_manager/log_manager.h b/log_manager/log_manager.h index 2b838dc13..5e11045f7 100644 --- a/log_manager/log_manager.h +++ b/log_manager/log_manager.h @@ -140,6 +140,11 @@ extern int lm_enabled_logfiles_bitmask; extern ssize_t log_ses_count[]; extern __thread log_info_t tls_log_info; +int mxs_log_flush(); +int mxs_log_rotate(); +int mxs_log_enable_priority(int priority); +int mxs_log_disable_priority(int priority); + bool skygw_logmanager_init(int argc, char* argv[]); void skygw_logmanager_done(void); void skygw_logmanager_exit(void);