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
|
@ -100,6 +100,8 @@ it is not set or set lower than the override value.
|
|||
:option:`CONFIG_LOG_MAX_LEVEL`: Maximal (lowest severity) level which is
|
||||
compiled in.
|
||||
|
||||
:option:`CONFIG_LOG_FUNCTION_NAME`: Prepend log message with function name.
|
||||
|
||||
:option:`CONFIG_LOG_PRINTK`: Redirect printk calls to the logger.
|
||||
|
||||
:option:`CONFIG_LOG_PRINTK_MAX_STRING_LENGTH`: Maximal string length that can
|
||||
|
|
|
@ -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*/ \
|
||||
|
|
|
@ -183,6 +183,12 @@ config LOG_MAX_LEVEL
|
|||
- 3 INFO, maximal level set to LOG_LEVEL_INFO
|
||||
- 4 DEBUG, maximal level set to LOG_LEVEL_DBG
|
||||
|
||||
config LOG_FUNCTION_NAME
|
||||
bool "Prepend log message with function name"
|
||||
default y
|
||||
help
|
||||
Prepends log message with function name.
|
||||
|
||||
config LOG_PRINTK
|
||||
bool "Enable processing of printk messages."
|
||||
help
|
||||
|
|
|
@ -177,7 +177,9 @@ static int ids_print(struct log_msg *msg,
|
|||
total += print_formatted(log_output, "<%s> ", severity[level]);
|
||||
}
|
||||
|
||||
total += print_formatted(log_output, "%s: ",
|
||||
total += print_formatted(log_output,
|
||||
IS_ENABLED(CONFIG_LOG_FUNCTION_NAME) ?
|
||||
"%s." : "%s: ",
|
||||
log_source_name_get(domain_id, source_id));
|
||||
|
||||
return total;
|
||||
|
|
|
@ -12,3 +12,4 @@ CONFIG_LOG_STRDUP_MAX_STRING=8
|
|||
CONFIG_KERNEL_LOG_LEVEL_OFF=y
|
||||
CONFIG_SOC_LOG_LEVEL_OFF=y
|
||||
CONFIG_ARCH_LOG_LEVEL_OFF=y
|
||||
CONFIG_LOG_FUNCTION_NAME=n
|
||||
|
|
Loading…
Reference in a new issue