attempting fix of va_list bug

This commit is contained in:
John Jones 2017-04-03 13:30:07 -05:00
parent aa92d72541
commit 1d06030aec

View file

@ -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);
}