From 2aae8c4bc436c89f1a1bbbf1722020f9e60fb1c6 Mon Sep 17 00:00:00 2001 From: Nate Thornton Date: Mon, 22 Dec 2025 10:48:48 -0800 Subject: [PATCH] logging: suppress logging except during normal output Suppress the logging macros `print_info` and `print_debug` except during normal output. This ensures that `json` and `binary` output formats do not include unnecessary warnings. This was originally causing issue with create-ns command printing warnings about namespace granularity alignment when using JSON option. See issue #2993. Signed-off-by: Nate Thornton --- logging.c | 6 ++++++ logging.h | 17 +++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/logging.c b/logging.c index b57d257f35..dcb8e7638b 100644 --- a/logging.c +++ b/logging.c @@ -27,6 +27,12 @@ struct submit_data { int log_level; static struct submit_data sb; +bool is_printable_at_level(int level) +{ + return ((log_level >= level) && + (strcmp(nvme_cfg.output_format, "normal") == 0)); +} + int map_log_level(int verbose, bool quiet) { int log_level; diff --git a/logging.h b/logging.h index 57ab5906e1..2f4633c83b 100644 --- a/logging.h +++ b/logging.h @@ -5,16 +5,16 @@ #include -#define print_info(...) \ - do { \ - if (log_level >= LOG_INFO) \ - printf(__VA_ARGS__); \ +#define print_info(...) \ + do { \ + if (is_printable_at_level(LOG_INFO)) \ + printf(__VA_ARGS__); \ } while (false) -#define print_debug(...) \ - do { \ - if (log_level >= LOG_DEBUG) \ - printf(__VA_ARGS__); \ +#define print_debug(...) \ + do { \ + if (is_printable_at_level(LOG_DEBUG)) \ + printf(__VA_ARGS__); \ } while (false) extern int log_level; @@ -29,6 +29,7 @@ void nvme_submit_exit(struct nvme_transport_handle *hdl, bool nvme_decide_retry(struct nvme_transport_handle *hdl, struct nvme_passthru_cmd *cmd, int err); +bool is_printable_at_level(int level); int map_log_level(int verbose, bool quiet); #endif // DEBUG_H_