Skip to content

feat(core): core log lines reach defmt (#352) - #361

Merged
lxsaah merged 4 commits into
mainfrom
feat/352-log-defmt
Oct 24, 2026
Merged

lxsaah merged 4 commits into
mainfrom
feat/352-log-defmt

Conversation

@lxsaah

@lxsaah lxsaah commented Oct 24, 2026

Copy link
Copy Markdown
Member

Description

Fixes #352: on an Embassy device, core's own log lines never reached the probe log. aimdb-core/src/log.rs forwarded log_*! only to tracing and log, and the places that mattered on the device mirrored to defmt by hand. The session engine had no mirrors at all, so the session reset (#328) and serve's accept-failure summary (#351) could only be inferred from their effect while testing on the board.

This merges the feature branch feat/352-log-defmt. Each step was reviewed as its own PR into that branch:

PR What
#358 defmt::Format for every type core's log lines format: derived for TransportError, CodecError, AuthError, FrameFault; DbError and SerializeFailure through their Display text (DbError's std variants carry io::Error, and docs.rs builds with every feature on); defmt/alloc for String/Vec<String>/Arc<str>; a compile-time guard
#359 The defmt arm in the five log_*! macros; LogDisplay/LogDebug for foreign types (10 call sites in the zenoh and MQTT std backends, so std + defmt builds stay green); KNX dep:defmt + ip_in_core; zenoh gets a defmt feature; check-cfg in the std-only aimdb-sync/aimdb-uds-connector; thumbv7em checks for core and zenoh with defmt in the Makefile
#360 Drops the 7 hand-written defmt mirrors that now duplicated a log_*! line (core router 3, session client 1, MQTT embedded 3). The defmt-only lines without a log_*! counterpart stay
docs Changelogs: aimdb-core, aimdb-zenoh-connector, aimdb-knx-connector, aimdb-mqtt-connector, root

How the scope was found

I temporarily added the defmt arm to the macros and built every crate that can build with defmt for thumbv7em. The compiler listed every missing piece: the Format impls, defmt/alloc, KNX's direct dependency and SocketAddr. The --all-features builds then showed the foreign types in zenoh's and MQTT's std backends. A check against defmt 1.0.1 confirmed that defmt accepts the existing format strings, including {:?}, so no call site's text changed.

Contract change

The macros are #[macro_export]ed:

  • a crate forwarding defmt needs dep:defmt itself, because defmt's macros expand to absolute paths;
  • every argument must implement defmt::Format, or be wrapped in LogDisplay/LogDebug;
  • a crate that never builds with defmt names the feature via check-cfg.

Normal (tracing/log) builds are unaffected. Details are in log.rs and the changelog.

Live on a NUCLEO-H563ZI

The device's defmt log now shows (with a temporary TCP server on port 0 and a record without a free slot):

ERROR accept failed: Io; retrying, further failures are summarized
WARN  accept still failing: 10 / 100 / 10000 / 100000 attempts in a row, last: Io
INFO  new handshake on a live connection: ending 1 subscription(s) of the previous client
WARN  subscription 2 ended: its source closed

The summary at 1,000 attempts didn't appear in that run. The logic is unit-tested (#351); the likely cause is defmt-rtt dropping lines when its buffer fills during the startup burst.

Verified locally

  • All Makefile tests and clippy for the affected crates, and every thumbv7em check/clippy line for core, MQTT, KNX, serial, TCP and zenoh, including the new defmt lines.
  • cargo check/cargo doc -D warnings --all-features for core, zenoh, MQTT and serial.
  • aimdb-knx-connector --all-features already failed before this branch (in aimdb-knx-pico 0.3.1), so it's unrelated.
  • This is the first full CI run over [FEAT] Core log macros reach defmt: forward log_*! to defmt and drop the hand-written mirrors #352: the PRs into the feature branch don't trigger CI.

Follow-up

#357: typed operational events (design), with the session engine as a pilot.

Related Issue

Checklist

  • I have read the CONTRIBUTING.md document.
  • My code follows the project's coding standards.
  • I have added tests to cover my changes. (A compile-time Format guard, and thumbv7em defmt checks in the Makefile.)
  • All new and existing tests passed (make check). The affected crates pass locally; the full run is left to CI.
  • I have updated the documentation accordingly.

🤖 Generated with Claude Code

https://claude.ai/code/session_01YPDjQ947yKjLLAq3Xzgu3e

lxsaah and others added 4 commits October 24, 2026 21:07
`aimdb-core` (log macros forward to defmt, `LogDisplay`/`LogDebug`, the
`defmt::Format` impls, the macro contract and the dropped mirrors),
`aimdb-zenoh-connector` (defmt feature), `aimdb-knx-connector` (direct defmt
dependency, `ip_in_core`), `aimdb-mqtt-connector` (no duplicate defmt lines),
and the root changelog.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YPDjQ947yKjLLAq3Xzgu3e
@lxsaah
lxsaah merged commit d45fa78 into main Oct 24, 2026
12 checks passed
@lxsaah
lxsaah deleted the feat/352-log-defmt branch October 24, 2026 20:16
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.

[FEAT] Core log macros reach defmt: forward log_*! to defmt and drop the hand-written mirrors

1 participant