Skip to content

Commit fa3b26b

Browse files
KonstantinKondrashovespressif-bot
authored andcommitted
feat(log): Use ESP_LOG_LEVEL_LEN in cache tag_log_level
1 parent 21f7309 commit fa3b26b

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

components/log/include/esp_log_level.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#pragma once
88

99
#include <stdint.h>
10+
#include "esp_assert.h"
1011
#include "sdkconfig.h"
1112

1213
#ifdef __cplusplus
@@ -26,7 +27,11 @@ typedef enum {
2627
ESP_LOG_MAX = 6, /*!< Number of levels supported */
2728
} esp_log_level_t;
2829

30+
#define ESP_LOG_LEVEL_LEN (3) /*!< Number of bits used to represent the log level */
31+
#define ESP_LOG_LEVEL_MASK ((1 << ESP_LOG_LEVEL_LEN) - 1) /*!< Mask for log level */
32+
2933
/** @cond */
34+
ESP_STATIC_ASSERT(ESP_LOG_MAX <= ESP_LOG_LEVEL_MASK, "Log level items of esp_log_level_t must fit ESP_LOG_LEVEL_MASK");
3035

3136
// LOG_LOCAL_LEVEL controls what log levels are included in the binary.
3237
#ifndef LOG_LOCAL_LEVEL

components/log/src/log_level/tag_log_level/cache/log_binary_heap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@
5656

5757
ESP_STATIC_ASSERT(((CONFIG_LOG_TAG_LEVEL_IMPL_CACHE_SIZE & (CONFIG_LOG_TAG_LEVEL_IMPL_CACHE_SIZE + 1)) == 0), "Number of tags to be cached must be 2**n - 1, n >= 2. [1, 3, 7, 15, 31, 63, 127, 255, ...]");
5858
#define TAG_CACHE_SIZE (CONFIG_LOG_TAG_LEVEL_IMPL_CACHE_SIZE)
59-
#define MAX_GENERATION ((1 << 29) - 1)
59+
#define MAX_GENERATION ((1 << (32 - ESP_LOG_LEVEL_LEN)) - 1)
6060

6161
typedef struct {
6262
const char *tag;
63-
uint32_t level : 3;
64-
uint32_t generation : 29; // this size should be the same in MAX_GENERATION
63+
uint32_t level : ESP_LOG_LEVEL_LEN;
64+
uint32_t generation : (32 - ESP_LOG_LEVEL_LEN); // this size should be the same in MAX_GENERATION
6565
} cached_tag_entry_t;
6666

6767
static cached_tag_entry_t s_log_cache[TAG_CACHE_SIZE];

0 commit comments

Comments
 (0)