zephyrproject-rtos / west

West, Zephyr's meta-tool
https://docs.zephyrproject.org/latest/guides/west/index.html
Apache License 2.0
215 stars 117 forks source link

log messages from west api modules are not being emitted as expected #665

Closed mbolivar-nordic closed 1 year ago

mbolivar-nordic commented 1 year ago

Commit https://github.com/zephyrproject-rtos/west/commit/92c18ac55acd631c11f9d4392556d3b7075a0bec did not achieve its purpose. We are loading the manifest long before we call the setup_logging() methods in each of the project.py classes, so any messages from the manifest class have long been discarded by the time that we enable them.

The 'west manifest' command happens to work because we deliberately load the manifest again.

This is wrong -- to reproduce, try adding a _logger.warning('test') line to Manifest.from_topdir, and observe that it is not emitted when you run west list manifest. The expected behavior would be that warnings and above are emitted by default, info and above emitted with west -v, debug and above with west -vv or higher.

Fixing this properly requires knowing the verbosity level before west loads the manifest. This in turn requires duplicating some work already done by argparse to handle the -v argument before we load the manifest itself. With that, we can decide what verbosity levels to apply to the west API's modules, and set up a common log handler and formatter for them. This in turn will make things work as expected for extension commands as well.