diff --git a/include/spdk/log.h b/include/spdk/log.h index d281c71b84..6c5ac8e39a 100644 --- a/include/spdk/log.h +++ b/include/spdk/log.h @@ -138,6 +138,8 @@ enum spdk_log_level spdk_log_get_print_level(void); spdk_log(SPDK_LOG_WARN, __FILE__, __LINE__, __func__, __VA_ARGS__) #define SPDK_ERRLOG(...) \ spdk_log(SPDK_LOG_ERROR, __FILE__, __LINE__, __func__, __VA_ARGS__) +#define SPDK_PRINTF(...) \ + spdk_log(SPDK_LOG_NOTICE, NULL, -1, NULL, __VA_ARGS__) /** * Write messages to the log file. If \c level is set to \c SPDK_LOG_DISABLED, diff --git a/lib/log/log.c b/lib/log/log.c index 79b7b89609..93a037b952 100644 --- a/lib/log/log.c +++ b/lib/log/log.c @@ -150,12 +150,20 @@ 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_print_level) { - fprintf(stderr, "%s:%4d:%s: *%s*: %s", file, line, func, spdk_level_names[level], buf); - spdk_log_unwind_stack(stderr, level); + if (file) { + fprintf(stderr, "%s:%4d:%s: *%s*: %s", file, line, func, spdk_level_names[level], buf); + spdk_log_unwind_stack(stderr, level); + } else { + fprintf(stderr, "%s", buf); + } } if (level <= g_spdk_log_level) { - syslog(severity, "%s:%4d:%s: *%s*: %s", file, line, func, spdk_level_names[level], buf); + if (file) { + syslog(severity, "%s:%4d:%s: *%s*: %s", file, line, func, spdk_level_names[level], buf); + } else { + syslog(severity, "%s", buf); + } } va_end(ap);