You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
HOWTO use west logging without a WestCommand object (and without the deprecated west.log global) #952
tl;dr: west should offer and document a convenient and standardized approach to log from low-level functions and other "helpers" with neither:
a (long deprecated) west.log global
a WestCommand object - because there isn't always one around.
A long time ago, logging used a global west.log. Globals cause problems, so west.log (and other globals) were deprecated in #149. More logging archeology in this comment:
As a replacement and fix, each WestCommand had logging methods for years.
This has worked well... when you have a WestCommand around! But low-level "helpers" used by some west commands and west extensions generally don't need and don't have any pointer to the higher level WestCommand that very indirectly invoked them. Which is why Zephyr extensions have kept using the global west.log in many places for so long (in addition to the newer WestCommand logging methods in other places: wherever the migration was trivial)
Depending on your PYTHONWARNINGS variable and other python settings, using the global west.logcan result in massive "DEPRECATED!" spam.
In zephyrproject-rtos/zephyr#97228, decsny tried to address this by passing a WestCommand object to basically every helper that does not otherwise need it. I was not a fan. A couple other ideas were thrown there.
In the much newer zephyrproject-rtos/zephyr#109158zephyrproject-rtos/zephyr#109165 and , @pdgendt had what looks (to me) like a much better idea: leveraging the flexibility of Python's logging module and more precisely its ability to forward logs to a custom logging.Handler object - which happens to point at a WestCommand that created it. The forwarding/"bridge" is name-based/string-based.
Unless someone has an even better idea, west should make that technique easier. If nothing else, by at least providing sample code (based on zephyrproject-rtos/zephyr#109165 ?) in the official west documentation.
In the much newer zephyrproject-rtos/zephyr#109158 and zephyrproject-rtos/zephyr#109165 and , @pdgendt had what looks (to me) like a much better idea: leveraging the flexibility of Python's logging module and more precisely its ability to forward logs to a custom logging.Handler object - which happens to point at a WestCommand that created it. The forwarding/"bridge" is name-based/string-based.
After taking a closer look at these I've now just realized that this "new" idea from @pdgendt is actually building on top of a 2019 change from @mbolivar, part of the bigger de-westization PR zephyrproject-rtos/zephyr#16871
I've had some requests to be able to use code in the runners package
without having west installed.
It turns out to be pretty easy to make this happen, as west is
currently only used for west.log and some trivial helper methods:
- To replace west log, use the standard logging module
- Add an appropriate handler for each runner's logger in
run_common.py which delegates to west.log, to keep
output working as expected.
In that 2019 time, this added indirection was forwarding standard Python logging to the (now deprecated) global west.log. So this indirection is not really new; only its destination and its generalization are. Credit where credit is due :-)
September 2026 EDIT: that same indirection logic was also used in west itself, see 2020 commit 71aaf57 and #999 (comment)
changed the title [-]Use west logging without a west command object (and without the deprecated west.log global)[/-][+]HOWTO use west logging without a west command object (and without the deprecated west.log global)[/+]on May 24, 2026
changed the title [-]HOWTO use west logging without a west command object (and without the deprecated west.log global)[/-][+]HOWTO use west logging without a WestCommand object (and without the deprecated west.log global)[/+]on May 24, 2026
Activity
marc-hb commentedon May 22, 2026
After taking a closer look at these I've now just realized that this "new" idea from @pdgendt is actually building on top of a 2019 change from @mbolivar, part of the bigger de-westization PR zephyrproject-rtos/zephyr#16871
In that 2019 time, this added indirection was forwarding standard Python
loggingto the (now deprecated) globalwest.log. So this indirection is not really new; only its destination and its generalization are. Credit where credit is due :-)September 2026 EDIT: that same indirection logic was also used in
westitself, see 2020 commit 71aaf57 and #999 (comment)[-]Use west logging without a west command object (and without the deprecated west.log global)[/-][+]HOWTO use west logging without a west command object (and without the deprecated west.log global)[/+][-]HOWTO use west logging without a west command object (and without the deprecated west.log global)[/-][+]HOWTO use west logging without a WestCommand object (and without the deprecated west.log global)[/+]scripts: west_commands: allow several forward_logging_to_west() handlers
scripts: west_commands: allow several forward_logging_to_west() handlers
scripts: west_commands: allow several forward_logging_to_west() handlers
scripts: west_commands: allow several forward_logging_to_west() handlers
scripts: west_commands: allow several forward_logging_to_west() handlers
scripts: west_commands: allow several forward_logging_to_west() handlers