defmt is an efficient, deferred-formatting logging framework for embedded systems written in Rust, aimed at firmware developers building for resource-constrained devices such as microcontrollers.
What it is
defmt ("de format", short for "deferred formatting") is a logging framework for embedded Rust that targets resource-constrained devices, with the formatting work deferred rather than performed on the microcontroller. It lives in the Rust embedded ecosystem and forms part of the Knurling project, which is Ferrous Systems' effort at improving tooling used to develop for embedded systems.
The concrete problem it solves is the cost of formatting log messages on the target. Instead of building formatted strings on a device with limited CPU and memory, defmt ships compact encoded frames off the device and decodes them on the host. The repository provides both halves of that pipeline: on-target crates such as defmt, defmt-rtt, defmt-itm, and defmt-semihosting, and host-side components such as defmt-decoder, defmt-parser, and defmt-print, a CLI utility for decoding and printing defmt encoded logs to standard out. What it replaces is the on-target string formatting that conventional embedded logging performs before transmitting output.
Key capabilities
- Deferred formatting: log data is encoded on the target and formatted on the host, which suits microcontrollers with tight resource budgets.
- Multiple on-target transports in one repository:
defmt-rtt sends logs over RTT, defmt-itm sends them over ITM, and defmt-semihosting uses semihosting.
panic-probe, an on-target library that routes panic! output through defmt.
defmt-test and defmt-test-macros, a framework with proc macros for running tests on-target.
defmt-print, a CLI utility for decoding and printing defmt encoded logs to standard out.
defmt-decoder and defmt-parser, host libraries for decoding and parsing defmt log frames.
defmt-json-schema, which describes the JSON emitted by defmt-decoder, giving machine-readable decoder output.
- Proc macros in
defmt-macros back the on-target logging code.
Who uses it and how
- Firmware teams writing Rust for microcontrollers that cannot absorb the cost of on-target string formatting.
- Developers using probe-based debug transports, choosing
defmt-rtt, defmt-itm, or defmt-semihosting to match hardware.
- Teams running tests against emulated hardware: the repository's own tests use
cargo xtask test-all, and some tests such as test-snapshot need qemu-system-arm installed and on $PATH.
- Engineers wanting log output in structured form downstream, via the JSON emitted by
defmt-decoder and described by defmt-json-schema.
- Projects that want panic output and on-target tests covered by the same logging framework, through
panic-probe and defmt-test.
Getting started
The README excerpt does not name a single install command; consumption is through the defmt crate for on-target code plus a transport crate such as defmt-rtt, defmt-itm, or defmt-semihosting, with the book at https://defmt.ferrous-systems.com/ holding the framework details. Tooling in the repository runs through cargo xtask, an alias defined in .cargo/config.toml for cargo run --package xtask --.
How it compares
The provided facts name no paid products this project replaces and no similar tools in this registry, so defmt stands alone here among the listed entries.
When to use it — and when not to
A self-hoster must operate a Rust embedded toolchain and a working host-side decoder, plus the debug transport the chosen crate expects, and must respect the version floors: Rust 1.76 or Ferrocene 24.05 for crates that cross-compile to the microcontroller, and Rust 1.83 for all host-side crates. It is a poor fit for teams outside the Rust embedded ecosystem, or for hosted or server-side logging where ordinary formatting costs nothing. The project also carries 117 open issues and a README excerpt that is terse about installation, so prospective users should expect to learn from the book and the source rather than from a quick-start section.
project readme (upstream, from github) — read inline
defmt
defmt ("de format", short for "deferred formatting") is a highly efficient logging framework that targets resource-constrained devices, like microcontrollers.
For more details about the framework check the book at .
Components
This repository contains the following packages:
MSRV
The minimum supported Rust version is 1.76 (or Ferrocene 24.05) for the crates that cross-compile to your microcontroller. The minimum supported Rust version is 1.83 for all host-side crates.
The defmt crates are tested against the latest stable Rust version and the MSRV.
Developer Information
Running Tests
Tests are run using cargo xtask -- although this is simply an alias (defined in .cargo/config.toml) for cargo run --package xtask --.
To see a list of options, see xtask/src/main.rs, or run:
cargo xtask help
For example, to run all the tests, run:
cargo xtask test-all
You will need qemu-system-arm installed and in your $PATH for some of the tests (e.g. test-snapshot).
Support
defmt is part of the Knurling project, Ferrous Systems' effort at
improving tooling used to develop for embedded systems.
If you think that our work is useful, consider sponsoring it via GitHub
Sponsors.
License
Licensed under either of
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
licensed as above, without any additional terms or conditions.