Browse Source

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>
(cherry picked from commit 8dd9d924fe)
backport-84955-to-v3.7-branch
Yong Cong Sin 5 months ago committed by github-actions[bot]
parent
commit
ab9f628bc6
  1. 8
      subsys/logging/log_core.c
  2. 6
      subsys/logging/log_mgmt.c

8
subsys/logging/log_core.c

@ -328,8 +328,14 @@ static uint32_t z_log_init(bool blocking, bool can_sleep)
int backend_index = 0; int backend_index = 0;
/* Activate autostart backends */
STRUCT_SECTION_FOREACH(log_backend, backend) { 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) { if (backend->autostart) {
log_backend_init(backend); log_backend_init(backend);

6
subsys/logging/log_mgmt.c

@ -553,12 +553,6 @@ void log_backend_enable(struct log_backend const *const backend,
void *ctx, void *ctx,
uint32_t level) 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->cb->level = level;
backend_filter_set(backend, level); backend_filter_set(backend, level);
log_backend_activate(backend, ctx); log_backend_activate(backend, ctx);

Loading…
Cancel
Save