zephyrproject-rtos/west

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

Open

#952 opened on May 20, 2026

View on GitHub
 (1 comment) (0 reactions) (0 assignees)Python (157 forks)auto 404
APIhelp wantedpriority: medium

Repository metrics

Stars
 (350 stars)
PR merge metrics
 (PR metrics pending)

Description

tl;dr: west should offer a convenient way to log from low-level functions and other "helpers" with neither:

  • a (long deprecated) west.log global
  • a WestCommand object

A long time ago, logging used a global west.log. Globals cause problems, so west.log (and other globals) were deprecated in #149.

Instead, 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 any handle to the top-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 https://github.com/zephyrproject-rtos/zephyr/pull/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 https://github.com/zephyrproject-rtos/zephyr/pull/109158 and https://github.com/zephyrproject-rtos/zephyr/pull/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 https://github.com/zephyrproject-rtos/zephyr/pull/109165 ?) in the official west documentation.

cc: @mbolivar

Contributor guide