Skip to content

Commit

Permalink
common: replace core_log_to_last() by core_log w/ new level
Browse files Browse the repository at this point in the history
Signed-off-by: Tomasz Gromadzki <tomasz.gromadzki@intel.com>
  • Loading branch information
grom72 committed Feb 27, 2024
1 parent 6d16e30 commit 1071ff2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
23 changes: 8 additions & 15 deletions src/core/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
11 changes: 5 additions & 6 deletions src/core/log_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]) { \
Expand All @@ -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
Expand Down

0 comments on commit 1071ff2

Please sign in to comment.