Commit 97976e74 authored by Yong Cong Sin's avatar Yong Cong Sin Committed by Anas Nashif
Browse files

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 8dd9d924 & dd9fd7d.

Signed-off-by: default avatarYong Cong Sin <ycsin@meta.com>
Signed-off-by: default avatarYong Cong Sin <yongcong.sin@gmail.com>
parent e2444509
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -286,6 +286,14 @@ void log_core_init(void)
	if (IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING)) {
		z_log_runtime_filters_init();
	}

	STRUCT_SECTION_FOREACH(log_backend, backend) {
		uint32_t id;
		/* As first slot in filtering mask is reserved, backend ID has offset.*/
		id = LOG_FILTER_FIRST_BACKEND_SLOT_IDX;
		id += backend - log_backend_get(0);
		log_backend_id_set(backend, id);
	}
}

static uint32_t activate_foreach_backend(uint32_t mask)
+0 −6
Original line number Diff line number Diff line
@@ -553,12 +553,6 @@ void log_backend_enable(struct log_backend const *const backend,
			void *ctx,
			uint32_t level)
{
	/* As first slot in filtering mask is reserved, backend ID has offset.*/
	uint32_t id = LOG_FILTER_FIRST_BACKEND_SLOT_IDX;

	id += backend - log_backend_get(0);

	log_backend_id_set(backend, id);
	backend->cb->level = level;
	backend_filter_set(backend, level);
	log_backend_activate(backend, ctx);