Skip to content

HOWTO use west logging without a WestCommand object (and without the deprecated west.log global) #952

Description

@marc-hb

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#109158 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.

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.

cc: @mbolivar

Activity

  1. added
    enhancementNew feature or request. Use "Type" and not this label for issues.
    help wantedImplementation help is requested
    APIwest's library APIs
    on May 20, 2026
  2. marc-hb commented on May 22, 2026

    @marc-hb
    CollaboratorAuthor

    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)

  3. 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
  4. 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
  5. removed
    enhancementNew feature or request. Use "Type" and not this label for issues.
    on Jun 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions