Commit 4f651a5c authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Tomasz Zawadzki
Browse files

log: Add spdk_flog/vflog() to write messages to a specified file



Add two public APIs, spdk_flog() and spdk_vflog(), to write messages to
a specified file. These APIs will be used to write JSON RPC call history
to a specified file.

Signed-off-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
Change-Id: I21cc15cc7984d068a9ba567708b86c162e54705a
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/18826


Reviewed-by: default avatarKrzysztof Karas <krzysztof.karas@intel.com>
Reviewed-by: default avatarSebastian Brzezinka <sebastian.brzezinka@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent ee47846a
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -12,6 +12,10 @@ The `phys_addr` parameter in spdk_*_malloc() functions is now invalid. Passing n
will return NULL from the functions. The parameter was deprecated in SPDK 19.04.
For retrieving physical addresses, spdk_vtophys() should be used instead.

### log

New APIs, `spdk_flog` and `spdk_vflog`, were added to write messages to the specified log file.

## v23.05

### accel
+27 −0
Original line number Diff line number Diff line
@@ -170,6 +170,33 @@ void spdk_log(enum spdk_log_level level, const char *file, const int line, const
void spdk_vlog(enum spdk_log_level level, const char *file, const int line, const char *func,
	       const char *format, va_list ap);

/**
 * Write messages to the log file. If \c level is set to \c SPDK_LOG_DISABLED,
 * this log message won't be written.
 *
 * \param fp File to hold the log.
 * \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.
 */
void spdk_flog(FILE *fp, const char *file, const int line, const char *func,
	       const char *format, ...) __attribute__((__format__(__printf__, 5, 6)));

/**
 * Same as spdk_flog except that instead of being called with variable number of
 * arguments it is called with an argument list as defined in stdarg.h
 *
 * \param fp File to hold the log.
 * \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_vflog(FILE *fp, 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
@@ -7,7 +7,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk

SO_VER := 6
SO_MINOR := 0
SO_MINOR := 1
SO_SUFFIX := $(SO_VER).$(SO_MINOR)

C_SRCS = log.c log_flags.c log_deprecated.c
+31 −0
Original line number Diff line number Diff line
@@ -175,6 +175,37 @@ spdk_vlog(enum spdk_log_level level, const char *file, const int line, const cha
	}
}

void
spdk_vflog(FILE *fp, const char *file, const int line, const char *func,
	   const char *format, va_list ap)
{
	char buf[MAX_TMPBUF];
	char timestamp[64];

	vsnprintf(buf, sizeof(buf), format, ap);

	get_timestamp_prefix(timestamp, sizeof(timestamp));

	if (file) {
		fprintf(fp, "%s%s:%4d:%s: %s", timestamp, file, line, func, buf);
	} else {
		fprintf(fp, "%s%s", timestamp, buf);
	}

	fflush(fp);
}

void
spdk_flog(FILE *fp, const char *file, const int line, const char *func,
	  const char *format, ...)
{
	va_list ap;

	va_start(ap, format);
	spdk_vflog(fp, file, line, func, format, ap);
	va_end(ap);
}

static void
fdump(FILE *fp, const char *label, const uint8_t *buf, size_t len)
{
+2 −0
Original line number Diff line number Diff line
@@ -11,6 +11,8 @@
	spdk_log_get_print_level;
	spdk_log;
	spdk_vlog;
	spdk_flog;
	spdk_vflog;
	spdk_log_dump;
	spdk_log_get_flag;
	spdk_log_set_flag;