Skip to main content

Crate nros_log

Crate nros_log 

Source
Expand description

Phase 88 — portable leveled-logging facade for nano-ros.

See docs/roadmap/archived/phase-88-nros-log.md for the design and acceptance criteria.

§Layering

  • This crate carries only the portable types + dispatcher + macros + PlatformSink. No backend code.
  • Per-platform log delivery is the responsibility of each nros-platform-<rtos> crate, exposing nros_platform_log_write / nros_platform_log_flush via the nros_platform_* ABI (header at packages/platform/nros-platform-api/include/nros/platform.h).
  • PlatformSink is the bridge: a single LogSink impl that forwards to the ABI. Apps that want fan-out (e.g. Platform + /rosout) compose a &'static [&dyn LogSink] manually and pass it to init.

§Quick start

ⓘ
use nros_log::{Logger, Severity};
use nros_log::{log_info, log_warn};

static LOGGER: Logger = Logger::new("my_node");

fn main() {
    nros_log::register_logger(&LOGGER);
    nros_log::init(nros_log::sinks::default());
    log_info!(&LOGGER, "started; domain = {}", 42);
}

Re-exports§

pub use pool::MAX_LOGGER_NAME_LEN;
pub use pool::dynamic_logger_capacity;
pub use pool::dynamic_logger_name_arena;
pub use pool::dynamic_loggers_in_use;
pub use throttle::ThrottleState;
pub use throttle::interval_ms_to_ns;
pub use throttle::throttle_decide;

Modules§

early
Records raised before any sink was installed.
macros
Phase 88.2 — the emission macros.
pool
phase-417 W4.d — bounded storage so get_or_create_logger can hand out a logger for a name nobody registered at compile time.
sinks
Sinks the FACADE itself can offer.
throttle
phase-417 W4.d — rate-limited logging, on the Logger everything else uses.

Macros§

log
Emit one record at a severity chosen at RUNTIME — rclrs’s log!.
log_debug
Emit at crate::Severity::Debug.
log_error
Emit at crate::Severity::Error.
log_fatal
Emit at crate::Severity::Fatal.
log_info
Emit at crate::Severity::Info.
log_warn
Emit at crate::Severity::Warn.
nros_debug_throttle
Emit at crate::Severity::Debug, at most once per interval_ms at this call site.
nros_debug_throttle_at
Emit at crate::Severity::Debug, at most once per interval_ms at this call site, measured against the now_ns the CALLER supplies.
nros_error_throttle
Emit at crate::Severity::Error, at most once per interval_ms at this call site.
nros_error_throttle_at
Emit at crate::Severity::Error, at most once per interval_ms at this call site, measured against the now_ns the CALLER supplies.
nros_fatal_throttle
Emit at crate::Severity::Fatal, at most once per interval_ms at this call site.
nros_fatal_throttle_at
Emit at crate::Severity::Fatal, at most once per interval_ms at this call site, measured against the now_ns the CALLER supplies.
nros_info_throttle
Emit at crate::Severity::Info, at most once per interval_ms at this call site.
nros_info_throttle_at
Emit at crate::Severity::Info, at most once per interval_ms at this call site, measured against the now_ns the CALLER supplies.
nros_trace
Emit at crate::Severity::Trace.
nros_trace_throttle
Emit at crate::Severity::Trace, at most once per interval_ms at this call site.
nros_trace_throttle_at
Emit at crate::Severity::Trace, at most once per interval_ms at this call site, measured against the now_ns the CALLER supplies.
nros_warn_throttle
Emit at crate::Severity::Warn, at most once per interval_ms at this call site.
nros_warn_throttle_at
Emit at crate::Severity::Warn, at most once per interval_ms at this call site, measured against the now_ns the CALLER supplies.

Structs§

FormatBuffer
Stack-resident UTF-8 buffer for one log record’s formatted body.
Logger
A named logger with a runtime severity threshold.
Record
One log entry, handed to each LogSink.

Enums§

ChildError
Why Logger::create_child made no child — RFC-0102 D1.
Severity
REP-2012 severity levels: rcutils’s five, in rcutils’s order, plus Trace.

Constants§

MAX_ADDED_SINKS
How many sinks add_sink can append on top of the init list.
MAX_LOGGERS
Maximum number of named loggers that can be registered via register_logger. Beyond this, get_logger returns DEFAULT_LOGGER.

Statics§

DEFAULT_LOGGER
Catch-all logger returned when the requested name is not registered (or the intern table is full).

Traits§

LogSink
Backend a log record is delivered to.

Functions§

add_sink
Append sink to the sinks every record is delivered to.
added_sink_count
How many sinks add_sink has installed.
flush
Flush every registered sink, appended ones included.
format_buffer_capacity
Returns the configured capacity in bytes.
get_logger
Look up a registered logger by name. Returns DEFAULT_LOGGER if none is registered (call register_logger for a 'static Logger to publish one).
get_or_create_logger
Look up a logger by name, CREATING one if the name is new.
init
Install the global sink list.
register_logger
Publish logger under its name so subsequent get_logger calls with that name return THIS reference.
resolve_logger
Resolve name to a logger — the TOTAL form of get_or_create_logger, and the one spelling every node-shaped accessor uses.
resolve_node_logger
resolve_logger for a NODE’s own logger, marking it as one — the one spelling the node-shaped accessors use (Node::logger, rclc_node_get_logger, the C++ node’s), so the /rosout sink can publish what upstream publishes (RFC-0102 D4). The catch-all is never marked: a node whose name fell back to it would otherwise publish every unnamed logger.
severity_enabled_at_compile_time
Compile-time ceiling check used by the nros_*! macros.
severity_from_u8
Reconstruct a Severity from its u8 discriminant.
timestamp_available
Whether [__timestamp_ns] can answer with a real clock.