Commit 8dd9d924 authored by Yong Cong Sin's avatar Yong Cong Sin Committed by Benjamin Cabé
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
`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: default avatarYong Cong Sin <ycsin@meta.com>
Signed-off-by: default avatarYong Cong Sin <yongcong.sin@gmail.com>
parent 676c3d2d
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -330,8 +330,14 @@ static uint32_t z_log_init(bool blocking, bool can_sleep)

	int backend_index = 0;

	/* Activate autostart backends */
	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);

		/* Activate autostart backends */
		if (backend->autostart) {
			log_backend_init(backend);

+0 −6
Original line number Diff line number Diff line
@@ -560,12 +560,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);