0
$\begingroup$

Rosanswers logo

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..


Originally posted by Windel on ROS Answers with karma: 36 on 2019-07-22

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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-logging/6469/24?u=alsora

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


Originally posted by alsora with karma: 1322 on 2019-07-22

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by Windel on 2019-07-22:
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.

Comment by alsora on 2019-07-22:
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/issues/402

Comment by Windel on 2019-07-22:
Btw, I tried a simple rclpy script, and ros2 topic echo /rosout does not give any output.

Comment by alsora on 2019-07-22:
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

Comment by ssnover95 on 2020-09-18:
Have there been any updates with regards to logging to a file in Eloquent or Foxy? Either support for it or perhaps a Github issue tracking the feature? (this is the top result when I search for it, so it'd be great if this page at least could direct one to the right place)

$\endgroup$

Your Answer

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