Rosanswers logo

I've recently been testing ROS2 galactic and tried using the new per-logger log levels here. I am using it with namespaces and couldn't get it to work. Is there a way to use it with namespaces?

The command I am using is:

ros2 run robot_control vehicle --ros-args -r __ns:=/drone_0 --log-level vehicle:=DEBUG

I've also tried the following after using ros2 node list to get the node names:

ros2 run robot_control vehicle --ros-args -r __ns:=/drone_0 --log-level /drone_0/vehicle:=DEBUG

Originally posted by Blake McHale on ROS Answers with karma: 5 on 2021-07-01

Post score: 0


1 Answer 1


Rosanswers logo

I think you need to do this:

ros2 run robot_control vehicle --ros-args -r __ns:=/drone_0 --log-level drone_0.vehicle:=DEBUG

To get it to work.

To test this, I modified the talker demo in the demo_nodes_cpp package, like this:

diff --git a/demo_nodes_cpp/src/topics/talker.cpp b/demo_nodes_cpp/src/topics/talker.cpp
index 30f97a0..01756d0 100644
--- a/demo_nodes_cpp/src/topics/talker.cpp
+++ b/demo_nodes_cpp/src/topics/talker.cpp
@@ -44,6 +44,7 @@ public:
         msg_ = std::make_unique<std_msgs::msg::String>();
         msg_->data = "Hello World: " + std::to_string(count_++);
+        RCLCPP_DEBUG(this->get_logger(), "Publishing: '%s'", msg_->data.c_str());
         RCLCPP_INFO(this->get_logger(), "Publishing: '%s'", msg_->data.c_str());
         // Put the message into a queue to be processed by the middleware.
         // This call is non-blocking.

And to reproduce what you were trying to do, I did this:

$ ros2 run demo_nodes_cpp talker --ros-args -r __ns:=/drone_0 --log-level talker:=DEBUG
[DEBUG] [1625186542.873545147] [talker]: Load library libtopics_library.so
[DEBUG] [1625186542.875355119] [talker]: Instantiate class rclcpp_components::NodeFactoryTemplate<demo_nodes_cpp::Talker>
1625186542.876201 [87]     talker: using network interface enp0s5 (udp/ selected arbitrarily from: enp0s5, docker0
[INFO] [1625186543.880863775] [drone_0.talker]: Publishing: 'Hello World: 1'

$ ros2 run demo_nodes_cpp talker --ros-args -r __ns:=/drone_0 --log-level drone_0.talker:=DEBUG
1625186556.836825 [87]     talker: using network interface enp0s5 (udp/ selected arbitrarily from: enp0s5, docker0
[DEBUG] [1625186557.841640933] [drone_0.talker]: Publishing: 'Hello World: 1'
[INFO] [1625186557.841909375] [drone_0.talker]: Publishing: 'Hello World: 1'

Note that even though the node name is /drone_0/talker (as reported by ros2 node list), the logger name is separated by . instead of /.

Originally posted by William with karma: 17335 on 2021-07-01

This answer was ACCEPTED on the original site

Post score: 1

Original comments

Comment by Blake McHale on 2021-07-02:
Thanks! That works!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.