02 Logging
Link to Source: samples/02_logging
Overview
This sample demonstrates the use of Zephyr’s logging subsystem. It shows how to use different log levels and print various data types to the console.
This sample is useful for:
Understanding log levels (ERR, WRN, INF, DBG)
Setting log level via Kconfig
Learning about logging backends
Observing that DBG messages include function names
Key Features:
Demonstrates printk() vs logging macros
Shows different data types (integers, strings, pointers)
Includes hexdump functionality
Building
This application can be built and executed on native_sim as follows:
host:~$ west build -b native_sim samples/02_logging -p
host:~$ west build -t run
To build for a real board (e.g., reel_board@2), use:
host:~$ west build -b reel_board@2 samples/02_logging -p
host:~$ west flash
Sample Output
*** Booting Zephyr OS build v4.3.0 ***
Hello World! native_sim
[00:00:00.001,691] <err> logging_sample: error string
[00:00:00.001,843] <dbg> logging_sample: main: debug string
[00:00:00.001,859] <inf> logging_sample: info string
[00:00:00.001,874] <dbg> logging_sample: main: int8_t 1, uint8_t 2
[00:00:00.001,887] <dbg> logging_sample: main: int16_t 16, uint16_t 17
[00:00:00.001,899] <dbg> logging_sample: main: int32_t 32, uint32_t 33
[00:00:00.001,921] <dbg> logging_sample: main: int64_t 64, uint64_t 65
[00:00:00.001,956] <dbg> logging_sample: main: char !
[00:00:00.002,383] <dbg> logging_sample: main: s str static str c str
[00:00:00.002,567] <dbg> logging_sample: main: d str dynamic str
[00:00:00.002,607] <dbg> logging_sample: main: mixed str dynamic str --- ...
[00:00:00.002,640] <dbg> logging_sample: main: mixed c/s ! static str ...
[00:00:00.002,653] <dbg> logging_sample: main: pointer 0x5c3e
[00:00:00.002,674] <dbg> logging_sample: main: HeXdUmP!
48 45 58 44 55 4d 50 21 20 23 40 |HEXDUMP! #@
Exit native_sim by pressing CTRL+C.