Skip to content

Commit 8dd9d92

Browse files
ycsinkartben
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 `z_log_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. Signed-off-by: Yong Cong Sin <ycsin@meta.com> Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
1 parent 676c3d2 commit 8dd9d92

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

subsys/logging/log_core.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,14 @@ static uint32_t z_log_init(bool blocking, bool can_sleep)
330330

331331
int backend_index = 0;
332332

333-
/* Activate autostart backends */
334333
STRUCT_SECTION_FOREACH(log_backend, backend) {
334+
uint32_t id;
335+
/* As first slot in filtering mask is reserved, backend ID has offset.*/
336+
id = LOG_FILTER_FIRST_BACKEND_SLOT_IDX;
337+
id += backend - log_backend_get(0);
338+
log_backend_id_set(backend, id);
339+
340+
/* Activate autostart backends */
335341
if (backend->autostart) {
336342
log_backend_init(backend);
337343

subsys/logging/log_mgmt.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -560,12 +560,6 @@ void log_backend_enable(struct log_backend const *const backend,
560560
void *ctx,
561561
uint32_t level)
562562
{
563-
/* As first slot in filtering mask is reserved, backend ID has offset.*/
564-
uint32_t id = LOG_FILTER_FIRST_BACKEND_SLOT_IDX;
565-
566-
id += backend - log_backend_get(0);
567-
568-
log_backend_id_set(backend, id);
569563
backend->cb->level = level;
570564
backend_filter_set(backend, level);
571565
log_backend_activate(backend, ctx);

0 commit comments

Comments
 (0)