Skip to content

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

Closed

Description

@lxsaah

Is your feature request related to a problem? Please describe.

On an Embassy device, core's own log lines never reach the probe log. aimdb-core/src/log.rs forwards the log_*! macros to tracing and log only. defmt was left out on purpose, because many call sites use {:?} on types that don't implement defmt::Format. Places that matter on a device mirror by hand instead (#[cfg(feature = "defmt")] defmt::warn!(…) next to the log_warn!).

That has two costs:

Describe the solution you'd like

log_trace! … log_error! also forward to defmt under core's defmt feature, as a third destination next to tracing and log. No new logging layer and no change to call sites' format strings.

A check against defmt 1.0.1 (thumbv7em, cargo check) shows that defmt accepts the existing syntax, including {:?} as a display hint, and with defmt's alloc feature it formats String and Vec<String>. So the work is in the argument types, not the call sites.

Scope (measured by parsing every macro call)

Crate log_*! calls including {:?} builds with defmt
aimdb-core 61 17 yes
aimdb-mqtt-connector 14 1 yes
aimdb-knx-connector 7 1 yes
aimdb-serial-connector 1 0 yes
aimdb-zenoh-connector, aimdb-sync, aimdb-uds-connector 31 1 no (std only, unaffected)

Plan: a short PR series, each reviewed separately.

  1. defmt::Format for logged argument types, under the defmt feature:
    • cfg_attr(feature = "defmt", derive(defmt::Format)) on TransportError, CodecError, AuthError, RpcError, the framer error in session/io.rs, and the error types logged by the MQTT and KNX connectors;
    • DbError gets a hand-written impl. Its std-only variants carry io::Error / serde_json::Error, which don't implement Format, and docs.rs builds with all-features = true (Cargo.toml:186), so std and defmt are on together there and a derive would break that build;
    • core's defmt feature enables defmt/alloc.
  2. The macro branch, plus CI: #[cfg(feature = "defmt")] defmt::…! in each log_*! macro, with the log.rs module docs updated. Direct thumbv7em checks with defmt for aimdb-core (alloc,connector-session,defmt), aimdb-mqtt-connector and aimdb-knx-connector. Today core with defmt is only compiled through the serial connector, so a missing Format impl would surface late.
  3. Remove the hand-written mirrors that the macros now cover (MQTT connector, Embassy adapter, core), keeping only those that log something the log_*! line doesn't.

Contract change: the macros are #[macro_export]ed. With defmt on, their arguments must implement defmt::Format. Normal (tracing/log) builds are unaffected. This needs a changelog entry.

On the device:

  • Format strings are interned, so they cost almost no flash.
  • debug/trace lines are filtered at compile time via DEFMT_LOG, so they cost nothing at the default info level.
  • Firmware built with DEFMT_LOG=debug will show about 60 more core lines than today.

Verification

Describe alternatives you've considered

  • Hand-written mirrors in the session engine only (the first plan for this issue): small, but it adds to the duplication above and leaves every other core log line invisible on devices.
  • Typed events (SessionEvent, …) instead of text: valuable beyond logging (tests, metrics, introspection), but a separate design question, tracked in its own issue. It doesn't depend on this one.

Additional context

🤖 Generated with Claude Code

Activity

  1. changed the title [-][FEAT] Session engine: mirror its operational events to defmt, as the router does[/-] [+][FEAT] Core log macros reach defmt: forward log_*! to defmt and drop the hand-written mirrors[/+] on Oct 24, 2026
  2. added 2 commits that reference this issue on Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions