log: optimize spdk_log() when logging is disabled

If the log level of the output log is higher than
the process's log level, the system does not output
it, so we needn't generate the formatting logs.

Change-Id: I36be0e6807ed575fcbf1d0ae01f064a6ca2c4539
Signed-off-by: Huiming Xie <xiehuiming@huawei.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/462790
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
x00267701 2019-07-22 10:39:53 -04:00 committed by Changpeng Liu
parent c0d4f7145e
commit a50246fb64

View File

@ -116,6 +116,15 @@ spdk_log(enum spdk_log_level level, const char *file, const int line, const char
char buf[MAX_TMPBUF]; char buf[MAX_TMPBUF];
va_list ap; va_list ap;
if (g_log) {
g_log(level, file, line, func, format);
return;
}
if (level > g_spdk_log_print_level && level > g_spdk_log_level) {
return;
}
switch (level) { switch (level) {
case SPDK_LOG_ERROR: case SPDK_LOG_ERROR:
severity = LOG_ERR; severity = LOG_ERR;
@ -134,10 +143,6 @@ spdk_log(enum spdk_log_level level, const char *file, const int line, const char
return; return;
} }
if (g_log) {
g_log(level, file, line, func, format);
} else {
va_start(ap, format); va_start(ap, format);
vsnprintf(buf, sizeof(buf), format, ap); vsnprintf(buf, sizeof(buf), format, ap);
@ -153,7 +158,6 @@ spdk_log(enum spdk_log_level level, const char *file, const int line, const char
va_end(ap); va_end(ap);
} }
}
static void static void
fdump(FILE *fp, const char *label, const uint8_t *buf, size_t len) fdump(FILE *fp, const char *label, const uint8_t *buf, size_t len)