xref: /aosp_15_r20/external/pigweed/pw_assert_log/docs.rst (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1*61c4878aSAndroid Build Coastguard Worker.. _module-pw_assert_log:
2*61c4878aSAndroid Build Coastguard Worker
3*61c4878aSAndroid Build Coastguard Worker=============
4*61c4878aSAndroid Build Coastguard Workerpw_assert_log
5*61c4878aSAndroid Build Coastguard Worker=============
6*61c4878aSAndroid Build Coastguard Worker
7*61c4878aSAndroid Build Coastguard Worker-----------------
8*61c4878aSAndroid Build Coastguard Workerpw_assert_BACKEND
9*61c4878aSAndroid Build Coastguard Worker-----------------
10*61c4878aSAndroid Build Coastguard WorkerThis assert backend implements the ``pw_assert:check`` facade, by routing the
11*61c4878aSAndroid Build Coastguard Worker``PW_CHECK()``/``PW_CRASH()`` macros into ``PW_LOG``  with the
12*61c4878aSAndroid Build Coastguard Worker``PW_LOG_LEVEL_FATAL`` log level. This is an easy way to tokenize your assert
13*61c4878aSAndroid Build Coastguard Workermessages, by using the ``pw_log_tokenized`` log backend for logging, then using
14*61c4878aSAndroid Build Coastguard Worker``pw_assert_log`` to route the tokenized messages into the tokenized log
15*61c4878aSAndroid Build Coastguard Workerhandler.
16*61c4878aSAndroid Build Coastguard Worker
17*61c4878aSAndroid Build Coastguard WorkerTo use this module:
18*61c4878aSAndroid Build Coastguard Worker
19*61c4878aSAndroid Build Coastguard Worker1. Set your assert backend: ``pw_assert_BACKEND = dir_pw_assert_log``
20*61c4878aSAndroid Build Coastguard Worker2. Ensure your logging backend knows how to handle the assert failure flag
21*61c4878aSAndroid Build Coastguard Worker
22*61c4878aSAndroid Build Coastguard Worker----------------------
23*61c4878aSAndroid Build Coastguard Workerpw_assert_LITE_BACKEND
24*61c4878aSAndroid Build Coastguard Worker----------------------
25*61c4878aSAndroid Build Coastguard WorkerThis assert backend implements the ``pw_assert:assert`` facade, by routing the
26*61c4878aSAndroid Build Coastguard Worker``PW_ASSERT()`` macros into ``PW_LOG`` with the ``PW_LOG_LEVEL_FATAL`` log
27*61c4878aSAndroid Build Coastguard Workerlevel. This is an easy way to forward your asserts to a native macro assert
28*61c4878aSAndroid Build Coastguard WorkerAPI if it is already constexpr safe such as on Android.
29*61c4878aSAndroid Build Coastguard Worker
30*61c4878aSAndroid Build Coastguard Worker.. warning::
31*61c4878aSAndroid Build Coastguard Worker   When building with Soong (using Android.bp), some Pigweed modules are listing
32*61c4878aSAndroid Build Coastguard Worker   `pw_log_null_headers` in their `header_lib` list. This means that the
33*61c4878aSAndroid Build Coastguard Worker   `PW_CHECK`, `PW_ASSERT`, and `PW_CRASH` macros that depend on logs are
34*61c4878aSAndroid Build Coastguard Worker   ignored. Make sure to use the correct log backend in your final target, such
35*61c4878aSAndroid Build Coastguard Worker   as the `pw_log_android` backend which supports crashing on
36*61c4878aSAndroid Build Coastguard Worker   `PW_LOG_LEVEL_FATAL`. See
37*61c4878aSAndroid Build Coastguard Worker   `b/324266698 <https://issues.pigweed.dev/324266698>`_.
38