logging: Add optional function name prefix
Extended logger to support optional log message prepending with function name. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
parent
c696e68bb9
commit
5d28fcd689
5 changed files with 56 additions and 2 deletions
|
@ -42,7 +42,10 @@ extern "C" {
|
|||
|
||||
#define LOG_DEBRACKET(...) __VA_ARGS__
|
||||
|
||||
#define __LOG_ARG_1(val, ...) val
|
||||
#define __LOG_ARG_2(ignore_this, val, ...) val
|
||||
#define __LOG_ARGS_LESS1(val, ...) __VA_ARGS__
|
||||
|
||||
#define __LOG_ARG_2_DEBRACKET(ignore_this, val, ...) LOG_DEBRACKET val
|
||||
|
||||
/**
|
||||
|
@ -72,6 +75,26 @@ extern "C" {
|
|||
#define _LOG_EVAL2(one_or_two_args, _iftrue, _iffalse) \
|
||||
__LOG_ARG_2_DEBRACKET(one_or_two_args _iftrue, _iffalse)
|
||||
|
||||
/**
|
||||
* @brief Macro for condition code generation.
|
||||
*
|
||||
* @param _eval Parameter evaluated against 0
|
||||
* @param _ifzero Code included if _eval is 0. Must be wrapped in brackets.
|
||||
* @param _ifnzero Code included if _eval is not 0.
|
||||
* Must be wrapped in brackets.
|
||||
*/
|
||||
|
||||
#define _LOG_Z_EVAL(_eval, _ifzero, _ifnzero) \
|
||||
_LOG_Z_EVAL1(_eval, _ifzero, _ifnzero)
|
||||
|
||||
#define _LOG_Z_EVAL1(_eval, _ifzero, _ifnzero) \
|
||||
_LOG_Z_EVAL2(_LOG_Z_ZZZZ##_eval, _ifzero, _ifnzero)
|
||||
|
||||
#define _LOG_Z_ZZZZ0 _LOG_Z_YYYY,
|
||||
|
||||
#define _LOG_Z_EVAL2(one_or_two_args, _ifzero, _ifnzero) \
|
||||
__LOG_ARG_2_DEBRACKET(one_or_two_args _ifzero, _ifnzero)
|
||||
|
||||
/** @brief Macro for getting log level for given module.
|
||||
*
|
||||
* It is evaluated to LOG_LEVEL if defined. Otherwise CONFIG_LOG_DEFAULT_LEVEL
|
||||
|
@ -125,6 +148,26 @@ extern "C" {
|
|||
(0) \
|
||||
)
|
||||
|
||||
/**
|
||||
* @brief Macro for optional injection of function name as first argument of
|
||||
* formatted string. _LOG_Z_EVAL() macro is used to handle no arguments
|
||||
* case.
|
||||
*
|
||||
* The purpose of this macro is to prefix string literal with format
|
||||
* specifier for function name and inject function name as first
|
||||
* argument. In order to handle string with no arguments _LOG_Z_EVAL is
|
||||
* used.
|
||||
*/
|
||||
#if CONFIG_LOG_FUNCTION_NAME
|
||||
#define _LOG_STR(...) "%s: " __LOG_ARG_1(__VA_ARGS__), __func__\
|
||||
_LOG_Z_EVAL(NUM_VA_ARGS_LESS_1(__VA_ARGS__),\
|
||||
(),\
|
||||
(, __LOG_ARGS_LESS1(__VA_ARGS__))\
|
||||
)
|
||||
#else
|
||||
#define _LOG_STR(...) __VA_ARGS__
|
||||
#endif
|
||||
|
||||
/******************************************************************************/
|
||||
/****************** Internal macros for log frontend **************************/
|
||||
/******************************************************************************/
|
||||
|
@ -203,7 +246,7 @@ extern "C" {
|
|||
.source_id = _id, \
|
||||
.domain_id = CONFIG_LOG_DOMAIN_ID \
|
||||
}; \
|
||||
__LOG_INTERNAL(src_level, __VA_ARGS__); \
|
||||
__LOG_INTERNAL(src_level, _LOG_STR(__VA_ARGS__)); \
|
||||
} else if (0) { \
|
||||
/* Arguments checker present but never evaluated.*/ \
|
||||
/* Placed here to ensure that __VA_ARGS__ are*/ \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue