Ask Your Question
0

Namespaces with per-logger log levels specification

asked 2021-07-01 18:58:12 -0500

Blake McHale gravatar image

updated 2021-07-01 18:58:54 -0500

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

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-07-01 19:48:19 -0500

William gravatar image

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/10.211.55.6) 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/10.211.55.6) 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 /.

edit flag offensive delete link more

Comments

Thanks! That works!

Blake McHale gravatar image Blake McHale  ( 2021-07-02 13:14:57 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2021-07-01 18:58:12 -0500

Seen: 29 times

Last updated: Jul 01