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:
parent
99cad03497
commit
dda26fba8b
@ -41,6 +41,25 @@
|
|||||||
|
|
||||||
#include "spdk/stdinc.h"
|
#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.
|
* Default: 1 - noticelog messages will print to stderr and syslog.
|
||||||
* Can be set to 0 to print noticelog messages to syslog only.
|
* 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);
|
int spdk_set_log_facility(const char *facility);
|
||||||
const char *spdk_get_log_facility(void);
|
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,
|
void spdk_noticelog(const char *file, const int line, const char *func,
|
||||||
const char *format, ...) __attribute__((__format__(__printf__, 4, 5)));
|
const char *format, ...) __attribute__((__format__(__printf__, 4, 5)));
|
||||||
void spdk_warnlog(const char *file, const int line, const char *func,
|
void spdk_warnlog(const char *file, const int line, const char *func,
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
#include "spdk/trace.h"
|
#include "spdk/trace.h"
|
||||||
|
|
||||||
#define SPDK_APP_DEFAULT_LOG_FACILITY "local7"
|
#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_MEM_SIZE -1
|
||||||
#define SPDK_APP_DPDK_DEFAULT_MASTER_CORE -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);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = spdk_set_log_priority(SPDK_APP_DEFAULT_LOG_PRIORITY);
|
spdk_log_set_level(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_open_log();
|
spdk_open_log();
|
||||||
|
|
||||||
if (opts->reactor_mask == NULL) {
|
if (opts->reactor_mask == NULL) {
|
||||||
|
@ -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;
|
unsigned int spdk_g_notice_stderr_flag = 1;
|
||||||
int spdk_g_log_facility = LOG_DAEMON;
|
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)
|
SPDK_LOG_REGISTER_TRACE_FLAG("debug", SPDK_TRACE_DEBUG)
|
||||||
|
|
||||||
@ -79,17 +79,16 @@ static const struct syslog_code facilitynames[] = {
|
|||||||
{ NULL, -1, }
|
{ NULL, -1, }
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct syslog_code prioritynames[] = {
|
void
|
||||||
{ "alert", LOG_ALERT, },
|
spdk_log_set_level(enum spdk_log_level level)
|
||||||
{ "crit", LOG_CRIT, },
|
{
|
||||||
{ "debug", LOG_DEBUG, },
|
g_spdk_log_level = level;
|
||||||
{ "emerg", LOG_EMERG, },
|
}
|
||||||
{ "err", LOG_ERR, },
|
|
||||||
{ "info", LOG_INFO, },
|
enum spdk_log_level
|
||||||
{ "notice", LOG_NOTICE, },
|
spdk_log_get_level(void) {
|
||||||
{ "warning", LOG_WARNING, },
|
return g_spdk_log_level;
|
||||||
{ NULL, -1, }
|
}
|
||||||
};
|
|
||||||
|
|
||||||
int
|
int
|
||||||
spdk_set_log_facility(const char *facility)
|
spdk_set_log_facility(const char *facility)
|
||||||
@ -124,22 +123,6 @@ spdk_get_log_facility(void)
|
|||||||
return def_name;
|
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
|
void
|
||||||
spdk_noticelog(const char *file, const int line, const char *func,
|
spdk_noticelog(const char *file, const int line, const char *func,
|
||||||
const char *format, ...)
|
const char *format, ...)
|
||||||
|
@ -60,12 +60,16 @@ log_test(void)
|
|||||||
SPDK_CU_ASSERT_FATAL(buf != NULL);
|
SPDK_CU_ASSERT_FATAL(buf != NULL);
|
||||||
CU_ASSERT_STRING_EQUAL(buf, "local7");
|
CU_ASSERT_STRING_EQUAL(buf, "local7");
|
||||||
|
|
||||||
rc = spdk_set_log_priority("test");
|
spdk_log_set_level(SPDK_LOG_ERROR);
|
||||||
CU_ASSERT(rc == -1);
|
CU_ASSERT_EQUAL(spdk_log_get_level(), SPDK_LOG_ERROR);
|
||||||
CU_ASSERT_EQUAL(spdk_g_log_priority, LOG_NOTICE);
|
spdk_log_set_level(SPDK_LOG_WARN);
|
||||||
rc = spdk_set_log_priority("debug");
|
CU_ASSERT_EQUAL(spdk_log_get_level(), SPDK_LOG_WARN);
|
||||||
CU_ASSERT(rc == 0);
|
spdk_log_set_level(SPDK_LOG_NOTICE);
|
||||||
CU_ASSERT_EQUAL(spdk_g_log_priority, LOG_DEBUG);
|
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
|
#ifdef DEBUG
|
||||||
CU_ASSERT(spdk_log_get_trace_flag("debug") == false);
|
CU_ASSERT(spdk_log_get_trace_flag("debug") == false);
|
||||||
|
Loading…
Reference in New Issue
Block a user