ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I'm not sure what you mean by "filter". You can already control log levels independently using something like --log-level l1:=INFO. But if you mean you want to only print from one logger, then you could do something like this to filter out most other things:

% ./install/lib/demo_nodes_cpp/talker --ros-args --log-level FATAL --log-level l1:=INFO
[INFO] [1659006256.611685000] [l1]: l1 info

In that example I modified the talker demo with these lines:

diff --git a/demo_nodes_cpp/src/topics/talker.cpp b/demo_nodes_cpp/src/topics/talker.cpp
index 5058722..aae7e1b 100644
--- a/demo_nodes_cpp/src/topics/talker.cpp
+++ b/demo_nodes_cpp/src/topics/talker.cpp
@@ -37,6 +37,14 @@ public:
   explicit Talker(const rclcpp::NodeOptions & options)
   : Node("talker", options)
   {
+    rclcpp::Logger l1 = rclcpp::get_logger("l1");
+    rclcpp::Logger l2 = rclcpp::get_logger("l2");
+
+    RCLCPP_INFO(l1, "l1 info");
+    RCLCPP_INFO(l2, "l2 info");
+    RCLCPP_DEBUG(l1, "l1 debug");
+    RCLCPP_DEBUG(l2, "l2 debug");
+
     // Create a function for when messages are to be sent.
     setvbuf(stdout, NULL, _IONBF, BUFSIZ);
     auto publish_message =

You can also control more than one at a time:

% ./install/lib/demo_nodes_cpp/talker --ros-args --log-level FATAL --log-level l1:=INFO --log-level l2:=DEBUG --log-level talker:=INFO
[INFO] [1659006445.024564000] [l1]: l1 info
[INFO] [1659006445.024583000] [l2]: l2 info
[DEBUG] [1659006445.024586000] [l2]: l2 debug
[INFO] [1659006446.039449000] [talker]: Publishing: 'Hello World: 1'
[INFO] [1659006447.039343000] [talker]: Publishing: 'Hello World: 2'
[INFO] [1659006448.036625000] [talker]: Publishing: 'Hello World: 3'
[INFO] [1659006449.036557000] [talker]: Publishing: 'Hello World: 4'

Not sure if that answers your question, but if not, please provide more details.