Bugfixes.
This commit is contained in:
parent
bf3b42204c
commit
20a8576106
1 changed files with 12 additions and 38 deletions
|
|
@ -44,11 +44,9 @@ typedef struct
|
||||||
} tag_entry_t;
|
} tag_entry_t;
|
||||||
|
|
||||||
static esp_log_level_t Saved_Global_Level = ESP_LOG_INFO;
|
static esp_log_level_t Saved_Global_Level = ESP_LOG_INFO;
|
||||||
static tag_entry_t Tag_Table[MAX_TAGS];
|
static tag_entry_t Tag_Table[MAX_TAGS] = {0};
|
||||||
static size_t Tag_Count = 0;
|
static size_t Tag_Count = 0;
|
||||||
|
|
||||||
/* ---------------- Utility ---------------- */
|
|
||||||
|
|
||||||
static bool parse_level(const char *s, esp_log_level_t *out)
|
static bool parse_level(const char *s, esp_log_level_t *out)
|
||||||
{
|
{
|
||||||
if (!strcmp(s, "none"))
|
if (!strcmp(s, "none"))
|
||||||
|
|
@ -89,19 +87,6 @@ static const char *level_str(esp_log_level_t lvl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void normalize_tag(char *dst, const char *src)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
for (i = 0; i < MAX_TAGLEN - 1 && src[i]; i++)
|
|
||||||
{
|
|
||||||
//dst[i] = toupper((unsigned char)src[i]);
|
|
||||||
dst[i] = src[i];
|
|
||||||
}
|
|
||||||
dst[i] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ---------------- NVS ---------------- */
|
|
||||||
|
|
||||||
static void nvs_save(void)
|
static void nvs_save(void)
|
||||||
{
|
{
|
||||||
nvs_handle_t h;
|
nvs_handle_t h;
|
||||||
|
|
@ -167,8 +152,6 @@ static void log_config_load(void)
|
||||||
nvs_close(h);
|
nvs_close(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------- Tag table ---------------- */
|
|
||||||
|
|
||||||
static void clear_tag_levels(void)
|
static void clear_tag_levels(void)
|
||||||
{
|
{
|
||||||
esp_log_level_t def = esp_log_get_default_level();
|
esp_log_level_t def = esp_log_get_default_level();
|
||||||
|
|
@ -183,7 +166,7 @@ static bool set_tag_level(const char *tag, esp_log_level_t level)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < Tag_Count; i++)
|
for (size_t i = 0; i < Tag_Count; i++)
|
||||||
{
|
{
|
||||||
if (!strcmp(Tag_Table[i].tag, tag))
|
if (Tag_Table[i].tag[0] != '\0' && !strcmp(Tag_Table[i].tag, tag))
|
||||||
{
|
{
|
||||||
Tag_Table[i].level = level;
|
Tag_Table[i].level = level;
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -200,14 +183,11 @@ static bool set_tag_level(const char *tag, esp_log_level_t level)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------- Command helpers ---------------- */
|
|
||||||
|
|
||||||
static void print_usage(void)
|
static void print_usage(void)
|
||||||
{
|
{
|
||||||
printf(
|
printf(
|
||||||
"Usage:\n"
|
"Usage:\n"
|
||||||
" log show\n"
|
" log show\n"
|
||||||
" log clear\n"
|
|
||||||
" log reset\n"
|
" log reset\n"
|
||||||
" log off | on\n"
|
" log off | on\n"
|
||||||
" log <level>\n"
|
" log <level>\n"
|
||||||
|
|
@ -237,14 +217,6 @@ static int log_cmd_show(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int log_cmd_clear(void)
|
|
||||||
{
|
|
||||||
clear_tag_levels();
|
|
||||||
nvs_clear_tags();
|
|
||||||
printf("All tag overrides cleared\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int log_cmd_reset(void)
|
static int log_cmd_reset(void)
|
||||||
{
|
{
|
||||||
esp_log_level_set("*", ESP_LOG_INFO);
|
esp_log_level_set("*", ESP_LOG_INFO);
|
||||||
|
|
@ -275,8 +247,16 @@ static int log_cmd_on(void)
|
||||||
|
|
||||||
static int log_cmd_tag(int argc, char **argv)
|
static int log_cmd_tag(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
if (argc < 3)
|
||||||
|
{
|
||||||
|
printf("Usage: log tag <tag> [level|off]\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure tag is null-terminated and within bounds
|
||||||
char tag[MAX_TAGLEN];
|
char tag[MAX_TAGLEN];
|
||||||
normalize_tag(tag, argv[2]);
|
strncpy(tag, argv[2], MAX_TAGLEN - 1);
|
||||||
|
tag[MAX_TAGLEN - 1] = '\0';
|
||||||
|
|
||||||
if (argc == 3)
|
if (argc == 3)
|
||||||
{
|
{
|
||||||
|
|
@ -325,8 +305,6 @@ static int log_cmd_set_global(const char *lvl)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------- Dispatcher ---------------- */
|
|
||||||
|
|
||||||
static int cmd_log(int argc, char **argv)
|
static int cmd_log(int argc, char **argv)
|
||||||
{
|
{
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
|
|
@ -337,8 +315,6 @@ static int cmd_log(int argc, char **argv)
|
||||||
|
|
||||||
if (!strcmp(argv[1], "show"))
|
if (!strcmp(argv[1], "show"))
|
||||||
return log_cmd_show();
|
return log_cmd_show();
|
||||||
if (!strcmp(argv[1], "clear"))
|
|
||||||
return log_cmd_clear();
|
|
||||||
if (!strcmp(argv[1], "reset"))
|
if (!strcmp(argv[1], "reset"))
|
||||||
return log_cmd_reset();
|
return log_cmd_reset();
|
||||||
if (!strcmp(argv[1], "off"))
|
if (!strcmp(argv[1], "off"))
|
||||||
|
|
@ -351,8 +327,6 @@ static int cmd_log(int argc, char **argv)
|
||||||
return log_cmd_set_global(argv[1]);
|
return log_cmd_set_global(argv[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------- Registration ---------------- */
|
|
||||||
|
|
||||||
static void log_completion(const char *buf, linenoiseCompletions *lc)
|
static void log_completion(const char *buf, linenoiseCompletions *lc)
|
||||||
{
|
{
|
||||||
if (!strncmp(buf, "log", 3))
|
if (!strncmp(buf, "log", 3))
|
||||||
|
|
@ -399,4 +373,4 @@ void Initialize_Console(void)
|
||||||
ESP_ERROR_CHECK(
|
ESP_ERROR_CHECK(
|
||||||
esp_console_new_repl_uart(&hw_cfg, &repl_cfg, &repl));
|
esp_console_new_repl_uart(&hw_cfg, &repl_cfg, &repl));
|
||||||
ESP_ERROR_CHECK(esp_console_start_repl(repl));
|
ESP_ERROR_CHECK(esp_console_start_repl(repl));
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue