Skip to content

Commit 1abbdb6

Browse files
Damian-Nordicnordicjm
authored andcommitted
logging: rpc: filter out rpc logs for streaming only
The Logging over RPC backend would filter out logs generated by nRF RPC to avoid the log infinite loop. However, this is only necessary for log live-streaming but it is perfectly ok to include nRF RPC logs in the log history buffer. Signed-off-by: Damian Krolik <[email protected]>
1 parent 4b82c0e commit 1abbdb6

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

subsys/logging/log_backend_rpc.c

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,6 @@ static struct coredump_mem_region_node dump_region = {
9292
static const uint8_t CRASH_INFO_MAGIC[] = { 'D', 'U', 'M', 'P', 'I', 'N', 'F', 'O' };
9393
#endif
9494

95-
/*
96-
* Drop messages coming from nRF RPC to avoid the avalanche of logs:
97-
* 1. log added
98-
* 2. log sent over nRF RPC
99-
* 3. more logs generated by nRF RPC
100-
* 4. more logs sent over nRF RPC
101-
* ...
102-
*/
103-
static const char *const filtered_out_sources[] = {
104-
"nrf_rpc",
105-
"NRF_RPC",
106-
};
107-
10895
static const uint32_t common_output_flags =
10996
LOG_OUTPUT_FLAG_TIMESTAMP | LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP;
11097

@@ -539,28 +526,47 @@ static bool starts_with(const char *str, const char *prefix)
539526
return strncmp(str, prefix, strlen(prefix)) == 0;
540527
}
541528

542-
static void process(const struct log_backend *const backend, union log_msg_generic *msg_generic)
529+
static bool should_filter_out(struct log_msg *msg)
543530
{
544-
struct log_msg *msg = &msg_generic->log;
531+
/*
532+
* Drop messages coming from nRF RPC to avoid the log feedback loop:
533+
* 1. log added
534+
* 2. log sent over nRF RPC
535+
* 3. more logs generated by nRF RPC
536+
* 4. more logs sent over nRF RPC
537+
* ...
538+
*/
539+
static const char *const filtered_out_sources[] = {
540+
"nrf_rpc",
541+
"NRF_RPC",
542+
};
543+
545544
const char *source_name = log_msg_source_name_get(msg);
546-
enum log_rpc_level level = (enum log_rpc_level)log_msg_get_level(msg);
547-
enum log_rpc_level max_level;
548545

549546
if (source_name != NULL) {
550547
for (size_t i = 0; i < ARRAY_SIZE(filtered_out_sources); i++) {
551548
if (starts_with(source_name, filtered_out_sources[i])) {
552-
return;
549+
return true;
553550
}
554551
}
555552
}
556553

554+
return false;
555+
}
556+
557+
static void process(const struct log_backend *const backend, union log_msg_generic *msg_generic)
558+
{
559+
struct log_msg *msg = &msg_generic->log;
560+
enum log_rpc_level level = (enum log_rpc_level)log_msg_get_level(msg);
561+
enum log_rpc_level max_level;
562+
557563
if (panic_mode) {
558564
return;
559565
}
560566

561567
max_level = stream_level;
562568

563-
if (max_level != LOG_RPC_LEVEL_NONE && level <= max_level) {
569+
if (max_level != LOG_RPC_LEVEL_NONE && level <= max_level && !should_filter_out(msg)) {
564570
/*
565571
* The "max_level != LOG_RPC_LEVEL_NONE" condition seems redundant but is in fact
566572
* needed, because a log message can be generated with the level NONE, and such

0 commit comments

Comments
 (0)