From cbe9ea52d0f975601b202c74e190e2fbad903793 Mon Sep 17 00:00:00 2001 From: Vitaliy Mysak Date: Mon, 20 Apr 2020 18:42:00 +0200 Subject: [PATCH] lib/log: add spdk_vlog function Some users of SPDK API, such as OCF, may want to generate logs with arguments themselves. In that case they would need to first create a buffer and then pass that buffer as a single argument to spdk_log(). This change adds spdk_vlog() which accepts va_list as argument list, so it is easier to use spdk_log(). Change-Id: Ie2a3ac481035a250fcd68d0f9b8292008ebb6fe0 Signed-off-by: Vitaliy Mysak Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1946 Community-CI: Mellanox Build Bot Community-CI: Broadcom CI Reviewed-by: Darek Stojaczyk Reviewed-by: Jim Harris Tested-by: SPDK CI Jenkins --- include/spdk/log.h | 14 ++++++++++++++ lib/log/Makefile | 2 +- lib/log/log.c | 18 +++++++++++------- lib/log/spdk_log.map | 1 + 4 files changed, 27 insertions(+), 8 deletions(-) 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;