log: Add a print to stderr threshold
Change-Id: I9c1865ff1ca2d8093227c89aa9857ff18d3e346a Signed-off-by: Ben Walker <benjamin.walker@intel.com> Reviewed-on: https://review.gerrithub.io/365294 Tested-by: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
cca697b0ec
commit
65918cb8ff
@ -95,6 +95,7 @@ main(int argc, char **argv)
|
||||
int rc, app_rc;
|
||||
int daemon_mode = 0;
|
||||
struct spdk_app_opts opts = {};
|
||||
enum spdk_log_level print_level = SPDK_LOG_NOTICE;
|
||||
|
||||
/* default value in opts structure */
|
||||
spdk_app_opts_init(&opts);
|
||||
@ -134,7 +135,7 @@ main(int argc, char **argv)
|
||||
opts.tpoint_group_mask = optarg;
|
||||
break;
|
||||
case 'q':
|
||||
spdk_g_notice_stderr_flag = 0;
|
||||
print_level = SPDK_LOG_WARN;
|
||||
break;
|
||||
case 'm':
|
||||
opts.reactor_mask = optarg;
|
||||
@ -165,7 +166,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (spdk_g_notice_stderr_flag == 1 &&
|
||||
if (print_level > SPDK_LOG_WARN &&
|
||||
isatty(STDERR_FILENO) &&
|
||||
!strncmp(ttyname(STDERR_FILENO), "/dev/tty", strlen("/dev/tty"))) {
|
||||
printf("Warning: printing stderr to console terminal without -q option specified.\n");
|
||||
@ -175,6 +176,8 @@ main(int argc, char **argv)
|
||||
sleep(10);
|
||||
}
|
||||
|
||||
spdk_log_set_print_level(print_level);
|
||||
|
||||
opts.shutdown_cb = spdk_iscsi_shutdown;
|
||||
opts.usr1_handler = spdk_sigusr1;
|
||||
|
||||
|
@ -74,6 +74,7 @@ main(int argc, char **argv)
|
||||
int ch;
|
||||
int rc;
|
||||
struct spdk_app_opts opts = {};
|
||||
enum spdk_log_level print_level = SPDK_LOG_NOTICE;
|
||||
|
||||
/* default value in opts */
|
||||
spdk_app_opts_init(&opts);
|
||||
@ -125,7 +126,7 @@ main(int argc, char **argv)
|
||||
opts.tpoint_group_mask = optarg;
|
||||
break;
|
||||
case 'q':
|
||||
spdk_g_notice_stderr_flag = 0;
|
||||
print_level = SPDK_LOG_WARN;
|
||||
break;
|
||||
case 'D':
|
||||
case 'H':
|
||||
@ -135,7 +136,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (spdk_g_notice_stderr_flag == 1 &&
|
||||
if (print_level > SPDK_LOG_WARN &&
|
||||
isatty(STDERR_FILENO) &&
|
||||
!strncmp(ttyname(STDERR_FILENO), "/dev/tty", strlen("/dev/tty"))) {
|
||||
printf("Warning: printing stderr to console terminal without -q option specified.\n");
|
||||
@ -145,6 +146,8 @@ main(int argc, char **argv)
|
||||
sleep(10);
|
||||
}
|
||||
|
||||
spdk_log_set_print_level(print_level);
|
||||
|
||||
rc = spdk_nvmf_tgt_start(&opts);
|
||||
|
||||
return rc;
|
||||
|
@ -83,6 +83,7 @@ main(int argc, char *argv[])
|
||||
char ch;
|
||||
int rc;
|
||||
const char *socket_path = NULL;
|
||||
enum spdk_log_level print_level = SPDK_LOG_NOTICE;
|
||||
|
||||
vhost_app_opts_init(&opts);
|
||||
|
||||
@ -110,7 +111,7 @@ main(int argc, char *argv[])
|
||||
opts.master_core = strtoul(optarg, NULL, 10);
|
||||
break;
|
||||
case 'q':
|
||||
spdk_g_notice_stderr_flag = 0;
|
||||
print_level = SPDK_LOG_WARN;
|
||||
break;
|
||||
case 's':
|
||||
opts.mem_size = strtoul(optarg, NULL, 10);
|
||||
@ -139,7 +140,7 @@ main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
if (spdk_g_notice_stderr_flag == 1 &&
|
||||
if (print_level > SPDK_LOG_WARN &&
|
||||
isatty(STDERR_FILENO) &&
|
||||
!strncmp(ttyname(STDERR_FILENO), "/dev/tty", strlen("/dev/tty"))) {
|
||||
printf("Warning: printing stderr to console terminal without -q option specified.\n");
|
||||
@ -149,6 +150,8 @@ main(int argc, char *argv[])
|
||||
sleep(10);
|
||||
}
|
||||
|
||||
spdk_log_set_print_level(print_level);
|
||||
|
||||
opts.shutdown_cb = spdk_vhost_shutdown_cb;
|
||||
|
||||
/* Blocks until the application is exiting */
|
||||
|
@ -72,11 +72,17 @@ void spdk_log_set_level(enum spdk_log_level level);
|
||||
*/
|
||||
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.
|
||||
/**
|
||||
* Set the current log level threshold for printing to stderr.
|
||||
* Messages with a level less than or equal to this level
|
||||
* are also printed to stderr.
|
||||
*/
|
||||
extern unsigned int spdk_g_notice_stderr_flag;
|
||||
void spdk_log_set_print_level(enum spdk_log_level level);
|
||||
|
||||
/**
|
||||
* Get the current log level print threshold.
|
||||
*/
|
||||
enum spdk_log_level spdk_log_get_print_level(void);
|
||||
|
||||
#define SPDK_NOTICELOG(...) \
|
||||
spdk_log(SPDK_LOG_NOTICE, __FILE__, __LINE__, __func__, __VA_ARGS__)
|
||||
|
@ -37,9 +37,9 @@
|
||||
|
||||
static TAILQ_HEAD(, spdk_trace_flag) g_trace_flags = TAILQ_HEAD_INITIALIZER(g_trace_flags);
|
||||
|
||||
unsigned int spdk_g_notice_stderr_flag = 1;
|
||||
int spdk_g_log_facility = LOG_DAEMON;
|
||||
static enum spdk_log_level g_spdk_log_level = SPDK_LOG_NOTICE;
|
||||
static enum spdk_log_level g_spdk_log_print_level = SPDK_LOG_NOTICE;
|
||||
|
||||
SPDK_LOG_REGISTER_TRACE_FLAG("debug", SPDK_TRACE_DEBUG)
|
||||
|
||||
@ -114,6 +114,17 @@ spdk_log_get_level(void) {
|
||||
return g_spdk_log_level;
|
||||
}
|
||||
|
||||
void
|
||||
spdk_log_set_print_level(enum spdk_log_level level)
|
||||
{
|
||||
g_spdk_log_print_level = level;
|
||||
}
|
||||
|
||||
enum spdk_log_level
|
||||
spdk_log_get_print_level(void) {
|
||||
return g_spdk_log_print_level;
|
||||
}
|
||||
|
||||
int
|
||||
spdk_set_log_facility(const char *facility)
|
||||
{
|
||||
@ -175,11 +186,12 @@ spdk_log(enum spdk_log_level level, const char *file, const int line, const char
|
||||
|
||||
vsnprintf(buf, sizeof(buf), format, ap);
|
||||
|
||||
if (level <= g_spdk_log_level) {
|
||||
if (level <= g_spdk_log_print_level) {
|
||||
fprintf(stderr, "%s:%4d:%s: *%s*: %s", file, line, func, spdk_level_names[level], buf);
|
||||
if (level <= SPDK_LOG_NOTICE) {
|
||||
syslog(severity, "%s:%4d:%s: *%s*: %s", file, line, func, spdk_level_names[level], buf);
|
||||
}
|
||||
}
|
||||
|
||||
if (level <= g_spdk_log_level) {
|
||||
syslog(severity, "%s:%4d:%s: *%s*: %s", file, line, func, spdk_level_names[level], buf);
|
||||
}
|
||||
|
||||
va_end(ap);
|
||||
|
Loading…
Reference in New Issue
Block a user