Skip to content
Permalink
Browse files

logging: Ensure constant side effects of log API

When log API is used it should give the same side effect when enabled
or disabled e.g. LOG_INF(%d,cnt++) should always increment cnt.
Before this change cnt would be incremented twice when log enabled
and never incremented when log was disabled.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
  • Loading branch information...
nordic-krch authored and nashif committed Jul 11, 2018
1 parent d731e53 commit 77b44df86a21a4a68923e576c483321243725c17
Showing with 17 additions and 12 deletions.
  1. +17 −12 include/logging/log_core.h
@@ -166,18 +166,23 @@ extern "C" {
/******************************************************************************/
/****************** Macros for standard logging *******************************/
/******************************************************************************/
#define __LOG(_level, _id, _filter, ...) \
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_printf_arg_checker(__VA_ARGS__); \
__LOG_INTERNAL(src_level, __VA_ARGS__); \
} \
#define __LOG(_level, _id, _filter, ...) \
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_INTERNAL(src_level, __VA_ARGS__); \
} else { \
/* arg checker evaluated when log is filtered out \
* to ensure that __VA_ARGS__ are evaluated only \
* once giving always same side effects. \
*/ \
log_printf_arg_checker(__VA_ARGS__); \
} \
} while (0)

#define _LOG(_level, ...) \

0 comments on commit 77b44df

Please sign in to comment.
You can’t perform that action at this time.