diff --git a/src/core/log.c b/src/core/log.c index b1b1bc37f47..6f440020ebc 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -252,24 +252,17 @@ core_log(enum core_log_level level, int errnum, const char *file_name, int line_no, const char *function_name, const char *message_format, ...) { char message[_CORE_LOG_MSG_MAXPRINT] = ""; + char *buf = message; + size_t buf_len = sizeof(message); + if (level == CORE_LOG_LEVEL_ERROR_LAST) { + level = CORE_LOG_LEVEL_ERROR; + buf = (char *)last_error_msg_get(); + buf_len = CORE_LAST_ERROR_MSG_MAXPRINT; + } va_list arg; va_start(arg, message_format); - core_log_va(message, sizeof(message), level, errnum, file_name, - line_no, function_name, message_format, arg); - va_end(arg); -} - -void -core_log_to_last(int errnum, const char *file_name, int line_no, - const char *function_name, const char *message_format, ...) -{ - char *last_error = (char *)last_error_msg_get(); - va_list arg; - - va_start(arg, message_format); - core_log_va(last_error, CORE_LAST_ERROR_MSG_MAXPRINT, - CORE_LOG_LEVEL_ERROR, errnum, file_name, line_no, + core_log_va(buf, buf_len, level, errnum, file_name, line_no, function_name, message_format, arg); va_end(arg); } diff --git a/src/core/log_internal.h b/src/core/log_internal.h index 1720b4fc656..8f78558426a 100644 --- a/src/core/log_internal.h +++ b/src/core/log_internal.h @@ -39,6 +39,9 @@ enum core_log_level { CORE_LOG_LEVEL_MAX }; +#define CORE_LOG_LEVEL_ERROR_LAST ((enum core_log_level) \ + (CORE_LOG_LEVEL_ERROR + CORE_LOG_LEVEL_MAX)) + enum core_log_threshold { /* * the main threshold level - the logging messages above this level @@ -130,10 +133,6 @@ void core_log(enum core_log_level level, int errnum, const char *file_name, int line_no, const char *function_name, const char *message_format, ...); -/* Only error messages can last. So, no level has to be specified. */ -void core_log_to_last(int errnum, const char *file_name, int line_no, - const char *function_name, const char *message_format, ...); - #define _CORE_LOG(level, errnum, format, ...) \ do { \ if (level <= Core_log_threshold[CORE_LOG_THRESHOLD]) { \ @@ -147,8 +146,8 @@ void core_log_to_last(int errnum, const char *file_name, int line_no, * Since the log message has to be generated anyway. */ #define CORE_LOG_TO_LAST(errnum, format, ...) \ - core_log_to_last(errnum, __FILE__, __LINE__, __func__, \ - format, ##__VA_ARGS__) + core_log(CORE_LOG_LEVEL_ERROR_LAST, errnum, __FILE__, __LINE__, \ + __func__, format, ##__VA_ARGS__) /* The value fine-tuned to accommodate all possible errno message strings. */ #define _CORE_LOG_MAX_ERRNO_MSG 50