esp_log_level_set() with tag provided as variable has no effect
Posted: Mon Jan 28, 2019 10:17 am
For many months I have used code such as:
However I'd like to programmatically enable debugging for certain tags in response to certain events. The tag I wish to set is stored in a char *, such that I wish to call:
However I've noticed that this does not work, for both stack-allocated and heap-allocated char arrays. It seems that unless the tag is a literal string, the log level is not set for the specified tag. However a string variable with the contents "*" does enable logging for all tags.
Is this a limitation in the way the logging mechanism works?
I'm using ESP-IDF 3.0.6+ (7e0ea6b05db8ad5d1a8dc183414ca8cd456ec934).
EDIT: After inspecting components/log/log.c it seems like a complete mystery to me. There is no macro magic, and the tag parameter is simply compared or copied, so any null-terminated char pointer should work fine.
EDIT2: I've printf-traced through esp_log_level_set() with both a literal tag and a variable tag, and the behaviour seems to be identical. In both cases, it->level is set to the specified level.
Code: Select all
esp_log_level_set("mytag", ESP_LOG_DEBUG);
Code: Select all
void set_debug(char * tag) {
esp_log_level_set(tag, ESP_LOG_DEBUG);
}
Is this a limitation in the way the logging mechanism works?
I'm using ESP-IDF 3.0.6+ (7e0ea6b05db8ad5d1a8dc183414ca8cd456ec934).
EDIT: After inspecting components/log/log.c it seems like a complete mystery to me. There is no macro magic, and the tag parameter is simply compared or copied, so any null-terminated char pointer should work fine.
EDIT2: I've printf-traced through esp_log_level_set() with both a literal tag and a variable tag, and the behaviour seems to be identical. In both cases, it->level is set to the specified level.