Skip to content

feat(core): the log_*! macros forward to defmt (#352, 2/3) - #359

Merged
lxsaah merged 1 commit into
feat/352-log-defmtfrom
fix/352-macro-branch
Oct 24, 2026
Merged

lxsaah merged 1 commit into
feat/352-log-defmtfrom
fix/352-macro-branch

Conversation

@lxsaah

@lxsaah lxsaah commented Oct 24, 2026

Copy link
Copy Markdown
Member

Description

PR 2 of 3 into feat/352-log-defmt for #352. Core's log_*! macros get a third destination, defmt, next to tracing and log. On an Embassy device every core log line then reaches the probe log, including the session engine, which had no defmt output at all.

Changes

  • aimdb-core/src/log.rs: each macro gets a #[cfg(feature = "defmt")] ::defmt::…!($s, …) arm, and the no-op arm also covers defmt. The format strings stay the same: defmt reads {} and {:?} alike, and PR 1 provided the Format impls. The module docs state the new rule:
    • a crate that forwards defmt needs dep:defmt. defmt's macros expand to absolute defmt:: paths, so unlike tracing/log, a re-export through $crate::__private wouldn't help;
    • arguments implement defmt::Format;
    • a std-only crate names the feature via check-cfg.
  • LogDisplay / LogDebug (new, aimdb_core::LogDisplay): wrappers for foreign types without Format in a log call, e.g. log_warn!("… {}", LogDisplay(&e)). Under defmt they use Display2Format/Debug2Format, and the tracing/log output stays unchanged. Used at 10 places in the std backends of zenoh (native.rs, ros2.rs) and MQTT (native.rs). Their rumqttc/zenoh types would otherwise break a build with std and defmt together, and docs.rs builds both crates with all features.
  • aimdb-knx-connector: dep:defmt, plus defmt/ip_in_core (Format for core::net::SocketAddr).
  • aimdb-zenoh-connector: a real defmt feature for its embedded build. It isn't std-only (it has an embedded build for thumbv7em), 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_cfgs with check-cfg for defmt, following the existing pattern in aimdb-wasm-adapter. Without it, unexpected_cfgs would fire at every macro call, and make clippy would fail.
  • Makefile: thumbv7em check and clippy for aimdb-core with defmt (alloc,defmt, alloc,connector-session,remote,defmt), and for zenoh with embedded,defmt. Until now, core with defmt was only compiled indirectly through the serial connector.

Verified locally

  • 94 Makefile commands: all thumbv7em check/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 "patch embassy-net-driver was 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-features for aimdb-core, aimdb-zenoh-connector, aimdb-mqtt-connector and aimdb-serial-connector: clean.
  • aimdb-knx-connector --all-features already fails without this PR (8 errors in aimdb-knx-pico 0.3.1, Backtrace), so it's unrelated to this change.

Next: PR 3 removes the hand-written defmt mirrors 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

`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
@lxsaah
lxsaah merged commit 9b13304 into feat/352-log-defmt Oct 24, 2026
4 checks passed
@lxsaah
lxsaah deleted the fix/352-macro-branch branch October 24, 2026 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant