Differences between the ROS2 logger and standard println!()
The ROS2 logger and
classic stdout (e.g., println!) differ in several key ways:
-
Severity Levels:
ROS2 provides structured log levels (DEBUG,INFO,WARN,ERROR,FATAL), enabling filtering based on urgency.println!outputs raw text without categorization. -
Dynamic Control:
ROS2 allows runtime adjustment of logging levels (e.g., enablingDEBUGon-the-fly).println!statements cannot be disabled without code changes. -
Metadata:
ROS2 automatically appends context (timestamp, node name, file/line number) to logs.println!requires manual addition of such details. -
Integration:
ROS2 logs are captured by tools likerqt_consoleand can be routed to files/network.println!outputs only to stdout unless manually redirected. -
Performance:
ROS2 optimizes by skipping disabled log levels (e.g.,DEBUGif not active).println!always executes, incurring overhead regardless of need. -
Configuration:
ROS2 logging is configurable via launch files/parameters (e.g., per-node log levels).println!offers no built-in configuration.
Example:
// ROS2 logger (Rust example with rclrs)
log!(node.info(), "Sensor value: {}", sensor_data); // Adds metadata, severity, and runtime control
// Classic stdout
println!("Sensor value: {}", sensor_data); // Simple, unstructured outputUse ROS2 logger for structured, controllable logging within the ROS2 ecosystem; use println! for quick, simple text output.