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

[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
1

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 image Windel  ( 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 image alsora  ( 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 image Windel  ( 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 image alsora  ( 2019-07-22 07:53:23 -0500 )edit

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)

ssnover95 gravatar image ssnover95  ( 2020-09-18 18:06:38 -0500 )edit

Question Tools

1 follower

Stats

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

Seen: 4,637 times

Last updated: Jul 22 '19