Skip to content

Commit 151c8c7

Browse files
committed
added some explanations
1 parent f3a39a0 commit 151c8c7

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

examples/minimal_logging/README.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Differences between the [ROS2](https://docs.ros.org/en/jazzy/index.html) logger and standard [`println!()`](https://doc.rust-lang.org/std/macro.println.html)
2+
3+
The [ROS2 logger](https://docs.ros.org/en/jazzy/Tutorials/Demos/Logging-and-logger-configuration.html) and
4+
[classic stdout (e.g., `println!`)](https://en.wikipedia.org/wiki/Standard_streams) differ in several key ways:
5+
6+
1. **Severity Levels**:
7+
ROS2 provides structured log levels (`DEBUG`, `INFO`, `WARN`, `ERROR`, `FATAL`), enabling filtering based on urgency. `println!` outputs raw text without categorization.
8+
9+
2. **Dynamic Control**:
10+
ROS2 allows runtime adjustment of logging levels (e.g., enabling `DEBUG` on-the-fly). `println!` statements cannot be disabled without code changes.
11+
12+
3. **Metadata**:
13+
ROS2 automatically appends context (timestamp, node name, file/line number) to logs. `println!` requires manual addition of such details.
14+
15+
4. **Integration**:
16+
ROS2 logs are captured by tools like `rqt_console` and can be routed to files/network. `println!` outputs only to stdout unless manually redirected.
17+
18+
5. **Performance**:
19+
ROS2 optimizes by skipping disabled log levels (e.g., `DEBUG` if not active). `println!` always executes, incurring overhead regardless of need.
20+
21+
6. **Configuration**:
22+
ROS2 logging is configurable via launch files/parameters (e.g., per-node log levels). `println!` offers no built-in configuration.
23+
24+
**Example**:
25+
26+
```rust
27+
// ROS2 logger (Rust example with rclrs)
28+
log!(node.info(), "Sensor value: {}", sensor_data); // Adds metadata, severity, and runtime control
29+
30+
// Classic stdout
31+
println!("Sensor value: {}", sensor_data); // Simple, unstructured output
32+
```
33+
34+
**Use ROS2 logger** for structured, controllable logging within the ROS2 ecosystem; use `println!` for quick, simple text output.

0 commit comments

Comments
 (0)