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.
Originally posted by William with karma: 17335 on 2022-07-28
This answer was ACCEPTED on the original site
Post score: 1
Original comments
Comment by Pablo Iñigo Blasco on 2022-07-28:
Great! That was the way I thought was. But, I tried that and didn't work. Obviously I did something wrong. Thank you very much.
So the main conclusion I get is that logger levels in program arguments refer to logger names not packages or nodes.
Thanks.
Comment by William on 2022-07-28:
That's right, logger names are just strings, and nodes just create a logger named after themselves, but otherwise they're not special.