logging: Add metadata to hexdump
Extended hexdump API with a raw string attached to the data. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
parent
f8a8bdf392
commit
3c63d05dfc
9 changed files with 144 additions and 147 deletions
|
@ -136,11 +136,12 @@ extern "C" {
|
|||
* @details It's meant to report severe errors, such as those from which it's
|
||||
* not possible to recover.
|
||||
*
|
||||
* @param data Pointer to the data to be logged.
|
||||
* @param length Length of data (in bytes).
|
||||
* @param _data Pointer to the data to be logged.
|
||||
* @param _length Length of data (in bytes).
|
||||
* @param _str Persistent, raw string.
|
||||
*/
|
||||
#define LOG_HEXDUMP_ERR(data, length) \
|
||||
_LOG_HEXDUMP(LOG_LEVEL_ERR, data, length)
|
||||
#define LOG_HEXDUMP_ERR(_data, _length, _str) \
|
||||
_LOG_HEXDUMP(LOG_LEVEL_ERR, _data, _length, _str)
|
||||
|
||||
/**
|
||||
* @brief Writes a WARNING level message to the log.
|
||||
|
@ -148,33 +149,36 @@ extern "C" {
|
|||
* @details It's meant to register messages related to unusual situations that
|
||||
* are not necessarily errors.
|
||||
*
|
||||
* @param data Pointer to the data to be logged.
|
||||
* @param length Length of data (in bytes).
|
||||
* @param _data Pointer to the data to be logged.
|
||||
* @param _length Length of data (in bytes).
|
||||
* @param _str Persistent, raw string.
|
||||
*/
|
||||
#define LOG_HEXDUMP_WRN(data, length) \
|
||||
_LOG_HEXDUMP(LOG_LEVEL_WRN, data, length)
|
||||
#define LOG_HEXDUMP_WRN(_data, _length, _str) \
|
||||
_LOG_HEXDUMP(LOG_LEVEL_WRN, _data, _length, _str)
|
||||
|
||||
/**
|
||||
* @brief Writes an INFO level message to the log.
|
||||
*
|
||||
* @details It's meant to write generic user oriented messages.
|
||||
*
|
||||
* @param data Pointer to the data to be logged.
|
||||
* @param length Length of data (in bytes).
|
||||
* @param _data Pointer to the data to be logged.
|
||||
* @param _length Length of data (in bytes).
|
||||
* @param _str Persistent, raw string.
|
||||
*/
|
||||
#define LOG_HEXDUMP_INF(data, length) \
|
||||
_LOG_HEXDUMP(LOG_LEVEL_INF, data, length)
|
||||
#define LOG_HEXDUMP_INF(_data, _length, _str) \
|
||||
_LOG_HEXDUMP(LOG_LEVEL_INF, _data, _length, _str)
|
||||
|
||||
/**
|
||||
* @brief Writes a DEBUG level message to the log.
|
||||
*
|
||||
* @details It's meant to write developer oriented information.
|
||||
*
|
||||
* @param data Pointer to the data to be logged.
|
||||
* @param length Length of data (in bytes).
|
||||
* @param _data Pointer to the data to be logged.
|
||||
* @param _length Length of data (in bytes).
|
||||
* @param _str Persistent, raw string.
|
||||
*/
|
||||
#define LOG_HEXDUMP_DBG(data, length) \
|
||||
_LOG_HEXDUMP(LOG_LEVEL_DBG, data, length)
|
||||
#define LOG_HEXDUMP_DBG(_data, _length, _str) \
|
||||
_LOG_HEXDUMP(LOG_LEVEL_DBG, _data, _length, _str)
|
||||
|
||||
/**
|
||||
* @brief Writes an ERROR hexdump message associated with the instance to the
|
||||
|
@ -186,11 +190,12 @@ extern "C" {
|
|||
* severe errors, such as those from which it's not possible to recover.
|
||||
*
|
||||
* @param _log_inst Pointer to the log structure associated with the instance.
|
||||
* @param data Pointer to the data to be logged.
|
||||
* @param length Length of data (in bytes).
|
||||
* @param _data Pointer to the data to be logged.
|
||||
* @param _length Length of data (in bytes).
|
||||
* @param _str Persistent, raw string.
|
||||
*/
|
||||
#define LOG_INST_HEXDUMP_ERR(_log_inst, data, length) \
|
||||
_LOG_HEXDUMP_INSTANCE(LOG_LEVEL_ERR, _log_inst, data, length)
|
||||
#define LOG_INST_HEXDUMP_ERR(_log_inst, _data, _length, _str) \
|
||||
_LOG_HEXDUMP_INSTANCE(LOG_LEVEL_ERR, _log_inst, _data, _length, _str)
|
||||
|
||||
/**
|
||||
* @brief Writes a WARNING level hexdump message associated with the instance to
|
||||
|
@ -200,11 +205,12 @@ extern "C" {
|
|||
* are not necessarily errors.
|
||||
*
|
||||
* @param _log_inst Pointer to the log structure associated with the instance.
|
||||
* @param data Pointer to the data to be logged.
|
||||
* @param length Length of data (in bytes).
|
||||
* @param _data Pointer to the data to be logged.
|
||||
* @param _length Length of data (in bytes).
|
||||
* @param _str Persistent, raw string.
|
||||
*/
|
||||
#define LOG_INST_HEXDUMP_WRN(_log_inst, data, length) \
|
||||
_LOG_HEXDUMP_INSTANCE(LOG_LEVEL_WRN, _log_inst, data, length)
|
||||
#define LOG_INST_HEXDUMP_WRN(_log_inst, _data, _length, _str) \
|
||||
_LOG_HEXDUMP_INSTANCE(LOG_LEVEL_WRN, _log_inst, _data, _length, _str)
|
||||
|
||||
/**
|
||||
* @brief Writes an INFO level hexdump message associated with the instance to
|
||||
|
@ -213,11 +219,12 @@ extern "C" {
|
|||
* @details It's meant to write generic user oriented messages.
|
||||
*
|
||||
* @param _log_inst Pointer to the log structure associated with the instance.
|
||||
* @param data Pointer to the data to be logged.
|
||||
* @param length Length of data (in bytes).
|
||||
* @param _data Pointer to the data to be logged.
|
||||
* @param _length Length of data (in bytes).
|
||||
* @param _str Persistent, raw string.
|
||||
*/
|
||||
#define LOG_INST_HEXDUMP_INF(_log_inst, data, length) \
|
||||
_LOG_HEXDUMP_INSTANCE(LOG_LEVEL_INF, _log_inst, data, length)
|
||||
#define LOG_INST_HEXDUMP_INF(_log_inst, _data, _length, _str) \
|
||||
_LOG_HEXDUMP_INSTANCE(LOG_LEVEL_INF, _log_inst, _data, _length, _str)
|
||||
|
||||
/**
|
||||
* @brief Writes a DEBUG level hexdump message associated with the instance to
|
||||
|
@ -226,11 +233,12 @@ extern "C" {
|
|||
* @details It's meant to write developer oriented information.
|
||||
*
|
||||
* @param _log_inst Pointer to the log structure associated with the instance.
|
||||
* @param _data Pointer to the data to be logged.
|
||||
* @param _length Length of data (in bytes).
|
||||
* @param _data Pointer to the data to be logged.
|
||||
* @param _length Length of data (in bytes).
|
||||
* @param _str Persistent, raw string.
|
||||
*/
|
||||
#define LOG_INST_HEXDUMP_DBG(_log_inst, _data, _length) \
|
||||
_LOG_HEXDUMP_INSTANCE(LOG_LEVEL_DBG, _log_inst, _data, _length)
|
||||
#define LOG_INST_HEXDUMP_DBG(_log_inst, _data, _length, _str) \
|
||||
_LOG_HEXDUMP_INSTANCE(LOG_LEVEL_DBG, _log_inst, _data, _length, _str)
|
||||
|
||||
/**
|
||||
* @brief Writes an formatted string to the log.
|
||||
|
|
|
@ -226,33 +226,34 @@ extern "C" {
|
|||
/******************************************************************************/
|
||||
/****************** Macros for hexdump logging ********************************/
|
||||
/******************************************************************************/
|
||||
#define __LOG_HEXDUMP(_level, _id, _filter, _data, _length) \
|
||||
do { \
|
||||
if (_LOG_CONST_LEVEL_CHECK(_level) && \
|
||||
(_level <= LOG_RUNTIME_FILTER(_filter))) { \
|
||||
struct log_msg_ids src_level = { \
|
||||
.level = _level, \
|
||||
.source_id = _id, \
|
||||
.domain_id = CONFIG_LOG_DOMAIN_ID \
|
||||
}; \
|
||||
log_hexdump(_data, _length, src_level); \
|
||||
} \
|
||||
#define __LOG_HEXDUMP(_level, _id, _filter, _data, _length, _str) \
|
||||
do { \
|
||||
if (_LOG_CONST_LEVEL_CHECK(_level) && \
|
||||
(_level <= LOG_RUNTIME_FILTER(_filter))) { \
|
||||
struct log_msg_ids src_level = { \
|
||||
.level = _level, \
|
||||
.source_id = _id, \
|
||||
.domain_id = CONFIG_LOG_DOMAIN_ID \
|
||||
}; \
|
||||
log_hexdump(_str, _data, _length, src_level); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define _LOG_HEXDUMP(_level, _data, _length) \
|
||||
#define _LOG_HEXDUMP(_level, _data, _length, _str) \
|
||||
__LOG_HEXDUMP(_level, \
|
||||
LOG_CURRENT_MODULE_ID(), \
|
||||
LOG_CURRENT_DYNAMIC_DATA_ADDR(), \
|
||||
_data, _length)
|
||||
_data, _length, _str)
|
||||
|
||||
#define _LOG_HEXDUMP_INSTANCE(_level, _inst, _data, _length) \
|
||||
__LOG_HEXDUMP(_level, \
|
||||
IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ? \
|
||||
LOG_DYNAMIC_ID_GET(_inst) : \
|
||||
LOG_CONST_ID_GET(_inst), \
|
||||
_inst, \
|
||||
_data, \
|
||||
_length)
|
||||
#define _LOG_HEXDUMP_INSTANCE(_level, _inst, _data, _length, _str) \
|
||||
__LOG_HEXDUMP(_level, \
|
||||
IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ? \
|
||||
LOG_DYNAMIC_ID_GET(_inst) : \
|
||||
LOG_CONST_ID_GET(_inst), \
|
||||
_inst, \
|
||||
_data, \
|
||||
_length, \
|
||||
_str)
|
||||
|
||||
/******************************************************************************/
|
||||
/****************** Filtering macros ******************************************/
|
||||
|
@ -444,11 +445,13 @@ void log_n(const char *str,
|
|||
|
||||
/** @brief Hexdump log.
|
||||
*
|
||||
* @param str String.
|
||||
* @param data Data.
|
||||
* @param length Data length.
|
||||
* @param src_level Log identification.
|
||||
*/
|
||||
void log_hexdump(const u8_t *data,
|
||||
void log_hexdump(const char *str,
|
||||
const u8_t *data,
|
||||
u32_t length,
|
||||
struct log_msg_ids src_level);
|
||||
|
||||
|
|
|
@ -74,8 +74,8 @@ struct log_msg_ids {
|
|||
u16_t source_id : 10; /*!< Source ID. */
|
||||
};
|
||||
|
||||
BUILD_ASSERT_MSG((sizeof(struct log_msg_ids) == sizeof(u16_t)), \
|
||||
"Structure must fit in 2 bytes");
|
||||
BUILD_ASSERT_MSG((sizeof(struct log_msg_ids) == sizeof(u16_t)),
|
||||
"Structure must fit in 2 bytes");
|
||||
|
||||
/** Part of log message header common to standard and hexdump log message. */
|
||||
struct log_msg_generic_hdr {
|
||||
|
@ -83,8 +83,8 @@ struct log_msg_generic_hdr {
|
|||
u16_t reserved : 14;
|
||||
};
|
||||
|
||||
BUILD_ASSERT_MSG((sizeof(struct log_msg_generic_hdr) == sizeof(u16_t)), \
|
||||
"Structure must fit in 2 bytes");
|
||||
BUILD_ASSERT_MSG((sizeof(struct log_msg_generic_hdr) == sizeof(u16_t)),
|
||||
"Structure must fit in 2 bytes");
|
||||
|
||||
/** Part of log message header specific to standard log message. */
|
||||
struct log_msg_std_hdr {
|
||||
|
@ -93,8 +93,8 @@ struct log_msg_std_hdr {
|
|||
u16_t nargs : 4;
|
||||
};
|
||||
|
||||
BUILD_ASSERT_MSG((sizeof(struct log_msg_std_hdr) == sizeof(u16_t)), \
|
||||
"Structure must fit in 2 bytes");
|
||||
BUILD_ASSERT_MSG((sizeof(struct log_msg_std_hdr) == sizeof(u16_t)),
|
||||
"Structure must fit in 2 bytes");
|
||||
|
||||
/** Part of log message header specific to hexdump log message. */
|
||||
struct log_msg_hexdump_hdr {
|
||||
|
@ -103,8 +103,8 @@ struct log_msg_hexdump_hdr {
|
|||
u16_t length : LOG_MSG_HEXDUMP_LENGTH_BITS;
|
||||
};
|
||||
|
||||
BUILD_ASSERT_MSG((sizeof(struct log_msg_hexdump_hdr) == sizeof(u16_t)), \
|
||||
"Structure must fit in 2 bytes");
|
||||
BUILD_ASSERT_MSG((sizeof(struct log_msg_hexdump_hdr) == sizeof(u16_t)),
|
||||
"Structure must fit in 2 bytes");
|
||||
|
||||
/** Log message header structure */
|
||||
struct log_msg_hdr {
|
||||
|
@ -119,25 +119,9 @@ struct log_msg_hdr {
|
|||
u32_t timestamp; /*!< Timestamp. */
|
||||
};
|
||||
|
||||
/** @brief Data part of head of standard log message. */
|
||||
struct log_msg_std_head_data {
|
||||
const char *str;
|
||||
u32_t args[LOG_MSG_NARGS_SINGLE_CHUNK];
|
||||
};
|
||||
|
||||
/** @brief Data part of head of extended standard log message.
|
||||
*
|
||||
* @details When message is extended, head of the message contains also a
|
||||
* pointer to the next chunk thus data part is reduced.
|
||||
*/
|
||||
struct log_msg_std_ext_head_data {
|
||||
const char *str;
|
||||
u32_t args[LOG_MSG_NARGS_HEAD_CHUNK];
|
||||
};
|
||||
|
||||
/** @brief Data part of log message. */
|
||||
union log_msg_head_data {
|
||||
struct log_msg_std_head_data std;
|
||||
u32_t args[LOG_MSG_NARGS_SINGLE_CHUNK];
|
||||
u8_t bytes[LOG_MSG_HEXDUMP_BYTES_SINGLE_CHUNK];
|
||||
};
|
||||
|
||||
|
@ -145,7 +129,7 @@ union log_msg_head_data {
|
|||
struct log_msg_ext_head_data {
|
||||
struct log_msg_cont *next;
|
||||
union log_msg_ext_head_data_data {
|
||||
struct log_msg_std_ext_head_data std;
|
||||
u32_t args[LOG_MSG_NARGS_HEAD_CHUNK];
|
||||
u8_t bytes[LOG_MSG_HEXDUMP_BYTES_HEAD_CHUNK];
|
||||
} data;
|
||||
};
|
||||
|
@ -154,16 +138,16 @@ struct log_msg_ext_head_data {
|
|||
struct log_msg {
|
||||
struct log_msg *next; /*!< Used by logger core list.*/
|
||||
struct log_msg_hdr hdr; /*!< Message header. */
|
||||
|
||||
const char *str;
|
||||
union log_msg_data {
|
||||
union log_msg_head_data data;
|
||||
union log_msg_head_data single;
|
||||
struct log_msg_ext_head_data ext;
|
||||
} data; /*!< Message data. */
|
||||
} payload; /*!< Message data. */
|
||||
};
|
||||
|
||||
BUILD_ASSERT_MSG((sizeof(union log_msg_head_data) == \
|
||||
sizeof(struct log_msg_ext_head_data)), \
|
||||
"Structure must be same size");
|
||||
BUILD_ASSERT_MSG((sizeof(union log_msg_head_data) ==
|
||||
sizeof(struct log_msg_ext_head_data)),
|
||||
"Structure must be same size");
|
||||
|
||||
/** @brief Chunks following message head when message is extended. */
|
||||
struct log_msg_cont {
|
||||
|
@ -171,7 +155,7 @@ struct log_msg_cont {
|
|||
union log_msg_cont_data {
|
||||
u32_t args[ARGS_CONT_MSG];
|
||||
u8_t bytes[HEXDUMP_BYTES_CONT_MSG];
|
||||
} data;
|
||||
} payload;
|
||||
};
|
||||
|
||||
/** @brief Log message */
|
||||
|
@ -307,12 +291,15 @@ const char *log_msg_str_get(struct log_msg *msg);
|
|||
*
|
||||
* @note Allocation and partial filling is combined for performance reasons.
|
||||
*
|
||||
* @param str String.
|
||||
* @param data Data.
|
||||
* @param length Data length.
|
||||
*
|
||||
* @return Pointer to allocated head of the message or NULL
|
||||
*/
|
||||
struct log_msg *log_msg_hexdump_create(const u8_t *data, u32_t length);
|
||||
struct log_msg *log_msg_hexdump_create(const char *str,
|
||||
const u8_t *data,
|
||||
u32_t length);
|
||||
|
||||
/** @brief Put data into hexdump log message.
|
||||
*
|
||||
|
@ -393,7 +380,7 @@ static inline struct log_msg *_log_msg_ext_std_alloc(void)
|
|||
}
|
||||
|
||||
msg->hdr.params.generic.ext = 1;
|
||||
msg->data.ext.next = cont;
|
||||
msg->payload.ext.next = cont;
|
||||
cont->next = NULL;
|
||||
}
|
||||
|
||||
|
@ -413,7 +400,7 @@ static inline struct log_msg *log_msg_create_0(const char *str)
|
|||
struct log_msg *msg = _log_msg_std_alloc();
|
||||
|
||||
if (msg != NULL) {
|
||||
msg->data.data.std.str = str;
|
||||
msg->str = str;
|
||||
}
|
||||
|
||||
return msg;
|
||||
|
@ -438,9 +425,9 @@ static inline struct log_msg *log_msg_create_1(const char *str,
|
|||
struct log_msg *msg = _log_msg_std_alloc();
|
||||
|
||||
if (msg != NULL) {
|
||||
msg->str = str;
|
||||
msg->hdr.params.std.nargs = 1;
|
||||
msg->data.data.std.str = str;
|
||||
msg->data.data.std.args[0] = arg1;
|
||||
msg->payload.single.args[0] = arg1;
|
||||
}
|
||||
|
||||
return msg;
|
||||
|
@ -467,10 +454,10 @@ static inline struct log_msg *log_msg_create_2(const char *str,
|
|||
struct log_msg *msg = _log_msg_std_alloc();
|
||||
|
||||
if (msg != NULL) {
|
||||
msg->str = str;
|
||||
msg->hdr.params.std.nargs = 2;
|
||||
msg->data.data.std.str = str;
|
||||
msg->data.data.std.args[0] = arg1;
|
||||
msg->data.data.std.args[1] = arg2;
|
||||
msg->payload.single.args[0] = arg1;
|
||||
msg->payload.single.args[1] = arg2;
|
||||
}
|
||||
|
||||
return msg;
|
||||
|
@ -499,11 +486,11 @@ static inline struct log_msg *log_msg_create_3(const char *str,
|
|||
struct log_msg *msg = _log_msg_std_alloc();
|
||||
|
||||
if (msg != NULL) {
|
||||
msg->str = str;
|
||||
msg->hdr.params.std.nargs = 3;
|
||||
msg->data.data.std.str = str;
|
||||
msg->data.data.std.args[0] = arg1;
|
||||
msg->data.data.std.args[1] = arg2;
|
||||
msg->data.data.std.args[2] = arg3;
|
||||
msg->payload.single.args[0] = arg1;
|
||||
msg->payload.single.args[1] = arg2;
|
||||
msg->payload.single.args[2] = arg3;
|
||||
}
|
||||
|
||||
return msg;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue