Skip to content

Conversation

@ycsin
Copy link
Member

@ycsin ycsin commented Apr 30, 2025

Backport from #84955 + #87097

The fix in #84955 introduce a bug which is fixed later by #87097, this PR is a combination of both, so that it fixes things without introducing bugs

Fixes #84952


Test

west build -b qemu_riscv64 -p auto -t run zephyr/samples/hello_world -- -DCONFIG_LOG=y -DCONFIG_SHELL=y -DCONFIG_LOG_CMDS=y -DCONFIG_LOG_BACKEND_UART=y -DCONFIG_LOG_BACKEND_UART_AUTOSTART=n

Before the patch

Full console log
Hello World! qemu_riscv64/qemu_virt_riscv64


*** Booting Zephyr OS build v3.7.1-113-gcab2f9d27f3e ***
uart:~$ log list_backends
log_backend_uart
        - Status: disabled
        - ID: 0

shell_uart_backend
        - Status: enabled
        - ID: 2

uart:~$ log backend shell_uart_backend status
module_name                              | current | built-in 
----------------------------------------------------------
cbprintf_package                         | inf     | inf
getopt                                   | inf     | inf
log                                      | inf     | inf
log_mgmt                                 | inf     | inf
log_uart                                 | inf     | inf
mpu                                      | inf     | inf
os                                       | inf     | inf
shell.shell_uart                         | inf     | inf
shell_uart                               | inf     | inf
uart_ns16550                             | inf     | inf
uart:~$ log backend log_backend_uart status
Logs are halted!
module_name                              | current | built-in 
----------------------------------------------------------
cbprintf_package                         | inf     | inf
getopt                                   | inf     | inf
log                                      | inf     | inf
log_mgmt                                 | inf     | inf
log_uart                                 | inf     | inf
mpu                                      | inf     | inf
os                                       | inf     | inf
shell.shell_uart                         | inf     | inf
shell_uart                               | inf     | inf
uart_ns16550                             | inf     | inf
uart:~$ log backend shell_uart_backend enable wrn
uart:~$ log backend shell_uart_backend status
module_name                              | current | built-in 
----------------------------------------------------------
cbprintf_package                         | wrn     | inf
getopt                                   | wrn     | inf
log                                      | wrn     | inf
log_mgmt                                 | wrn     | inf
log_uart                                 | wrn     | inf
mpu                                      | wrn     | inf
os                                       | wrn     | inf
shell.shell_uart                         | wrn     | inf
shell_uart                               | wrn     | inf
uart_ns16550                             | wrn     | inf
uart:~$ log backend log_backend_uart status
Logs are halted!
module_name                              | current | built-in 
----------------------------------------------------------
cbprintf_package                         | wrn     | inf
getopt                                   | wrn     | inf
log                                      | wrn     | inf
log_mgmt                                 | wrn     | inf
log_uart                                 | wrn     | inf
mpu                                      | wrn     | inf
os                                       | wrn     | inf
shell.shell_uart                         | wrn     | inf
shell_uart                               | wrn     | inf
uart_ns16550                             | wrn     | inf
uart:~$ 

After the patch:

Hello World! qemu_riscv64/qemu_virt_riscv64


*** Booting Zephyr OS build v3.7.1-115-gd9d6b62c29d5 ***
uart:~$ log list_backends
log_backend_uart
        - Status: disabled
        - ID: 1

shell_uart_backend
        - Status: enabled
        - ID: 2

uart:~$ log backend shell_uart_backend status
module_name                              | current | built-in 
----------------------------------------------------------
cbprintf_package                         | inf     | inf
getopt                                   | inf     | inf
log                                      | inf     | inf
log_mgmt                                 | inf     | inf
log_uart                                 | inf     | inf
mpu                                      | inf     | inf
os                                       | inf     | inf
shell.shell_uart                         | inf     | inf
shell_uart                               | inf     | inf
uart_ns16550                             | inf     | inf
uart:~$ log backend log_backend_uart status
Logs are halted!
module_name                              | current | built-in 
----------------------------------------------------------
cbprintf_package                         | none    | inf
getopt                                   | none    | inf
log                                      | none    | inf
log_mgmt                                 | none    | inf
log_uart                                 | none    | inf
mpu                                      | none    | inf
os                                       | none    | inf
shell.shell_uart                         | none    | inf
shell_uart                               | none    | inf
uart_ns16550                             | none    | inf
uart:~$ log backend shell_uart_backend enable wrn
uart:~$ log backend shell_uart_backend status
module_name                              | current | built-in 
----------------------------------------------------------
cbprintf_package                         | wrn     | inf
getopt                                   | wrn     | inf
log                                      | wrn     | inf
log_mgmt                                 | wrn     | inf
log_uart                                 | wrn     | inf
mpu                                      | wrn     | inf
os                                       | wrn     | inf
shell.shell_uart                         | wrn     | inf
shell_uart                               | wrn     | inf
uart_ns16550                             | wrn     | inf
uart:~$ log backend log_backend_uart status
Logs are halted!
module_name                              | current | built-in 
----------------------------------------------------------
cbprintf_package                         | none    | inf
getopt                                   | none    | inf
log                                      | none    | inf
log_mgmt                                 | none    | inf
log_uart                                 | none    | inf
mpu                                      | none    | inf
os                                       | none    | inf
shell.shell_uart                         | none    | inf
shell_uart                               | none    | inf
uart_ns16550                             | none    | inf
uart:~$ 

@ycsin ycsin changed the base branch from main to v3.7-branch April 30, 2025 12:21
@ycsin ycsin marked this pull request as ready for review April 30, 2025 13:27
@ycsin ycsin added the Backport Backport PR and backport failure issues label Apr 30, 2025
@github-project-automation github-project-automation bot moved this to To do in Backports Apr 30, 2025
ycsin and others added 2 commits June 18, 2025 07:44
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 8dd9d92 & dd9fd7d.

Signed-off-by: Yong Cong Sin <[email protected]>
Signed-off-by: Yong Cong Sin <[email protected]>
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 <[email protected]>
Signed-off-by: Yong Cong Sin <[email protected]>
@nashif nashif force-pushed the pr/v3.7-branch-backport-85159 branch from d9d6b62 to 9e927fb Compare June 18, 2025 11:44
@sonarqubecloud
Copy link

@nashif nashif merged commit 7cfc153 into zephyrproject-rtos:v3.7-branch Jun 18, 2025
25 checks passed
@github-project-automation github-project-automation bot moved this from To do to Done in Backports Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Logging Backport Backport PR and backport failure issues

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

logging: log_cmds: backend ID is wrong for backend(s) that do not autostart

4 participants