Skip to content

Commit 920ae83

Browse files
NateThorntonigaw
authored andcommitted
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 <[email protected]>
1 parent 074b199 commit 920ae83

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

logging.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ struct submit_data {
2727
int log_level;
2828
static struct submit_data sb;
2929

30+
bool is_printable_at_level(int level)
31+
{
32+
return ((log_level >= level) &&
33+
(strcmp(nvme_cfg.output_format, "normal") == 0));
34+
}
35+
3036
int map_log_level(int verbose, bool quiet)
3137
{
3238
int log_level;

logging.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55

66
#include <stdbool.h>
77

8-
#define print_info(...) \
9-
do { \
10-
if (log_level >= LOG_INFO) \
11-
printf(__VA_ARGS__); \
8+
#define print_info(...) \
9+
do { \
10+
if (is_printable_at_level(LOG_INFO)) \
11+
printf(__VA_ARGS__); \
1212
} while (false)
1313

14-
#define print_debug(...) \
15-
do { \
16-
if (log_level >= LOG_DEBUG) \
17-
printf(__VA_ARGS__); \
14+
#define print_debug(...) \
15+
do { \
16+
if (is_printable_at_level(LOG_DEBUG)) \
17+
printf(__VA_ARGS__); \
1818
} while (false)
1919

2020
extern int log_level;
@@ -29,6 +29,7 @@ void nvme_submit_exit(struct nvme_transport_handle *hdl,
2929
bool nvme_decide_retry(struct nvme_transport_handle *hdl,
3030
struct nvme_passthru_cmd *cmd, int err);
3131

32+
bool is_printable_at_level(int level);
3233
int map_log_level(int verbose, bool quiet);
3334

3435
#endif // DEBUG_H_

0 commit comments

Comments
 (0)