diff --git a/include/spdk/log.h b/include/spdk/log.h index 6c5ac8e39..b81233d0e 100644 --- a/include/spdk/log.h +++ b/include/spdk/log.h @@ -154,6 +154,20 @@ enum spdk_log_level spdk_log_get_print_level(void); void spdk_log(enum spdk_log_level level, const char *file, const int line, const char *func, const char *format, ...) __attribute__((__format__(__printf__, 5, 6))); +/** + * Same as spdk_log except that instead of being called with variable number of + * arguments it is called with an argument list as defined in stdarg.h + * + * \param level Log level threshold. + * \param file Name of the current source file. + * \param line Current source line number. + * \param func Current source function name. + * \param format Format string to the message. + * \param ap printf arguments + */ +void spdk_vlog(enum spdk_log_level level, const char *file, const int line, const char *func, + const char *format, va_list ap); + /** * Log the contents of a raw buffer to a file. * diff --git a/lib/log/Makefile b/lib/log/Makefile index 9ca97ab1c..a05aff983 100644 --- a/lib/log/Makefile +++ b/lib/log/Makefile @@ -35,7 +35,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..) include $(SPDK_ROOT_DIR)/mk/spdk.common.mk SO_VER := 2 -SO_MINOR := 0 +SO_MINOR := 1 SO_SUFFIX := $(SO_VER).$(SO_MINOR) C_SRCS = log.c log_flags.c diff --git a/lib/log/log.c b/lib/log/log.c index c5682c51e..09c060863 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -127,16 +127,24 @@ get_timestamp_prefix(char *buf, int buf_size) void spdk_log(enum spdk_log_level level, const char *file, const int line, const char *func, const char *format, ...) +{ + va_list ap; + + va_start(ap, format); + spdk_vlog(level, file, line, func, format, ap); + va_end(ap); +} + +void +spdk_vlog(enum spdk_log_level level, const char *file, const int line, const char *func, + const char *format, va_list ap) { int severity = LOG_INFO; char buf[MAX_TMPBUF]; char timestamp[32]; - va_list ap; if (g_log) { - va_start(ap, format); g_log(level, file, line, func, format, ap); - va_end(ap); return; } @@ -162,8 +170,6 @@ spdk_log(enum spdk_log_level level, const char *file, const int line, const char return; } - va_start(ap, format); - vsnprintf(buf, sizeof(buf), format, ap); if (level <= g_spdk_log_print_level) { @@ -183,8 +189,6 @@ spdk_log(enum spdk_log_level level, const char *file, const int line, const char syslog(severity, "%s", buf); } } - - va_end(ap); } static void diff --git a/lib/log/spdk_log.map b/lib/log/spdk_log.map index 6c202f9a4..a91e931fc 100644 --- a/lib/log/spdk_log.map +++ b/lib/log/spdk_log.map @@ -11,6 +11,7 @@ spdk_log_set_print_level; spdk_log_get_print_level; spdk_log; + spdk_vlog; spdk_log_dump; spdk_log_get_flag; spdk_log_set_flag;