zephyr

Module logging

source
Expand description

Rust logging in Zephyr

There are a few config settings in Zephyr that affect how logging is done. Zephyr has multiple choices of front ends and backends for the logging. We try to work with a few of these.

There are various tradeoffs in terms of code size, and processing time that affect how logging is done. In addition to the tradeoffs in Zephyr, there are also tradeoffs in the Rust world, especially when it comes to formatting.

For now, any use of logging in Rust will go through the log crate. This brings in the overhead of string formatting. For the most part, due to a semantic mismatch between how Rust does string formatting, and how C does it, we will not defer logging, but generate log strings that will be sent as full strings to the Zephyr logging system.

  • CONFIG_LOG: Global enable of logging in Zephyr.
  • CONFIG_LOG_MODE_MINIMAL: Indicates a minimal printk type of logging.

At this time, we will provide two loggers. One is based on using the underlying printk mechanism, and if enabled, will send log messages directly to printk. This roughly corresponds to the minimal logging mode of Zephyr, but also works if logging is entirely disabled.

The other log backend uses the logging infrastructure to log simple messages to the C logger. At this time, these require allocation for the string formatting, although the allocation will generally be short lived. A good future task will be to make the string formatter format directly into the log buffer used by Zephyr.

Functions§

  • Set the log handler to log messages through printk in Zephyr.