mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-04 21:24:32 +02:00
feat(log): Update esp_log_buffer
This commit is contained in:
committed by
BOT
parent
9f2b892512
commit
d9265a3f88
@@ -80,7 +80,7 @@ void esp_log_buffer_hexdump_internal(const char *tag, const void *buffer, uint16
|
|||||||
* @param level Log level
|
* @param level Log level
|
||||||
*/
|
*/
|
||||||
#define ESP_LOG_BUFFER_HEX_LEVEL(tag, buffer, buff_len, level) \
|
#define ESP_LOG_BUFFER_HEX_LEVEL(tag, buffer, buff_len, level) \
|
||||||
do { if (LOG_LOCAL_LEVEL >= (level)) {esp_log_buffer_hex_internal(tag, buffer, buff_len, level);} } while(0)
|
do { if (ESP_LOG_ENABLED(level)) {esp_log_buffer_hex_internal(tag, buffer, buff_len, level);} } while(0)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Log a buffer of characters at specified level, separated into 16 bytes each line. Buffer should contain only printable characters.
|
* @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
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#define ESP_LOG_BUFFER_CHAR_LEVEL(tag, buffer, buff_len, level) \
|
#define ESP_LOG_BUFFER_CHAR_LEVEL(tag, buffer, buff_len, level) \
|
||||||
do { if (LOG_LOCAL_LEVEL >= (level)) {esp_log_buffer_char_internal(tag, buffer, buff_len, level);} } while(0)
|
do { if (ESP_LOG_ENABLED(level)) {esp_log_buffer_char_internal(tag, buffer, buff_len, level);} } while(0)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Dump a buffer to the log at specified level.
|
* @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
|
|||||||
* @param level Log level.
|
* @param level Log level.
|
||||||
*/
|
*/
|
||||||
#define ESP_LOG_BUFFER_HEXDUMP(tag, buffer, buff_len, level) \
|
#define ESP_LOG_BUFFER_HEXDUMP(tag, buffer, buff_len, level) \
|
||||||
do { if (LOG_LOCAL_LEVEL >= (level)) {esp_log_buffer_hexdump_internal(tag, buffer, buff_len, level);} } while(0)
|
do { if (ESP_LOG_ENABLED(level)) {esp_log_buffer_hexdump_internal(tag, buffer, buff_len, level);} } while(0)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Log a buffer of hex bytes at Info level
|
* @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
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#define ESP_LOG_BUFFER_HEX(tag, buffer, buff_len) \
|
#define ESP_LOG_BUFFER_HEX(tag, buffer, buff_len) \
|
||||||
do { if (LOG_LOCAL_LEVEL >= ESP_LOG_INFO) {ESP_LOG_BUFFER_HEX_LEVEL(tag, buffer, buff_len, ESP_LOG_INFO);} } while(0)
|
do { if (ESP_LOG_ENABLED(ESP_LOG_INFO)) {ESP_LOG_BUFFER_HEX_LEVEL(tag, buffer, buff_len, ESP_LOG_INFO);} } while(0)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Log a buffer of characters at Info level. Buffer should contain only printable characters.
|
* @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
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#define ESP_LOG_BUFFER_CHAR(tag, buffer, buff_len) \
|
#define ESP_LOG_BUFFER_CHAR(tag, buffer, buff_len) \
|
||||||
do { if (LOG_LOCAL_LEVEL >= ESP_LOG_INFO) {ESP_LOG_BUFFER_CHAR_LEVEL(tag, buffer, buff_len, ESP_LOG_INFO);} } while(0)
|
do { if (ESP_LOG_ENABLED(ESP_LOG_INFO)) {ESP_LOG_BUFFER_CHAR_LEVEL(tag, buffer, buff_len, ESP_LOG_INFO);} } while(0)
|
||||||
|
|
||||||
/** @cond */
|
/** @cond */
|
||||||
/**
|
/**
|
||||||
|
@@ -44,6 +44,19 @@ ESP_STATIC_ASSERT(ESP_LOG_MAX <= ESP_LOG_LEVEL_MASK, "Log level items of esp_log
|
|||||||
#endif
|
#endif
|
||||||
#endif // LOG_LOCAL_LEVEL
|
#endif // LOG_LOCAL_LEVEL
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check if a specific log level is enabled at compile-time.
|
||||||
|
*
|
||||||
|
* This macro checks whether logging for the specified log level is enabled based on the
|
||||||
|
* current local log level setting (`LOG_LOCAL_LEVEL`). It uses a compile-time check to
|
||||||
|
* determine if logging for the specified level should be included in the binary,
|
||||||
|
* helping to exclude logs that are not configured.
|
||||||
|
*
|
||||||
|
* @param level log level.
|
||||||
|
* @return true if the specified log level is enabled, false otherwise.
|
||||||
|
*/
|
||||||
|
#define ESP_LOG_ENABLED(level) (LOG_LOCAL_LEVEL >= (level))
|
||||||
|
|
||||||
#if NON_OS_BUILD
|
#if NON_OS_BUILD
|
||||||
|
|
||||||
#define _ESP_LOG_ENABLED(log_level) (LOG_LOCAL_LEVEL >= (log_level))
|
#define _ESP_LOG_ENABLED(log_level) (LOG_LOCAL_LEVEL >= (log_level))
|
||||||
|
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <sys/param.h>
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "esp_private/log_util.h"
|
#include "esp_private/log_util.h"
|
||||||
|
|
||||||
@@ -73,7 +74,7 @@ static void print_buffer(const char *tag, const void *buffer, uint16_t buff_len,
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
const char *ptr_line = buffer;
|
const char *ptr_line = buffer;
|
||||||
int bytes_cur_line = (buff_len > BYTES_PER_LINE) ? BYTES_PER_LINE : buff_len;
|
int bytes_cur_line = MIN(BYTES_PER_LINE, buff_len);
|
||||||
if (!esp_ptr_byte_accessible(buffer)) {
|
if (!esp_ptr_byte_accessible(buffer)) {
|
||||||
//use memcpy to get around alignment issue
|
//use memcpy to get around alignment issue
|
||||||
memcpy(temp_buffer, buffer, (bytes_cur_line + 3) / 4 * 4);
|
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
|
|||||||
{
|
{
|
||||||
(void) orig_buff;
|
(void) orig_buff;
|
||||||
const unsigned char *ptr = (unsigned char *)ptr_line;
|
const unsigned char *ptr = (unsigned char *)ptr_line;
|
||||||
for (int i = 0; i < buff_len; i++) {
|
int i;
|
||||||
|
for (i = 0; i < buff_len - 1; i++) {
|
||||||
output_str += esp_log_util_cvt_hex(ptr[i], 2, output_str);
|
output_str += esp_log_util_cvt_hex(ptr[i], 2, output_str);
|
||||||
*output_str++ = ' ';
|
*output_str++ = ' ';
|
||||||
}
|
}
|
||||||
*--output_str = 0;
|
output_str += esp_log_util_cvt_hex(ptr[i], 2, output_str);
|
||||||
|
*output_str = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
static void log_buffer_char_line(uintptr_t orig_buff, const void *ptr_line, char *output_str, int buff_len)
|
static void log_buffer_char_line(uintptr_t orig_buff, const void *ptr_line, char *output_str, int buff_len)
|
||||||
|
Reference in New Issue
Block a user