Commit cbe9ea52 authored by Vitaliy Mysak's avatar Vitaliy Mysak Committed by Tomasz Zawadzki
Browse files

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: default avatarVitaliy Mysak <vitaliy.mysak@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1946


Community-CI: Mellanox Build Bot
Community-CI: Broadcom CI
Reviewed-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent 9211c005
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -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.
 *
+1 −1
Original line number Diff line number Diff line
@@ -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
+11 −7
Original line number Diff line number Diff line
@@ -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
+1 −0
Original line number Diff line number Diff line
@@ -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;