Skip to content

Commit d9265a3

Browse files
KonstantinKondrashovespressif-bot
authored andcommitted
feat(log): Update esp_log_buffer
1 parent 9f2b892 commit d9265a3

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

components/log/include/esp_log_buffer.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void esp_log_buffer_hexdump_internal(const char *tag, const void *buffer, uint16
8080
* @param level Log level
8181
*/
8282
#define ESP_LOG_BUFFER_HEX_LEVEL(tag, buffer, buff_len, level) \
83-
do { if (LOG_LOCAL_LEVEL >= (level)) {esp_log_buffer_hex_internal(tag, buffer, buff_len, level);} } while(0)
83+
do { if (ESP_LOG_ENABLED(level)) {esp_log_buffer_hex_internal(tag, buffer, buff_len, level);} } while(0)
8484

8585
/**
8686
* @brief Log a buffer of characters at specified level, separated into 16 bytes each line. Buffer should contain only printable characters.
@@ -100,7 +100,7 @@ void esp_log_buffer_hexdump_internal(const char *tag, const void *buffer, uint16
100100
*
101101
*/
102102
#define ESP_LOG_BUFFER_CHAR_LEVEL(tag, buffer, buff_len, level) \
103-
do { if (LOG_LOCAL_LEVEL >= (level)) {esp_log_buffer_char_internal(tag, buffer, buff_len, level);} } while(0)
103+
do { if (ESP_LOG_ENABLED(level)) {esp_log_buffer_char_internal(tag, buffer, buff_len, level);} } while(0)
104104

105105
/**
106106
* @brief Dump a buffer to the log at specified level.
@@ -121,7 +121,7 @@ void esp_log_buffer_hexdump_internal(const char *tag, const void *buffer, uint16
121121
* @param level Log level.
122122
*/
123123
#define ESP_LOG_BUFFER_HEXDUMP(tag, buffer, buff_len, level) \
124-
do { if (LOG_LOCAL_LEVEL >= (level)) {esp_log_buffer_hexdump_internal(tag, buffer, buff_len, level);} } while(0)
124+
do { if (ESP_LOG_ENABLED(level)) {esp_log_buffer_hexdump_internal(tag, buffer, buff_len, level);} } while(0)
125125

126126
/**
127127
* @brief Log a buffer of hex bytes at Info level
@@ -134,7 +134,7 @@ void esp_log_buffer_hexdump_internal(const char *tag, const void *buffer, uint16
134134
*
135135
*/
136136
#define ESP_LOG_BUFFER_HEX(tag, buffer, buff_len) \
137-
do { if (LOG_LOCAL_LEVEL >= ESP_LOG_INFO) {ESP_LOG_BUFFER_HEX_LEVEL(tag, buffer, buff_len, ESP_LOG_INFO);} } while(0)
137+
do { if (ESP_LOG_ENABLED(ESP_LOG_INFO)) {ESP_LOG_BUFFER_HEX_LEVEL(tag, buffer, buff_len, ESP_LOG_INFO);} } while(0)
138138

139139
/**
140140
* @brief Log a buffer of characters at Info level. Buffer should contain only printable characters.
@@ -147,7 +147,7 @@ void esp_log_buffer_hexdump_internal(const char *tag, const void *buffer, uint16
147147
*
148148
*/
149149
#define ESP_LOG_BUFFER_CHAR(tag, buffer, buff_len) \
150-
do { if (LOG_LOCAL_LEVEL >= ESP_LOG_INFO) {ESP_LOG_BUFFER_CHAR_LEVEL(tag, buffer, buff_len, ESP_LOG_INFO);} } while(0)
150+
do { if (ESP_LOG_ENABLED(ESP_LOG_INFO)) {ESP_LOG_BUFFER_CHAR_LEVEL(tag, buffer, buff_len, ESP_LOG_INFO);} } while(0)
151151

152152
/** @cond */
153153
/**

components/log/include/esp_log_level.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ ESP_STATIC_ASSERT(ESP_LOG_MAX <= ESP_LOG_LEVEL_MASK, "Log level items of esp_log
4444
#endif
4545
#endif // LOG_LOCAL_LEVEL
4646

47+
/**
48+
* @brief Check if a specific log level is enabled at compile-time.
49+
*
50+
* This macro checks whether logging for the specified log level is enabled based on the
51+
* current local log level setting (`LOG_LOCAL_LEVEL`). It uses a compile-time check to
52+
* determine if logging for the specified level should be included in the binary,
53+
* helping to exclude logs that are not configured.
54+
*
55+
* @param level log level.
56+
* @return true if the specified log level is enabled, false otherwise.
57+
*/
58+
#define ESP_LOG_ENABLED(level) (LOG_LOCAL_LEVEL >= (level))
59+
4760
#if NON_OS_BUILD
4861

4962
#define _ESP_LOG_ENABLED(log_level) (LOG_LOCAL_LEVEL >= (log_level))

components/log/src/buffer/log_buffers.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <string.h>
88
#include <stdbool.h>
9+
#include <sys/param.h>
910
#include "esp_log.h"
1011
#include "esp_private/log_util.h"
1112

@@ -73,7 +74,7 @@ static void print_buffer(const char *tag, const void *buffer, uint16_t buff_len,
7374

7475
do {
7576
const char *ptr_line = buffer;
76-
int bytes_cur_line = (buff_len > BYTES_PER_LINE) ? BYTES_PER_LINE : buff_len;
77+
int bytes_cur_line = MIN(BYTES_PER_LINE, buff_len);
7778
if (!esp_ptr_byte_accessible(buffer)) {
7879
//use memcpy to get around alignment issue
7980
memcpy(temp_buffer, buffer, (bytes_cur_line + 3) / 4 * 4);
@@ -92,11 +93,13 @@ static void log_buffer_hex_line(uintptr_t orig_buff, const void *ptr_line, char
9293
{
9394
(void) orig_buff;
9495
const unsigned char *ptr = (unsigned char *)ptr_line;
95-
for (int i = 0; i < buff_len; i++) {
96+
int i;
97+
for (i = 0; i < buff_len - 1; i++) {
9698
output_str += esp_log_util_cvt_hex(ptr[i], 2, output_str);
9799
*output_str++ = ' ';
98100
}
99-
*--output_str = 0;
101+
output_str += esp_log_util_cvt_hex(ptr[i], 2, output_str);
102+
*output_str = '\0';
100103
}
101104

102105
static void log_buffer_char_line(uintptr_t orig_buff, const void *ptr_line, char *output_str, int buff_len)

0 commit comments

Comments
 (0)