log: add an API to return syslog level based on SPDK's log level

Change-Id: I970119385989e7d97bda065f5aa2bbd82519c655
Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9103
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: John Levon <levon@movementarian.org>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Paul Luse <paul.e.luse@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
This commit is contained in:
Changpeng Liu 2021-08-06 17:29:44 +08:00 committed by Tomasz Zawadzki
parent aa51757648
commit 01936d2ed8
5 changed files with 39 additions and 16 deletions

View File

@ -2,6 +2,11 @@
## v21.10: (Upcoming Release)
### log
Added API `spdk_log_to_syslog_level` to return syslog level based on SPDK's
log level.
## v21.07:
### accel_fw

View File

@ -101,6 +101,14 @@ void spdk_log_set_level(enum spdk_log_level level);
*/
enum spdk_log_level spdk_log_get_level(void);
/**
* Get syslog level based on SPDK current log level threshold.
*
* \param level Log level threshold
* \return -1 for disable log print, otherwise is syslog level.
*/
int spdk_log_to_syslog_level(enum spdk_log_level level);
/**
* Set the current log level threshold for printing to stderr.
* Messages with a level less than or equal to this level

View File

@ -35,7 +35,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
SO_VER := 4
SO_MINOR := 0
SO_MINOR := 1
SO_SUFFIX := $(SO_VER).$(SO_MINOR)
C_SRCS = log.c log_flags.c

View File

@ -111,6 +111,28 @@ spdk_log(enum spdk_log_level level, const char *file, const int line, const char
va_end(ap);
}
int
spdk_log_to_syslog_level(enum spdk_log_level level)
{
switch (level) {
case SPDK_LOG_DEBUG:
case SPDK_LOG_INFO:
return LOG_INFO;
case SPDK_LOG_NOTICE:
return LOG_NOTICE;
case SPDK_LOG_WARN:
return LOG_WARNING;
case SPDK_LOG_ERROR:
return LOG_ERR;
case SPDK_LOG_DISABLED:
return -1;
default:
break;
}
return LOG_INFO;
}
void
spdk_vlog(enum spdk_log_level level, const char *file, const int line, const char *func,
const char *format, va_list ap)
@ -128,21 +150,8 @@ spdk_vlog(enum spdk_log_level level, const char *file, const int line, const cha
return;
}
switch (level) {
case SPDK_LOG_ERROR:
severity = LOG_ERR;
break;
case SPDK_LOG_WARN:
severity = LOG_WARNING;
break;
case SPDK_LOG_NOTICE:
severity = LOG_NOTICE;
break;
case SPDK_LOG_INFO:
case SPDK_LOG_DEBUG:
severity = LOG_INFO;
break;
case SPDK_LOG_DISABLED:
severity = spdk_log_to_syslog_level(level);
if (severity < 0) {
return;
}

View File

@ -6,6 +6,7 @@
spdk_log_close;
spdk_log_set_level;
spdk_log_get_level;
spdk_log_to_syslog_level;
spdk_log_set_print_level;
spdk_log_get_print_level;
spdk_log;