Add UART SET_LOG_LEVEL for runtime master ESP-IDF logging.
Expose the command via goTool CLI/REST and dashboard controls so log verbosity can be tuned without reflashing. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
#include "cmd_set_log_level.h"
|
||||
#include "esp_log.h"
|
||||
#include "uart_cmd.h"
|
||||
|
||||
static const char *TAG = "[LOG_LVL]";
|
||||
|
||||
static bool valid_level(uint32_t level) { return level <= ESP_LOG_VERBOSE; }
|
||||
|
||||
static void reply(uint32_t level, bool success) {
|
||||
alox_UartMessage response;
|
||||
uart_cmd_init_response(&response, alox_MessageType_SET_LOG_LEVEL,
|
||||
alox_UartMessage_set_log_level_response_tag);
|
||||
response.payload.set_log_level_response.success = success;
|
||||
response.payload.set_log_level_response.level = level;
|
||||
uart_cmd_send(&response, TAG);
|
||||
}
|
||||
|
||||
static void handle_set_log_level(const uint8_t *data, size_t len) {
|
||||
alox_UartMessage uart_msg;
|
||||
alox_SetLogLevelRequest req = alox_SetLogLevelRequest_init_zero;
|
||||
|
||||
if (uart_cmd_decode(data, len, &uart_msg) != ESP_OK) {
|
||||
ESP_LOGW(TAG, "decode failed");
|
||||
reply((uint32_t)esp_log_level_get("*"), false);
|
||||
return;
|
||||
}
|
||||
|
||||
const alox_SetLogLevelRequest *req_ptr = UART_CMD_REQ(
|
||||
&uart_msg, alox_UartMessage_set_log_level_request_tag, set_log_level_request);
|
||||
if (req_ptr != NULL) {
|
||||
req = *req_ptr;
|
||||
}
|
||||
|
||||
if (req.write) {
|
||||
if (!valid_level(req.level)) {
|
||||
ESP_LOGW(TAG, "invalid level %lu", (unsigned long)req.level);
|
||||
reply((uint32_t)esp_log_level_get("*"), false);
|
||||
return;
|
||||
}
|
||||
esp_log_level_set("*", (esp_log_level_t)req.level);
|
||||
ESP_LOGI(TAG, "global log level set to %lu", (unsigned long)req.level);
|
||||
reply(req.level, true);
|
||||
return;
|
||||
}
|
||||
|
||||
reply((uint32_t)esp_log_level_get("*"), true);
|
||||
}
|
||||
|
||||
void cmd_set_log_level_register(void) {
|
||||
uart_cmd_register(alox_MessageType_SET_LOG_LEVEL, handle_set_log_level);
|
||||
}
|
||||
Reference in New Issue
Block a user