Skip to main content

Module macros

Module macros 

Source
Expand description

Phase 88.2 — the emission macros.

Each macro formats its arguments into a stack-resident crate::FormatBuffer (capacity picked at compile time by the buffer-size-<N> feature), wraps the result in a crate::Record, and hands it to the crate::Logger’s dispatcher.

Compile-time ceiling: macros below severity_enabled_at_compile_time expand to () — the format call is dead-code-eliminated.

§Naming (RFC-0089, settled 2026-09-04)

The three ROS 2 client libraries disagree with each other about how to spell a log line:

rclrs    log_info!(logger, "…")        <- Rust follows THIS
rclcpp   RCLCPP_INFO(logger, "…")
rcutils  RCUTILS_LOG_INFO_NAMED(…)

There is no single “ROS 2 spelling”, so each of our languages follows ITS OWN upstream. For Rust that is rclrs, and rclrs’s five severity macros are log_debug!, log_info!, log_warn!, log_error! and log_fatal! — which is what this module now exports. (They carry an explicit target because #[macro_export] puts a macro at the CRATE ROOT, not in the module whose file declares it.) The pre-rename nros_debug! .. nros_fatal! forwarders, and the deprecate-legacy-names feature that armed their #[deprecated], were removed in phase-417 W-B5 once every in-tree call site had moved. There is no log_trace!: see below.

A name takes rclrs’s spelling exactly when rclrs HAS that name. Two families deliberately keep the nros_ prefix, because inventing a name inside rclrs’s namespace-alike would claim an upstream twin that does not exist:

  • nros_trace! — rclrs stops at debug. TRACE is ours (ledger rust:nros_trace, verdict extension), so it keeps a name that says so.
  • the nros_*_throttle! / nros_*_throttle_at! family — a macro per severity, which predates the modifier form below. rclrs has no such names.

The first argument is rclrs’s ToLogParams (phase-515 R3), so rclrs’s modifiers chain off the logger: log_info!(logger.once(), …), .skip_first(), .only_if(b), and — with the platform clock — .throttle(d). A plain &Logger is still the common case. See crate::log_params for the bounds.