Repository navigation
feat(core): the log_*! macros forward to defmt (#352, 2/3) - #359
Merged
Merged
Conversation
`log_trace!` … `log_error!` gain a third destination: `defmt`, under the calling crate's `defmt` feature, next to `tracing` and `log`. On an Embassy device every core log line now reaches the probe log (the session engine had none, #352). - `aimdb-core/src/log.rs`: a `::defmt::…!` arm per macro; the module docs give the rule: a crate forwarding `defmt` needs `dep:defmt` (defmt's macros expand to absolute `defmt::` paths, so a re-export would not help), its arguments implement `defmt::Format`, and a `std`-only crate names the feature through `check-cfg`. - `LogDisplay` / `LogDebug`: wrap a foreign type without `defmt::Format` in a log call (Display2Format / Debug2Format under defmt; tracing/log output unchanged). Used at ten call sites in the zenoh and MQTT std backends, whose `rumqttc`/zenoh types would otherwise break an all-features build (docs.rs builds both crates with `std` and `defmt` together). - `aimdb-knx-connector`: `dep:defmt`, and `defmt/ip_in_core` for `SocketAddr`. - `aimdb-zenoh-connector`: a `defmt` feature for its embedded build. - `aimdb-sync`, `aimdb-uds-connector` (std only): `check-cfg` for the name. - Makefile: thumbv7em check and clippy for `aimdb-core` with `defmt`, and for the zenoh embedded build with `defmt`. Part of #352. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YPDjQ947yKjLLAq3Xzgu3e
This was referenced Oct 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
PR 2 of 3 into
feat/352-log-defmtfor #352. Core'slog_*!macros get a third destination,defmt, next totracingandlog. On an Embassy device every core log line then reaches the probe log, including the session engine, which had nodefmtoutput at all.Changes
aimdb-core/src/log.rs: each macro gets a#[cfg(feature = "defmt")] ::defmt::…!($s, …)arm, and the no-op arm also coversdefmt. The format strings stay the same:defmtreads{}and{:?}alike, and PR 1 provided theFormatimpls. The module docs state the new rule:defmtneedsdep:defmt.defmt's macros expand to absolutedefmt::paths, so unliketracing/log, a re-export through$crate::__privatewouldn't help;defmt::Format;check-cfg.LogDisplay/LogDebug(new,aimdb_core::LogDisplay): wrappers for foreign types withoutFormatin a log call, e.g.log_warn!("… {}", LogDisplay(&e)). Underdefmtthey useDisplay2Format/Debug2Format, and thetracing/logoutput stays unchanged. Used at 10 places in the std backends of zenoh (native.rs,ros2.rs) and MQTT (native.rs). Theirrumqttc/zenoh types would otherwise break a build withstdanddefmttogether, and docs.rs builds both crates with all features.aimdb-knx-connector:dep:defmt, plusdefmt/ip_in_core(Formatforcore::net::SocketAddr).aimdb-zenoh-connector: a realdefmtfeature for its embedded build. It isn't std-only (it has an embedded build forthumbv7em), which my first inventory in [FEAT] Core log macros reach defmt: forward log_*! to defmt and drop the hand-written mirrors #352 missed.aimdb-sync,aimdb-uds-connector(truly std-only):[lints.rust] unexpected_cfgswithcheck-cfgfordefmt, following the existing pattern inaimdb-wasm-adapter. Without it,unexpected_cfgswould fire at every macro call, andmake clippywould fail.Makefile:thumbv7emcheck and clippy foraimdb-corewithdefmt(alloc,defmt,alloc,connector-session,remote,defmt), and for zenoh withembedded,defmt. Until now, core withdefmtwas only compiled indirectly through the serial connector.Verified locally
thumbv7emcheck/clippy lines for core, MQTT, KNX, serial, TCP and zenoh (including the new ones), plus tests and clippy for every crate touched. The only notice is Cargo's "patchembassy-net-driverwas not used" for zenoh's std tests, which comes from the workspace patch ([BUG] A plain git clone does not build: the workspace patch requires the _external/embassy submodule #341), not from this PR.cargo check/cargo doc -D warnings --all-featuresforaimdb-core,aimdb-zenoh-connector,aimdb-mqtt-connectorandaimdb-serial-connector: clean.aimdb-knx-connector --all-featuresalready fails without this PR (8 errors inaimdb-knx-pico 0.3.1,Backtrace), so it's unrelated to this change.Next: PR 3 removes the hand-written
defmtmirrors that the macros now cover (21 in MQTT, 5 in the Embassy adapter, 4 in core), and checks it live on the board.Related Issue
🤖 Generated with Claude Code
https://claude.ai/code/session_01YPDjQ947yKjLLAq3Xzgu3e