Ask Your Question
0

[ROS2] How to enable logging

asked 2019-07-22 03:16:42 -0500

I'm having troubles with my ROS2 setup. One common way I use during troubleshooting is logging. Basically, whenever I face an issue, my standard response is: crank up the logging!

My question is: how do I enable logging to file or standard output with ROS2?

  • Is there an environment variable that I could not find in the documentation which should be set?
  • Is there a flag to an executable?

I tried this:

$ ros2 topic list __log_level:=debug

But that did not work out..

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-07-22 04:41:48 -0500

alsora gravatar image

updated 2019-07-22 04:44:49 -0500

At the moment logging to file is not directly possible with ROS2, unless you register a custom logger interface. It will be probably available soon https://discourse.ros.org/t/ros2-logg...

For what concerns enabling log to standard output, the command that you used is not entirely correct. You have to set the logger verbosity for a specific ROS2 application.

The correct one would be something like this (for example for the publisher_lambda demo executable)

ros2 run examples_rclcpp_minimal_publisher publisher_lambda __log_level:=debug

Inside your application, you can log using the following macro (assuming C++ application)

RCLCPP_INFO(node->get_logger(), "This is my log message");

By default, the messages will be also logged to a specific topic, named rosout. (This behavior can be disabled using the parameter __log_disable_rosout:=true) So you can listen to them using

ros2 topic echo /rosout

An alternative is to use rqt which has plugins for reading and filtering logs

edit flag offensive delete link more

Comments

Thank you for this explanation. Is the fastrtps internal logger also routed into the rcl logging system? In order to troubleshoot connectivity issues, I would like to see logs from the FastRTPS library.

Windel gravatar imageWindel ( 2019-07-22 05:52:35 -0500 )edit

No, it isn't. As a side note, until some time ago logging in Fast-RTPS required a debug build, I'm not aware if they changed this. https://github.com/eProsima/Fast-RTPS...

alsora gravatar imagealsora ( 2019-07-22 05:59:26 -0500 )edit

Btw, I tried a simple rclpy script, and ros2 topic echo /rosout does not give any output.

Windel gravatar imageWindel ( 2019-07-22 06:05:48 -0500 )edit

There is probably an error in the implementation of your script. I suggest you to open a new question about that. If you want to test this with rclpy try the following:

ros2 run examples_rclpy_minimal_client client ros2 topic echo rosout

The client node will log a message saying that it's not finding a server. You should see the message both in the client terminal, as well as in a new terminal using the echo command shown above

alsora gravatar imagealsora ( 2019-07-22 07:53:23 -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

1 follower

Stats

Asked: 2019-07-22 03:16:42 -0500

Seen: 37 times

Last updated: Jul 22