Skip to content

Commit 97976e7

Browse files
ycsinnashif
authored andcommitted
logging: init backend id regardless of autostart
The `id` is basically a compile-time constant. Setting it every time the backend is enabled is unnecessary. Instead, set it on `log_core_init()` regardless of whether or not it requires to be `autostart`ed. Fixes an issue where the `filter_get`/`filter_set` accessed the wrong index and displayed the wrong log level when user accesses the status of an uninitialized backend via: `log backend <uninitialized_backend> status`. Also fixes an issue when user tries to list the backends via: `log list_backends`, where all uninitialized backends will have ID = 0. This commit is a combination of 8dd9d92 & dd9fd7d. Signed-off-by: Yong Cong Sin <[email protected]> Signed-off-by: Yong Cong Sin <[email protected]>
1 parent e244450 commit 97976e7

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

subsys/logging/log_core.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,14 @@ void log_core_init(void)
286286
if (IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING)) {
287287
z_log_runtime_filters_init();
288288
}
289+
290+
STRUCT_SECTION_FOREACH(log_backend, backend) {
291+
uint32_t id;
292+
/* As first slot in filtering mask is reserved, backend ID has offset.*/
293+
id = LOG_FILTER_FIRST_BACKEND_SLOT_IDX;
294+
id += backend - log_backend_get(0);
295+
log_backend_id_set(backend, id);
296+
}
289297
}
290298

291299
static uint32_t activate_foreach_backend(uint32_t mask)

subsys/logging/log_mgmt.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -553,12 +553,6 @@ void log_backend_enable(struct log_backend const *const backend,
553553
void *ctx,
554554
uint32_t level)
555555
{
556-
/* As first slot in filtering mask is reserved, backend ID has offset.*/
557-
uint32_t id = LOG_FILTER_FIRST_BACKEND_SLOT_IDX;
558-
559-
id += backend - log_backend_get(0);
560-
561-
log_backend_id_set(backend, id);
562556
backend->cb->level = level;
563557
backend_filter_set(backend, level);
564558
log_backend_activate(backend, ctx);

0 commit comments

Comments
 (0)