fix(log): Fix log_level_get, add item to cache after checking linked list

This commit is contained in:
Konstantin Kondrashov 2024-05-21 16:18:11 +03:00
parent 438971c108
commit d3ed1198d3
2 changed files with 14 additions and 6 deletions

View File

@ -68,17 +68,15 @@ static esp_log_level_t log_level_get(const char *tag, bool timeout)
} else {
esp_log_impl_lock();
}
bool search_in_linked_list = !CACHE_ENABLED;
#if CACHE_ENABLED
bool cache_miss = !esp_log_cache_get_level(tag, &level_for_tag);
if (cache_miss) {
search_in_linked_list = true;
esp_log_linked_list_get_level(tag, &level_for_tag);
esp_log_cache_add(tag, level_for_tag);
}
#endif // CACHE_ENABLED
if (search_in_linked_list) {
esp_log_linked_list_get_level(tag, &level_for_tag);
}
#else
esp_log_linked_list_get_level(tag, &level_for_tag);
#endif
esp_log_impl_unlock();
return level_for_tag;
}

View File

@ -98,6 +98,16 @@ TEST_CASE("LOG_LOCAL_LEVEL can be re-defined", "[log]")
TEST_ASSERT_GREATER_THAN(17, get_counter());
TEST_ASSERT_NOT_NULL(strstr(get_buffer(), "There is an info log"));
reset_buffer();
esp_log_level_set("*", ESP_LOG_INFO);
esp_log_level_set(TAG1, ESP_LOG_DEBUG);
ESP_LOGD(TAG1, "There is a debug log");
TEST_ASSERT_NOT_NULL(strstr(get_buffer(), "There is a debug log"));
reset_buffer();
ESP_LOGD(TAG1, "There is 2nd debug log");
TEST_ASSERT_NOT_NULL(strstr(get_buffer(), "There is 2nd debug log"));
esp_log_level_set("*", ESP_LOG_ERROR);
reset_buffer();
ESP_LOGI(TAG1, "There is an info log");