From e64cd5c74d3ccbb1b660e374b70a8b13e917ea96 Mon Sep 17 00:00:00 2001 From: Krzysztof Chruscinski Date: Tue, 26 Feb 2019 14:33:47 +0100 Subject: [PATCH] logging: Fix silent logs dropping when LOG_MODE_OVERFLOW disabled There was no notification about dropped logs When logger operated in the mode where message is dropped when logger has no space to store the message. Notification was printed only if logger operated in the mode which overwrites oldest log. Signed-off-by: Krzysztof Chruscinski --- include/logging/log_core.h | 4 ++++ subsys/logging/log_core.c | 7 +++++-- subsys/logging/log_msg.c | 3 +++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/logging/log_core.h b/include/logging/log_core.h index 6e5d467de35..d690d767713 100644 --- a/include/logging/log_core.h +++ b/include/logging/log_core.h @@ -540,6 +540,10 @@ bool log_is_strdup(void *buf); */ void log_free(void *buf); +/** @brief Indicate to the log core that one log message has been dropped. + */ +void log_dropped(void); + #ifdef __cplusplus } #endif diff --git a/subsys/logging/log_core.c b/subsys/logging/log_core.c index 35a52630a75..07f314406e0 100644 --- a/subsys/logging/log_core.c +++ b/subsys/logging/log_core.c @@ -439,8 +439,6 @@ static void msg_process(struct log_msg *msg, bool bypass) log_backend_put(backend, msg); } } - } else { - atomic_inc(&dropped_cnt); } log_msg_put(msg); @@ -488,6 +486,11 @@ u32_t log_buffered_cnt(void) return buffered_cnt; } +void log_dropped(void) +{ + atomic_inc(&dropped_cnt); +} + u32_t log_src_cnt_get(u32_t domain_id) { return log_sources_count(); diff --git a/subsys/logging/log_msg.c b/subsys/logging/log_msg.c index 92e4a7225d3..21e4d45f857 100644 --- a/subsys/logging/log_msg.c +++ b/subsys/logging/log_msg.c @@ -74,10 +74,13 @@ union log_msg_chunk *log_msg_no_space_handle(void) if (IS_ENABLED(CONFIG_LOG_MODE_OVERFLOW)) { do { more = log_process(true); + log_dropped(); err = k_mem_slab_alloc(&log_msg_pool, (void **)&msg, K_NO_WAIT); } while ((err != 0) && more); + } else { + log_dropped(); } return msg;