Skip to main content

Crate consortium_log

Crate consortium_log 

Source
Expand description

A tiny logging facade that forwards to [defmt], [tracing], both, or neither, chosen by Cargo features.

Consortium spans no_std firmware (which logs with defmt) and std host-side tooling such as the config codegen (which logs with tracing). This crate lets a single call site — consortium_log::trace!(...) — compile against whichever backend the consuming crate turns on:

  • defmt routes each macro to the matching defmt macro.
  • tracing routes each macro to the matching tracing macro. tracing also enables alloc because the tracing dependency needs it.
  • With both enabled, every event is emitted to both backends.
  • With neither enabled, the macros expand to nothing.

§Format syntax

The portable subset is a format string plus positional arguments — trace!("channel {} lowered", name) — or Rust-style implicit captures — trace!("channel {name} lowered"). Implicit captures are normalized to indexed arguments before being forwarded, because defmt does not parse them itself. Each argument must implement the traits both backends require (defmt::Format for defmt, core::fmt::Display/Debug for tracing). Backend-specific extensions (defmt’s {=u8} type hints, tracing’s structured fields) are only valid when that backend is the sole one enabled.

Log arguments must be side-effect free: when no backend is enabled the macros expand to nothing and the arguments are never evaluated.

§Features

  • defmt — forward to the defmt logging macros. defmt’s proc-macros expand to literal defmt::… paths resolved at the call site, so a crate that enables this backend must also depend on defmt directly (the facade cannot supply the name). The workspace’s firmware crates already do.
  • tracing — forward to the tracing logging macros (implies alloc). tracing’s macros are $crate-hygienic, so no direct dependency is needed beyond this crate.
  • alloc — marker capability required by tracing; enabling it alone pulls no backend.

Macros§

debug
Logs at the debug level to every enabled backend.
error
Logs at the error level to every enabled backend.
info
Logs at the info level to every enabled backend.
trace
Logs at the trace level to every enabled backend. See the crate docs for the portable format syntax.
warn
Logs at the warn level to every enabled backend.