Merge branch 'bugfix/log_macro_statements' into 'master'

log: Make ESP_LOGx macros into single statements

See merge request idf/esp-idf!2275
This commit is contained in:
Angus Gratton 2018-04-26 08:05:49 +08:00
commit d9cbfe42f9
5 changed files with 63 additions and 56 deletions

View file

@ -191,7 +191,7 @@ esp_err_t esp_ota_write(esp_ota_handle_t handle, const void *data, size_t size)
}
//if go to here ,means don't find the handle
ESP_LOGE(TAG,"not found the handle")
ESP_LOGE(TAG,"not found the handle");
return ESP_ERR_INVALID_ARG;
}

View file

@ -140,7 +140,7 @@ static void select_rtc_slow_clk(rtc_slow_freq_t slow_clk)
uint32_t wait = 0;
// increment of 'wait' counter equivalent to 3 seconds
const uint32_t warning_timeout = 3 /* sec */ * 32768 /* Hz */ / (2 * XTAL_32K_DETECT_CYCLES);
ESP_EARLY_LOGD(TAG, "waiting for 32k oscillator to start up")
ESP_EARLY_LOGD(TAG, "waiting for 32k oscillator to start up");
do {
++wait;
rtc_clk_32k_enable(true);

View file

@ -244,26 +244,31 @@ void esp_log_write(esp_log_level_t level, const char* tag, const char* format, .
#define LOG_FORMAT(letter, format) LOG_COLOR_ ## letter #letter " (%d) %s: " format LOG_RESET_COLOR "\n"
/// macro to output logs in startup code, before heap allocator and syscalls have been initialized. log at ``ESP_LOG_ERROR`` level. @see ``printf``,``ESP_LOGE``
#define ESP_EARLY_LOGE( tag, format, ... ) if (LOG_LOCAL_LEVEL >= ESP_LOG_ERROR) { ets_printf(LOG_FORMAT(E, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }
#define ESP_EARLY_LOGE( tag, format, ... ) ESP_LOG_EARLY_IMPL(tag, format, ESP_LOG_ERROR, E, ##__VA_ARGS__)
/// macro to output logs in startup code at ``ESP_LOG_WARN`` level. @see ``ESP_EARLY_LOGE``,``ESP_LOGE``, ``printf``
#define ESP_EARLY_LOGW( tag, format, ... ) if (LOG_LOCAL_LEVEL >= ESP_LOG_WARN) { ets_printf(LOG_FORMAT(W, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }
#define ESP_EARLY_LOGW( tag, format, ... ) ESP_LOG_EARLY_IMPL(tag, format, ESP_LOG_WARN, W, ##__VA_ARGS__)
/// macro to output logs in startup code at ``ESP_LOG_INFO`` level. @see ``ESP_EARLY_LOGE``,``ESP_LOGE``, ``printf``
#define ESP_EARLY_LOGI( tag, format, ... ) if (LOG_LOCAL_LEVEL >= ESP_LOG_INFO) { ets_printf(LOG_FORMAT(I, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }
#define ESP_EARLY_LOGI( tag, format, ... ) ESP_LOG_EARLY_IMPL(tag, format, ESP_LOG_INFO, I, ##__VA_ARGS__)
/// macro to output logs in startup code at ``ESP_LOG_DEBUG`` level. @see ``ESP_EARLY_LOGE``,``ESP_LOGE``, ``printf``
#define ESP_EARLY_LOGD( tag, format, ... ) if (LOG_LOCAL_LEVEL >= ESP_LOG_DEBUG) { ets_printf(LOG_FORMAT(D, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }
#define ESP_EARLY_LOGD( tag, format, ... ) ESP_LOG_EARLY_IMPL(tag, format, ESP_LOG_DEBUG, D, ##__VA_ARGS__)
/// macro to output logs in startup code at ``ESP_LOG_VERBOSE`` level. @see ``ESP_EARLY_LOGE``,``ESP_LOGE``, ``printf``
#define ESP_EARLY_LOGV( tag, format, ... ) if (LOG_LOCAL_LEVEL >= ESP_LOG_VERBOSE) { ets_printf(LOG_FORMAT(V, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }
#define ESP_EARLY_LOGV( tag, format, ... ) ESP_LOG_EARLY_IMPL(tag, format, ESP_LOG_VERBOSE, V, ##__VA_ARGS__)
#define ESP_LOG_EARLY_IMPL(tag, format, log_level, log_tag_letter, ...) do { \
if (LOG_LOCAL_LEVEL >= log_level) { \
ets_printf(LOG_FORMAT(log_tag_letter, format), esp_log_timestamp(), tag, ##__VA_ARGS__); \
}} while(0)
#ifndef BOOTLOADER_BUILD
#define ESP_LOGE( tag, format, ... ) if (LOG_LOCAL_LEVEL >= ESP_LOG_ERROR) { esp_log_write(ESP_LOG_ERROR, tag, LOG_FORMAT(E, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }
#define ESP_LOGW( tag, format, ... ) if (LOG_LOCAL_LEVEL >= ESP_LOG_WARN) { esp_log_write(ESP_LOG_WARN, tag, LOG_FORMAT(W, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }
#define ESP_LOGI( tag, format, ... ) if (LOG_LOCAL_LEVEL >= ESP_LOG_INFO) { esp_log_write(ESP_LOG_INFO, tag, LOG_FORMAT(I, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }
#define ESP_LOGD( tag, format, ... ) if (LOG_LOCAL_LEVEL >= ESP_LOG_DEBUG) { esp_log_write(ESP_LOG_DEBUG, tag, LOG_FORMAT(D, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }
#define ESP_LOGV( tag, format, ... ) if (LOG_LOCAL_LEVEL >= ESP_LOG_VERBOSE) { esp_log_write(ESP_LOG_VERBOSE, tag, LOG_FORMAT(V, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }
#define ESP_LOGE( tag, format, ... ) ESP_LOG_LEVEL_LOCAL(ESP_LOG_ERROR, tag, format, ##__VA_ARGS__)
#define ESP_LOGW( tag, format, ... ) ESP_LOG_LEVEL_LOCAL(ESP_LOG_WARN, tag, format, ##__VA_ARGS__)
#define ESP_LOGI( tag, format, ... ) ESP_LOG_LEVEL_LOCAL(ESP_LOG_INFO, tag, format, ##__VA_ARGS__)
#define ESP_LOGD( tag, format, ... ) ESP_LOG_LEVEL_LOCAL(ESP_LOG_DEBUG, tag, format, ##__VA_ARGS__)
#define ESP_LOGV( tag, format, ... ) ESP_LOG_LEVEL_LOCAL(ESP_LOG_VERBOSE, tag, format, ##__VA_ARGS__)
#else
/**
* macro to output logs at ESP_LOG_ERROR level.
*
*
* @param tag tag of the log, which can be used to change the log level by ``esp_log_level_set`` at runtime.
*
* @see ``printf``
@ -291,19 +296,21 @@ void esp_log_write(esp_log_level_t level, const char* tag, const char* format, .
*
* @see ``printf``
*/
#define ESP_LOG_LEVEL(level, tag, format, ...) do {\
if (level==ESP_LOG_ERROR ) { esp_log_write(ESP_LOG_ERROR, tag, LOG_FORMAT(E, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }\
else if (level==ESP_LOG_WARN ) { esp_log_write(ESP_LOG_WARN, tag, LOG_FORMAT(W, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }\
else if (level==ESP_LOG_DEBUG ) { esp_log_write(ESP_LOG_DEBUG, tag, LOG_FORMAT(D, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }\
else if (level==ESP_LOG_VERBOSE ) { esp_log_write(ESP_LOG_VERBOSE, tag, LOG_FORMAT(V, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }\
else { esp_log_write(ESP_LOG_INFO, tag, LOG_FORMAT(I, format), esp_log_timestamp(), tag, ##__VA_ARGS__); }}while(0)
#define ESP_LOG_LEVEL(level, tag, format, ...) do { \
if (level==ESP_LOG_ERROR ) { esp_log_write(ESP_LOG_ERROR, tag, LOG_FORMAT(E, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } \
else if (level==ESP_LOG_WARN ) { esp_log_write(ESP_LOG_WARN, tag, LOG_FORMAT(W, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } \
else if (level==ESP_LOG_DEBUG ) { esp_log_write(ESP_LOG_DEBUG, tag, LOG_FORMAT(D, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } \
else if (level==ESP_LOG_VERBOSE ) { esp_log_write(ESP_LOG_VERBOSE, tag, LOG_FORMAT(V, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } \
else { esp_log_write(ESP_LOG_INFO, tag, LOG_FORMAT(I, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } \
} while(0)
/** runtime macro to output logs at a specified level. Also check the level with ``LOG_LOCAL_LEVEL``.
*
*
* @see ``printf``, ``ESP_LOG_LEVEL``
*/
#define ESP_LOG_LEVEL_LOCAL(level, tag, format, ...) do {\
if ( LOG_LOCAL_LEVEL >= level ) ESP_LOG_LEVEL(level, tag, format, ##__VA_ARGS__); } while(0);
#define ESP_LOG_LEVEL_LOCAL(level, tag, format, ...) do { \
if ( LOG_LOCAL_LEVEL >= level ) ESP_LOG_LEVEL(level, tag, format, ##__VA_ARGS__); \
} while(0)
#ifdef __cplusplus
}

View file

@ -72,13 +72,13 @@ void mesh_send_to_group(const mesh_data_t *data, const mesh_addr_t *group, int s
"[GROUP:%d][L:%d][rtableSize:%d]parent:"MACSTR" to "MACSTR", heap:%d[err:0x%x, proto:%d, tos:%d]",
seqno, mesh_layer, esp_mesh_get_routing_table_size(),
MAC2STR(mesh_parent_addr.addr), MAC2STR(group->addr),
esp_get_free_heap_size(), err, data->proto, data->tos)
esp_get_free_heap_size(), err, data->proto, data->tos);
} else {
ESP_LOGW(MESH_TAG,
"[GROUP:%d][L:%d][rtableSize:%d]parent:"MACSTR" to "MACSTR", heap:%d[err:0x%x, proto:%d, tos:%d]",
seqno, mesh_layer, esp_mesh_get_routing_table_size(),
MAC2STR(mesh_parent_addr.addr), MAC2STR(group->addr),
esp_get_free_heap_size(), err, data->proto, data->tos)
esp_get_free_heap_size(), err, data->proto, data->tos);
}
}
@ -104,7 +104,7 @@ void esp_mesh_p2p_tx_main(void *arg)
ESP_LOGI(MESH_TAG, "layer:%d, rtableSize:%d, %s%s", mesh_layer,
esp_mesh_get_routing_table_size(),
is_mesh_connected ? "CONNECT" : "DISCONNECT",
esp_mesh_is_root() ? "<ROOT>" : "[NODE]")
esp_mesh_is_root() ? "<ROOT>" : "[NODE]");
vTaskDelay(10 * 1000 / portTICK_RATE_MS);
continue;
}
@ -113,7 +113,7 @@ void esp_mesh_p2p_tx_main(void *arg)
CONFIG_MESH_ROUTE_TABLE_SIZE * 6, &route_table_size);
if (send_count && !(send_count % 100)) {
ESP_LOGI(MESH_TAG, "size:%d/%d,send_count:%d", route_table_size,
esp_mesh_get_routing_table_size(), send_count)
esp_mesh_get_routing_table_size(), send_count);
}
send_count++;
tx_buf[25] = (send_count >> 24) & 0xff;
@ -138,7 +138,7 @@ void esp_mesh_p2p_tx_main(void *arg)
"[ROOT-2-UNICAST:%d][L:%d]parent:"MACSTR" to "MACSTR", heap:%d[err:0x%x, proto:%d, tos:%d]",
send_count, mesh_layer, MAC2STR(mesh_parent_addr.addr),
MAC2STR(route_table[i].addr), esp_get_free_heap_size(),
err, data.proto, data.tos)
err, data.proto, data.tos);
} else if (!(send_count % 100)) {
ESP_LOGW(MESH_TAG,
"[ROOT-2-UNICAST:%d][L:%d][rtableSize:%d]parent:"MACSTR" to "MACSTR", heap:%d[err:0x%x, proto:%d, tos:%d]",
@ -146,7 +146,7 @@ void esp_mesh_p2p_tx_main(void *arg)
esp_mesh_get_routing_table_size(),
MAC2STR(mesh_parent_addr.addr),
MAC2STR(route_table[i].addr), esp_get_free_heap_size(),
err, data.proto, data.tos)
err, data.proto, data.tos);
}
}
if (route_table_size < 10) {
@ -172,7 +172,7 @@ void esp_mesh_p2p_rx_main(void *arg)
data.size = RX_SIZE;
err = esp_mesh_recv(&from, &data, portMAX_DELAY, &flag, NULL, 0);
if (err != ESP_OK || !data.size) {
ESP_LOGE(MESH_TAG, "err:0x%x, size:%d", err, data.size)
ESP_LOGE(MESH_TAG, "err:0x%x, size:%d", err, data.size);
continue;
}
/* extract send count */
@ -189,7 +189,7 @@ void esp_mesh_p2p_rx_main(void *arg)
recv_count, send_count, mesh_layer,
MAC2STR(mesh_parent_addr.addr), MAC2STR(from.addr),
data.size, esp_get_free_heap_size(), flag, err, data.proto,
data.tos)
data.tos);
}
}
vTaskDelete(NULL);
@ -213,40 +213,40 @@ void esp_mesh_event_handler(mesh_event_t event)
#endif
static uint8_t last_layer = 0;
static int disconnect_count = 0;
ESP_LOGD(MESH_TAG, "esp_event_handler:%d", event.id)
ESP_LOGD(MESH_TAG, "esp_event_handler:%d", event.id);
switch (event.id) {
case MESH_EVENT_STARTED:
ESP_LOGI(MESH_TAG, "<MESH_EVENT_STARTED>")
ESP_LOGI(MESH_TAG, "<MESH_EVENT_STARTED>");
break;
case MESH_EVENT_STOPPED:
ESP_LOGI(MESH_TAG, "<MESH_EVENT_STOPPED>")
ESP_LOGI(MESH_TAG, "<MESH_EVENT_STOPPED>");
break;
case MESH_EVENT_CHILD_CONNECTED:
ESP_LOGI(MESH_TAG, "<MESH_EVENT_CHILD_CONNECTED>aid:%d, "MACSTR"",
event.info.child_connected.aid,
MAC2STR(event.info.child_connected.mac))
MAC2STR(event.info.child_connected.mac));
break;
case MESH_EVENT_CHILD_DISCONNECTED:
ESP_LOGI(MESH_TAG, "<MESH_EVENT_CHILD_DISCONNECTED>aid:%d, "MACSTR"",
event.info.child_disconnected.aid,
MAC2STR(event.info.child_disconnected.mac))
MAC2STR(event.info.child_disconnected.mac));
break;
case MESH_EVENT_ROUTING_TABLE_ADD:
ESP_LOGW(MESH_TAG, "<MESH_EVENT_ROUTING_TABLE_ADD>add %d, new:%d",
event.info.routing_table.rt_size_change,
event.info.routing_table.rt_size_new)
event.info.routing_table.rt_size_new);
break;
case MESH_EVENT_ROUTING_TABLE_REMOVE:
ESP_LOGW(MESH_TAG, "<MESH_EVENT_ROUTING_TABLE_REMOVE>remove %d, new:%d",
event.info.routing_table.rt_size_change,
event.info.routing_table.rt_size_new)
event.info.routing_table.rt_size_new);
break;
case MESH_EVENT_NO_PARNET_FOUND:
ESP_LOGI(MESH_TAG, "<MESH_EVENT_NO_PARNET_FOUND>scan times:%d",
event.info.no_parent.scan_times)
event.info.no_parent.scan_times);
/* TODO handler for the failure */
break;
@ -257,7 +257,7 @@ void esp_mesh_event_handler(mesh_event_t event)
"<MESH_EVENT_PARENT_CONNECTED>layer:%d-->%d, parent:"MACSTR"%s, discnx:%d",
last_layer, mesh_layer, MAC2STR(mesh_parent_addr.addr),
esp_mesh_is_root() ? "<ROOT>" :
(mesh_layer == 2) ? "<layer2>" : "", disconnect_count)
(mesh_layer == 2) ? "<layer2>" : "", disconnect_count);
disconnect_count = 0;
last_layer = mesh_layer;
mesh_connected_indicator(mesh_layer);
@ -271,7 +271,7 @@ void esp_mesh_event_handler(mesh_event_t event)
esp_mesh_set_group_id((mesh_addr_t * ) MESH_GROUP_ID, 1))
ESP_ERROR_CHECK(esp_mesh_get_group_list(&group, 1))
ESP_LOGI(MESH_TAG, "num:%d, group "MACSTR"\n",
esp_mesh_get_group_num(), MAC2STR(group.addr))
esp_mesh_get_group_num(), MAC2STR(group.addr));
}
#endif
esp_mesh_comm_p2p_start();
@ -280,7 +280,7 @@ void esp_mesh_event_handler(mesh_event_t event)
case MESH_EVENT_PARENT_DISCONNECTED:
ESP_LOGI(MESH_TAG,
"<MESH_EVENT_PARENT_DISCONNECTED>reason:%d, count:%d",
event.info.disconnected.reason, disconnect_count)
event.info.disconnected.reason, disconnect_count);
if (event.info.disconnected.reason == 201) {
disconnect_count++;
}
@ -293,14 +293,14 @@ void esp_mesh_event_handler(mesh_event_t event)
ESP_LOGI(MESH_TAG, "<MESH_EVENT_LAYER_CHANGE>layer:%d-->%d%s",
last_layer, mesh_layer,
esp_mesh_is_root() ? "<ROOT>" :
(mesh_layer == 2) ? "<layer2>" : "")
(mesh_layer == 2) ? "<layer2>" : "");
last_layer = mesh_layer;
mesh_connected_indicator(mesh_layer);
break;
case MESH_EVENT_ROOT_ADDRESS:
ESP_LOGI(MESH_TAG, "<MESH_EVENT_ROOT_ADDRESS>rc_addr:"MACSTR"",
MAC2STR(event.info.root_addr.addr))
MAC2STR(event.info.root_addr.addr));
break;
case MESH_EVENT_ROOT_GOT_IP:
@ -309,11 +309,11 @@ void esp_mesh_event_handler(mesh_event_t event)
"<MESH_EVENT_ROOT_GOT_IP>sta ip: " IPSTR ", mask: " IPSTR ", gw: " IPSTR,
IP2STR(&event.info.got_ip.ip_info.ip),
IP2STR(&event.info.got_ip.ip_info.netmask),
IP2STR(&event.info.got_ip.ip_info.gw))
IP2STR(&event.info.got_ip.ip_info.gw));
break;
case MESH_EVENT_ROOT_LOST_IP:
ESP_LOGI(MESH_TAG, "<MESH_EVENT_ROOT_LOST_IP>")
ESP_LOGI(MESH_TAG, "<MESH_EVENT_ROOT_LOST_IP>");
break;
case MESH_EVENT_VOTE_STARTED:
@ -321,29 +321,29 @@ void esp_mesh_event_handler(mesh_event_t event)
"<MESH_EVENT_VOTE_STARTED>attempts:%d, reason:%d, rc_addr:"MACSTR"",
event.info.vote_started.attempts,
event.info.vote_started.reason,
MAC2STR(event.info.vote_started.rc_addr.addr))
MAC2STR(event.info.vote_started.rc_addr.addr));
break;
case MESH_EVENT_VOTE_STOPPED:
ESP_LOGI(MESH_TAG, "<MESH_EVENT_VOTE_DONE>")
ESP_LOGI(MESH_TAG, "<MESH_EVENT_VOTE_DONE>");
break;
case MESH_EVENT_ROOT_SWITCH_REQ:
ESP_LOGI(MESH_TAG,
"<MESH_EVENT_ROOT_SWITCH_REQ>reason:%d, rc_addr:"MACSTR"",
event.info.switch_req.reason,
MAC2STR( event.info.switch_req.rc_addr.addr))
MAC2STR( event.info.switch_req.rc_addr.addr));
break;
case MESH_EVENT_ROOT_SWITCH_ACK:
ESP_LOGI(MESH_TAG, "<MESH_EVENT_ROOT_SWITCH_ACK>")
ESP_LOGI(MESH_TAG, "<MESH_EVENT_ROOT_SWITCH_ACK>");
break;
case MESH_EVENT_TODS_STATE:
ESP_LOGI(MESH_TAG, "<MESH_EVENT_TODS_REACHABLE>state:%d",
event.info.toDS_state)
event.info.toDS_state);
;
break;
default:
ESP_LOGI(MESH_TAG, "unknown")
ESP_LOGI(MESH_TAG, "unknown");
break;
}
}
@ -403,5 +403,5 @@ void app_main(void)
ESP_ERROR_CHECK(esp_mesh_set_switch_parent_paras(&switch_paras));
/* mesh start */
ESP_ERROR_CHECK(esp_mesh_start());
ESP_LOGI(MESH_TAG, "mesh starts successfully, heap:%d\n", esp_get_free_heap_size())
ESP_LOGI(MESH_TAG, "mesh starts successfully, heap:%d\n", esp_get_free_heap_size());
}

View file

@ -163,13 +163,13 @@ reconnect:
ESP_LOGI(TAG, "SSL read: %s", recv_buf);
if (strstr(recv_buf, "GET ") &&
strstr(recv_buf, " HTTP/1.1")) {
ESP_LOGI(TAG, "SSL get matched message")
ESP_LOGI(TAG, "SSL write message")
ESP_LOGI(TAG, "SSL get matched message");
ESP_LOGI(TAG, "SSL write message");
ret = SSL_write(ssl, send_data, send_bytes);
if (ret > 0) {
ESP_LOGI(TAG, "OK")
ESP_LOGI(TAG, "OK");
} else {
ESP_LOGI(TAG, "error")
ESP_LOGI(TAG, "error");
}
break;
}