log: Change priority to generic log level

The log priority was very syslog specific. Instead, create
a generic set of log levels as an enum.

The log level/priority isn't actually used anywhere today.

Change-Id: Iebcf6b7e1b263b56f317b86b5f2ea0d9e45170f3
Signed-off-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-on: https://review.gerrithub.io/365267
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
Ben Walker 2017-06-13 11:08:48 -07:00 committed by Daniel Verkamp
parent 99cad03497
commit dda26fba8b
4 changed files with 43 additions and 42 deletions

View File

@ -41,6 +41,25 @@
#include "spdk/stdinc.h"
enum spdk_log_level {
SPDK_LOG_ERROR,
SPDK_LOG_WARN,
SPDK_LOG_NOTICE,
SPDK_LOG_INFO,
SPDK_LOG_DEBUG,
};
/**
* Set the threshold to log messages. Messages with a higher
* level than this are ignored.
*/
void spdk_log_set_level(enum spdk_log_level level);
/**
* Get the current log threshold.
*/
enum spdk_log_level spdk_log_get_level(void);
/*
* Default: 1 - noticelog messages will print to stderr and syslog.
* Can be set to 0 to print noticelog messages to syslog only.
@ -56,7 +75,7 @@ extern unsigned int spdk_g_notice_stderr_flag;
int spdk_set_log_facility(const char *facility);
const char *spdk_get_log_facility(void);
int spdk_set_log_priority(const char *priority);
void spdk_noticelog(const char *file, const int line, const char *func,
const char *format, ...) __attribute__((__format__(__printf__, 4, 5)));
void spdk_warnlog(const char *file, const int line, const char *func,

View File

@ -41,7 +41,7 @@
#include "spdk/trace.h"
#define SPDK_APP_DEFAULT_LOG_FACILITY "local7"
#define SPDK_APP_DEFAULT_LOG_PRIORITY "info"
#define SPDK_APP_DEFAULT_LOG_PRIORITY SPDK_LOG_INFO
#define SPDK_APP_DPDK_DEFAULT_MEM_SIZE -1
#define SPDK_APP_DPDK_DEFAULT_MASTER_CORE -1
@ -288,12 +288,7 @@ spdk_app_start(struct spdk_app_opts *opts, spdk_event_fn start_fn,
exit(EXIT_FAILURE);
}
rc = spdk_set_log_priority(SPDK_APP_DEFAULT_LOG_PRIORITY);
if (rc < 0) {
SPDK_ERRLOG("log priority error\n");
spdk_conf_free(g_spdk_app.config);
exit(EXIT_FAILURE);
}
spdk_log_set_level(SPDK_APP_DEFAULT_LOG_PRIORITY);
spdk_open_log();
if (opts->reactor_mask == NULL) {

View File

@ -39,7 +39,7 @@ static TAILQ_HEAD(, spdk_trace_flag) g_trace_flags = TAILQ_HEAD_INITIALIZER(g_tr
unsigned int spdk_g_notice_stderr_flag = 1;
int spdk_g_log_facility = LOG_DAEMON;
unsigned int spdk_g_log_priority = LOG_NOTICE;
static enum spdk_log_level g_spdk_log_level = SPDK_LOG_NOTICE;
SPDK_LOG_REGISTER_TRACE_FLAG("debug", SPDK_TRACE_DEBUG)
@ -79,17 +79,16 @@ static const struct syslog_code facilitynames[] = {
{ NULL, -1, }
};
static const struct syslog_code prioritynames[] = {
{ "alert", LOG_ALERT, },
{ "crit", LOG_CRIT, },
{ "debug", LOG_DEBUG, },
{ "emerg", LOG_EMERG, },
{ "err", LOG_ERR, },
{ "info", LOG_INFO, },
{ "notice", LOG_NOTICE, },
{ "warning", LOG_WARNING, },
{ NULL, -1, }
};
void
spdk_log_set_level(enum spdk_log_level level)
{
g_spdk_log_level = level;
}
enum spdk_log_level
spdk_log_get_level(void) {
return g_spdk_log_level;
}
int
spdk_set_log_facility(const char *facility)
@ -124,22 +123,6 @@ spdk_get_log_facility(void)
return def_name;
}
int
spdk_set_log_priority(const char *priority)
{
int i;
for (i = 0; prioritynames[i].c_name != NULL; i++) {
if (strcasecmp(prioritynames[i].c_name, priority) == 0) {
spdk_g_log_priority = prioritynames[i].c_val;
return 0;
}
}
spdk_g_log_priority = LOG_NOTICE;
return -1;
}
void
spdk_noticelog(const char *file, const int line, const char *func,
const char *format, ...)

View File

@ -60,12 +60,16 @@ log_test(void)
SPDK_CU_ASSERT_FATAL(buf != NULL);
CU_ASSERT_STRING_EQUAL(buf, "local7");
rc = spdk_set_log_priority("test");
CU_ASSERT(rc == -1);
CU_ASSERT_EQUAL(spdk_g_log_priority, LOG_NOTICE);
rc = spdk_set_log_priority("debug");
CU_ASSERT(rc == 0);
CU_ASSERT_EQUAL(spdk_g_log_priority, LOG_DEBUG);
spdk_log_set_level(SPDK_LOG_ERROR);
CU_ASSERT_EQUAL(spdk_log_get_level(), SPDK_LOG_ERROR);
spdk_log_set_level(SPDK_LOG_WARN);
CU_ASSERT_EQUAL(spdk_log_get_level(), SPDK_LOG_WARN);
spdk_log_set_level(SPDK_LOG_NOTICE);
CU_ASSERT_EQUAL(spdk_log_get_level(), SPDK_LOG_NOTICE);
spdk_log_set_level(SPDK_LOG_INFO);
CU_ASSERT_EQUAL(spdk_log_get_level(), SPDK_LOG_INFO);
spdk_log_set_level(SPDK_LOG_DEBUG);
CU_ASSERT_EQUAL(spdk_log_get_level(), SPDK_LOG_DEBUG);
#ifdef DEBUG
CU_ASSERT(spdk_log_get_trace_flag("debug") == false);