defmt (deferred formatting) solves a real problem: log strings are expensive. Formatting "CAN frame received: id=0x{:x} len={}" at runtime on a microcontroller requires string processing, stack allocation, and UART transmission — all with measurable latency.

defmt moves the formatting to the host. On the target, only an integer index (identifying the format string) and the raw argument values are transmitted over RTT. On the host, probe-rs / defmt-print looks up the index in the firmware's ELF debug info and formats the string.

use defmt::info;

info!("CAN frame received: id={:#x} len={}", frame.id(), frame.dlc());
// Target transmits: [index: u8] [id: u32] [len: u8] = ~6 bytes
// Host formats the complete string from ELF

Total overhead on target: one RTT write of ~6 bytes. Compare to UART-based logging: potentially hundreds of bytes of formatted string, blocking UART transmission.

Levels: trace!, debug!, info!, warn!, error! compile out at zero cost when the level is disabled — via a build-time DEFMT_LOG environment variable.

panic handler: defmt-rtt provides a panic handler that logs the panic message via RTT before halting. Combined with probe-rs, you see the panic in your terminal with full source location. Essential for debugging.