logging: add mechanism for handling transient strings
Extending logger to support logging transient strings (with %s). With dedicated call (log_strdup), string is duplicated to a buffer from internal logger pool. Logger implicitly manages the pool. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
parent
6cb20ab4c1
commit
a15438e8f5
9 changed files with 184 additions and 11 deletions
|
@ -255,6 +255,19 @@ extern "C" {
|
|||
*/
|
||||
int log_printk(const char *fmt, va_list ap);
|
||||
|
||||
/** @brief Copy transient string to a buffer from internal, logger pool.
|
||||
*
|
||||
* Function should be used when transient string is intended to be logged.
|
||||
* Logger allocates a buffer and copies input string returning a pointer to the
|
||||
* copy. Logger ensures that buffer is freed when logger message is freed.
|
||||
*
|
||||
* @param str Transient string.
|
||||
*
|
||||
* @return Copy of the string or default string if buffer could not be
|
||||
* allocated. String may be truncated if input string does not fit in
|
||||
* a buffer from the pool (see CONFIG_LOG_STRDUP_MAX_STRING).
|
||||
*/
|
||||
char *log_strdup(char *str);
|
||||
|
||||
#define __DYNAMIC_MODULE_REGISTER(_name)\
|
||||
struct log_source_dynamic_data LOG_ITEM_DYNAMIC_DATA(_name) \
|
||||
|
|
|
@ -472,6 +472,20 @@ int log_printk(const char *fmt, va_list ap);
|
|||
*/
|
||||
void log_generic(struct log_msg_ids src_level, const char *fmt, va_list ap);
|
||||
|
||||
/** @brief Check if address belongs to the memory pool used for transient.
|
||||
*
|
||||
* @param buf Buffer.
|
||||
*
|
||||
* @return True if address within the pool, false otherwise.
|
||||
*/
|
||||
bool log_is_strdup(void *buf);
|
||||
|
||||
/** @brief Free allocated buffer.
|
||||
*
|
||||
* @param buf Buffer.
|
||||
*/
|
||||
void log_free(void *buf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -23,7 +23,7 @@ extern "C" {
|
|||
*/
|
||||
|
||||
/** @brief Maximum number of arguments in the standard log entry. */
|
||||
#define LOG_MAX_NARGS 6
|
||||
#define LOG_MAX_NARGS 9
|
||||
|
||||
/** @brief Number of arguments in the log entry which fits in one chunk.*/
|
||||
#define LOG_MSG_NARGS_SINGLE_CHUNK 3
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue