lib/log: passing va_list to user-provided log call

va_list is not passed in logfunc, so the user-provided log call can't
get the arguments corresponding to the format string.

This patch fixes it and replaces log func pointer in spdk_app_opts
with logfunc.

Change-Id: I7f7806f47c4fd8f36f3234aa5a8c877db0fc7140
Signed-off-by: Yang Fan <fanyang@smartx.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/469828
Reviewed-by: Feng,Li <fengli@smartx.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
fanyang 2019-09-30 16:46:37 +08:00 committed by Jim Harris
parent 3a9b5f3cd2
commit bb9d17a5c3
3 changed files with 15 additions and 10 deletions

View File

@ -135,15 +135,8 @@ struct spdk_app_opts {
/**
* for passing user-provided log call
*
* \param level Log level threshold.
* \param file Name of the current source file.
* \param line Current source file line.
* \param func Current source function name.
* \param format Format string to the message.
*/
void (* log)(int level, const char *file, const int line,
const char *func, const char *format);
logfunc *log;
};

View File

@ -45,8 +45,18 @@
extern "C" {
#endif
/**
* for passing user-provided log call
*
* \param level Log level threshold.
* \param file Name of the current source file.
* \param line Current source file line.
* \param func Current source function name.
* \param format Format string to the message.
* \param args Additional arguments for format string.
*/
typedef void logfunc(int level, const char *file, const int line,
const char *func, const char *format);
const char *func, const char *format, va_list args);
/**
* Initialize the logging module. Messages prior

View File

@ -117,7 +117,9 @@ spdk_log(enum spdk_log_level level, const char *file, const int line, const char
va_list ap;
if (g_log) {
g_log(level, file, line, func, format);
va_start(ap, format);
g_log(level, file, line, func, format, ap);
va_end(ap);
return;
}