1.. _module-pw_log_zephyr: 2 3============= 4pw_log_zephyr 5============= 6.. pigweed-module:: 7 :name: pw_log_zephyr 8 9-------- 10Overview 11-------- 12This interrupt backend implements the ``pw_log`` facade. Currently, two 13separate Pigweed backends are implemented. One that uses the plain Zephyr 14logging framework and routes Pigweed's logs to Zephyr. While another maps 15the Zephyr logging macros to Pigweed's tokenized logging. 16 17Using Zephyr logging 18-------------------- 19To enable, set ``CONFIG_PIGWEED_LOG_ZEPHYR=y``. After that, logging can be 20controlled via the standard `Kconfig options`_. All logs made through 21`PW_LOG_*` are logged to the Zephyr logging module ``pigweed``. In this 22model, the Zephyr logging is set as ``pw_log``'s backend. 23 24Using Pigweed tokenized logging 25------------------------------- 26Using the pigweed logging can be done by enabling 27``CONFIG_PIGWEED_LOG_TOKENIZED=y``. At that point ``pw_log_tokenized`` is set 28as the backend for ``pw_log`` and all Zephyr logs are routed to Pigweed's 29logging facade. This means that any logging statements made in Zephyr itself 30are also tokenized. 31 32When enabled, a few extra configurations are available to control the tokenized 33metadata bits such as log level bits, line number bits, custom flag bits, and 34module string bits. 35The log format string may also be modified by defining your own ``PW_LOG_TOKENIZED_FORMAT_STRING``. 36This can be done in your cmake by including your own header that defines it. 37 38.. code-block:: 39 40 add_library(log_tokenized_config INTERFACE) 41 target_compile_options(log_tokenized_config INTERFACE -include header_file_that_sets_that_macro.h) 42 pw_set_module_config(pw_log_tokenized_CONFIG log_tokenized_config) 43 44Setting the log level 45--------------------- 46In order to remain compatible with existing Pigweed code, the logging backend 47respects ``PW_LOG_LEVEL``. If set, the backend will translate the Pigweed log 48levels to their closest Zephyr counterparts: 49 50+---------------------------+-------------------+ 51| Pigweed | Zephyr | 52+===========================+===================+ 53| ``PW_LOG_LEVEL_DEBUG`` | ``LOG_LEVEL_DBG`` | 54+---------------------------+-------------------+ 55| ``PW_LOG_LEVEL_INFO`` | ``LOG_LEVEL_INF`` | 56+---------------------------+-------------------+ 57| ``PW_LOG_LEVEL_WARN`` | ``LOG_LEVEL_WRN`` | 58+---------------------------+-------------------+ 59| ``PW_LOG_LEVEL_ERROR`` | ``LOG_LEVEL_ERR`` | 60| | | 61| ``PW_LOG_LEVEL_CRITICAL`` | | 62| | | 63| ``PW_LOG_LEVEL_FATAL`` | | 64+---------------------------+-------------------+ 65 66Alternatively, it is also possible to set the Zephyr logging level directly via 67``CONFIG_PIGWEED_LOG_LEVEL``. 68 69.. _`Kconfig options`: https://docs.zephyrproject.org/latest/reference/logging/index.html#global-kconfig-options 70