Skip to content

Commit

Permalink
logging: log_cmds: init uninitialized backend on log_go()
Browse files Browse the repository at this point in the history
For backends that do not autostart themselves, initialize
& enable them on `log backend <log_backend_*> go`, so
that they function properly.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
(cherry picked from commit f840a35)
  • Loading branch information
ycsin authored and mmahadevan108 committed Feb 20, 2025
1 parent ae73df5 commit a50476c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/zephyr/logging/log_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ struct log_backend_control_block {
void *ctx;
uint8_t id;
bool active;
bool initialized;

/* Initialization level. */
uint8_t level;
Expand Down Expand Up @@ -140,6 +141,7 @@ static inline void log_backend_init(const struct log_backend *const backend)
if (backend->api->init) {
backend->api->init(backend);
}
backend->cb->initialized = true;
}

/**
Expand Down
14 changes: 13 additions & 1 deletion subsys/logging/log_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,19 @@ static int log_go(const struct shell *sh,
char **argv)
{
if (backend || !IS_ENABLED(CONFIG_LOG_FRONTEND)) {
log_backend_activate(backend, backend->cb->ctx);
if (!backend->cb->initialized) {
log_backend_init(backend);
while (log_backend_is_ready(backend) != 0) {
if (IS_ENABLED(CONFIG_MULTITHREADING)) {
k_msleep(10);
}
}
if (log_backend_is_ready(backend) == 0) {
log_backend_enable(backend, backend->cb->ctx, CONFIG_LOG_MAX_LEVEL);
}
} else {
log_backend_activate(backend, backend->cb->ctx);
}
return 0;
}

Expand Down

0 comments on commit a50476c

Please sign in to comment.