From 1d06030aecfb0ad7f7bfff36d98b9d74f244de35 Mon Sep 17 00:00:00 2001 From: John Jones Date: Mon, 3 Apr 2017 13:30:07 -0500 Subject: [PATCH] attempting fix of va_list bug --- utils/logger.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/utils/logger.c b/utils/logger.c index 45ff8d4..5051462 100644 --- a/utils/logger.c +++ b/utils/logger.c @@ -33,6 +33,28 @@ void libp2p_logger_log(const char* area, int log_level, const char* format, ...) } } +/** + * Log a message to the console + * @param area the class it is coming from + * @param log_level logger level + * @param format the logging string + * @param ... params + */ +void libp2p_logger_vlog(const char* area, int log_level, const char* format, va_list argptr) { + if (log_level <= CURRENT_LOGLEVEL) { + int found = 0; + for (int i = 0; i < logger_classes_len; i++) { + if (strcmp(logger_classes[i], area) == 0) { + found = 1; + break; + } + } + if (found) { + vfprintf(stderr, format, argptr); + } + } +} + /** * Log a debug message to the console * @param area the class it is coming from @@ -42,7 +64,7 @@ void libp2p_logger_log(const char* area, int log_level, const char* format, ...) void libp2p_logger_debug(const char* area, const char* format, ...) { va_list argptr; va_start(argptr, format); - libp2p_logger_log(area, LOGLEVEL_DEBUG, format, argptr); + libp2p_logger_vlog(area, LOGLEVEL_DEBUG, format, argptr); va_end(argptr); } @@ -55,6 +77,6 @@ void libp2p_logger_debug(const char* area, const char* format, ...) { void libp2p_logger_error(const char* area, const char* format, ...) { va_list argptr; va_start(argptr, format); - libp2p_logger_log(area, LOGLEVEL_ERROR, format, argptr); + libp2p_logger_vlog(area, LOGLEVEL_ERROR, format, argptr); va_end(argptr); }