mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'feature/console_log_level_command' into 'master'
console: add log_level command to the example See merge request espressif/esp-idf!18614
This commit is contained in:
commit
1b1068ce22
@ -39,6 +39,7 @@ static void register_light_sleep(void);
|
||||
#if WITH_TASKS_INFO
|
||||
static void register_tasks(void);
|
||||
#endif
|
||||
static void register_log_level(void);
|
||||
|
||||
void register_system_common(void)
|
||||
{
|
||||
@ -49,6 +50,7 @@ void register_system_common(void)
|
||||
#if WITH_TASKS_INFO
|
||||
register_tasks();
|
||||
#endif
|
||||
register_log_level();
|
||||
}
|
||||
|
||||
void register_system_sleep(void)
|
||||
@ -87,6 +89,9 @@ static int get_version(int argc, char **argv)
|
||||
case CHIP_ESP32H2:
|
||||
model = "ESP32-H2";
|
||||
break;
|
||||
case CHIP_ESP32C2:
|
||||
model = "ESP32-C2";
|
||||
break;
|
||||
default:
|
||||
model = "Unknown";
|
||||
break;
|
||||
@ -394,3 +399,68 @@ static void register_light_sleep(void)
|
||||
};
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
|
||||
}
|
||||
|
||||
/** log_level command changes log level via esp_log_level_set */
|
||||
|
||||
static struct {
|
||||
struct arg_str *tag;
|
||||
struct arg_str *level;
|
||||
struct arg_end *end;
|
||||
} log_level_args;
|
||||
|
||||
static const char* s_log_level_names[] = {
|
||||
"none",
|
||||
"error",
|
||||
"warn",
|
||||
"info",
|
||||
"debug",
|
||||
"verbose"
|
||||
};
|
||||
|
||||
static int log_level(int argc, char **argv)
|
||||
{
|
||||
int nerrors = arg_parse(argc, argv, (void **) &log_level_args);
|
||||
if (nerrors != 0) {
|
||||
arg_print_errors(stderr, log_level_args.end, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
assert(log_level_args.tag->count == 1);
|
||||
assert(log_level_args.level->count == 1);
|
||||
const char* tag = log_level_args.tag->sval[0];
|
||||
const char* level_str = log_level_args.level->sval[0];
|
||||
esp_log_level_t level;
|
||||
size_t level_len = strlen(level_str);
|
||||
for (level = ESP_LOG_NONE; level <= ESP_LOG_VERBOSE; level++) {
|
||||
if (memcmp(level_str, s_log_level_names[level], level_len) == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (level > ESP_LOG_VERBOSE) {
|
||||
printf("Invalid log level '%s', choose from none|error|warn|info|debug|verbose\n", level_str);
|
||||
return 1;
|
||||
}
|
||||
if (level > CONFIG_LOG_MAXIMUM_LEVEL) {
|
||||
printf("Can't set log level to %s, max level limited in menuconfig to %s. "
|
||||
"Please increase CONFIG_LOG_MAXIMUM_LEVEL in menuconfig.\n",
|
||||
s_log_level_names[level], s_log_level_names[CONFIG_LOG_MAXIMUM_LEVEL]);
|
||||
return 1;
|
||||
}
|
||||
esp_log_level_set(tag, level);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void register_log_level(void)
|
||||
{
|
||||
log_level_args.tag = arg_str1(NULL, NULL, "<tag|*>", "Log tag to set the level for, or * to set for all tags");
|
||||
log_level_args.level = arg_str1(NULL, NULL, "<none|error|warn|debug|verbose>", "Log level to set. Abbreviated words are accepted.");
|
||||
log_level_args.end = arg_end(2);
|
||||
|
||||
const esp_console_cmd_t cmd = {
|
||||
.command = "log_level",
|
||||
.help = "Set log level for all tags or a specific tag.",
|
||||
.hint = NULL,
|
||||
.func = &log_level,
|
||||
.argtable = &log_level_args
|
||||
};
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user