Skip to content

Commit 79e0889

Browse files
authored
Allow use of log_x() in if (espressif#5844)
if (1) log_e("error") produces a warning ("missing braces") and probably wrong code if no log level is defined. This fixes that.
1 parent 4aff6dd commit 79e0889

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

Diff for: cores/esp32/esp32-hal-log.h

+18-18
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ void log_print_buf(const uint8_t *b, size_t len);
9999
#define log_buf_v(b,l) do {ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_VERBOSE);}while(0)
100100
#endif
101101
#else
102-
#define log_v(format, ...)
103-
#define isr_log_v(format, ...)
104-
#define log_buf_v(b,l)
102+
#define log_v(format, ...) do {} while(0)
103+
#define isr_log_v(format, ...) do {} while(0)
104+
#define log_buf_v(b,l) do {} while(0)
105105
#endif
106106

107107
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_DEBUG
@@ -115,9 +115,9 @@ void log_print_buf(const uint8_t *b, size_t len);
115115
#define log_buf_d(b,l) do {ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_DEBUG);}while(0)
116116
#endif
117117
#else
118-
#define log_d(format, ...)
119-
#define isr_log_d(format, ...)
120-
#define log_buf_d(b,l)
118+
#define log_d(format, ...) do {} while(0)
119+
#define isr_log_d(format, ...) do {} while(0)
120+
#define log_buf_d(b,l) do {} while(0)
121121
#endif
122122

123123
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
@@ -131,9 +131,9 @@ void log_print_buf(const uint8_t *b, size_t len);
131131
#define log_buf_i(b,l) do {ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_INFO);}while(0)
132132
#endif
133133
#else
134-
#define log_i(format, ...)
135-
#define isr_log_i(format, ...)
136-
#define log_buf_i(b,l)
134+
#define log_i(format, ...) do {} while(0)
135+
#define isr_log_i(format, ...) do {} while(0)
136+
#define log_buf_i(b,l) do {} while(0)
137137
#endif
138138

139139
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_WARN
@@ -147,9 +147,9 @@ void log_print_buf(const uint8_t *b, size_t len);
147147
#define log_buf_w(b,l) do {ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_WARN);}while(0)
148148
#endif
149149
#else
150-
#define log_w(format, ...)
151-
#define isr_log_w(format, ...)
152-
#define log_buf_w(b,l)
150+
#define log_w(format, ...) do {} while(0)
151+
#define isr_log_w(format, ...) do {} while(0)
152+
#define log_buf_w(b,l) do {} while(0)
153153
#endif
154154

155155
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_ERROR
@@ -163,9 +163,9 @@ void log_print_buf(const uint8_t *b, size_t len);
163163
#define log_buf_e(b,l) do {ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_ERROR);}while(0)
164164
#endif
165165
#else
166-
#define log_e(format, ...)
167-
#define isr_log_e(format, ...)
168-
#define log_buf_e(b,l)
166+
#define log_e(format, ...) do {} while(0)
167+
#define isr_log_e(format, ...) do {} while(0)
168+
#define log_buf_e(b,l) do {} while(0)
169169
#endif
170170

171171
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_NONE
@@ -179,9 +179,9 @@ void log_print_buf(const uint8_t *b, size_t len);
179179
#define log_buf_n(b,l) do {ESP_LOG_BUFFER_HEXDUMP(TAG, b, l, ESP_LOG_ERROR);}while(0)
180180
#endif
181181
#else
182-
#define log_n(format, ...)
183-
#define isr_log_n(format, ...)
184-
#define log_buf_n(b,l)
182+
#define log_n(format, ...) do {} while(0)
183+
#define isr_log_n(format, ...) do {} while(0)
184+
#define log_buf_n(b,l) do {} while(0)
185185
#endif
186186

187187
#include "esp_log.h"

0 commit comments

Comments
 (0)