Skip to content

Commit ce82455

Browse files
committed
Mbed: Check debug_enable flag runtime before print
1 parent 00db276 commit ce82455

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

boot/mbed/include/mcuboot_config/mcuboot_logging.h

+13-4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@
5858
#include "mbed_trace.h"
5959
#include "bootutil/ignore.h"
6060

61+
#define PRINT_IF(condition,format,args...) \
62+
if(condition) { \
63+
printf(format, ##args); \
64+
}
65+
6166
#define MCUBOOT_LOG_MODULE_DECLARE(domain) /* ignore */
6267
#define MCUBOOT_LOG_MODULE_REGISTER(domain) /* ignore */
6368

@@ -67,7 +72,8 @@
6772
#else
6873
#define MCUBOOT_LOG_ERR(_fmt, ...) \
6974
do { \
70-
printf("E-" _fmt "\n", ##__VA_ARGS__); \
75+
extern bool debug_enabled; \
76+
PRINT_IF(debug_enabled, "E-" _fmt "\n", ##__VA_ARGS__); \
7177
} while (0)
7278
#endif
7379
#else
@@ -80,7 +86,8 @@
8086
#else
8187
#define MCUBOOT_LOG_WRN(_fmt, ...) \
8288
do { \
83-
printf("W-" _fmt "\n", ##__VA_ARGS__); \
89+
extern bool debug_enabled; \
90+
PRINT_IF(debug_enabled,"W-" _fmt "\n", ##__VA_ARGS__); \
8491
} while (0)
8592
#endif
8693
#else
@@ -93,7 +100,8 @@
93100
#else
94101
#define MCUBOOT_LOG_INF(_fmt, ...) \
95102
do { \
96-
printf("I-" _fmt "\n", ##__VA_ARGS__); \
103+
extern bool debug_enabled; \
104+
PRINT_IF(debug_enabled, "I-" _fmt "\n", ##__VA_ARGS__); \
97105
} while (0)
98106
#endif
99107
#else
@@ -106,7 +114,8 @@
106114
#else
107115
#define MCUBOOT_LOG_DBG(_fmt, ...) \
108116
do { \
109-
printf("D-" _fmt "\n", ##__VA_ARGS__); \
117+
extern bool debug_enabled; \
118+
PRINT_IF(debug_enabled, "D-" _fmt "\n", ##__VA_ARGS__); \
110119
} while (0)
111120
#endif
112121
#else

0 commit comments

Comments
 (0)