From d3ed1198d384374d90beedc136979eadd104ad17 Mon Sep 17 00:00:00 2001 From: Konstantin Kondrashov Date: Tue, 21 May 2024 16:18:11 +0300 Subject: [PATCH] fix(log): Fix log_level_get, add item to cache after checking linked list --- .../log/src/log_level/tag_log_level/tag_log_level.c | 10 ++++------ components/log/test_apps/main/test_log_level.c | 10 ++++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/components/log/src/log_level/tag_log_level/tag_log_level.c b/components/log/src/log_level/tag_log_level/tag_log_level.c index 835d9a85f4..aa4d92707f 100644 --- a/components/log/src/log_level/tag_log_level/tag_log_level.c +++ b/components/log/src/log_level/tag_log_level/tag_log_level.c @@ -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; } diff --git a/components/log/test_apps/main/test_log_level.c b/components/log/test_apps/main/test_log_level.c index 2bfa70fe6a..b51dc1ad5c 100644 --- a/components/log/test_apps/main/test_log_level.c +++ b/components/log/test_apps/main/test_log_level.c @@ -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");