Ask Your Question

Get logging output to /rosout using rclutils (writing a client library)

asked 2021-03-08 07:19:02 -0500

Jan Wielemaker gravatar image

I'm writing a ROS2 client library for SWI-Prolog. Basic pub/sub works. Next step is to get logging to work. Calling rcutils_log() works fine for loging to the console, but nothing appears in /rosout or in rqt. It doesn't seem to matter whether I leave the initialization to RCUTILS_LOGGING_AUTOINIT or call rcutils_logging_initialize(). Controlling the level affects the output in the console, so the basics seem to work. I tried with and without a creating a ROS node. The subscription works fine and the node is visible in rqt.

Platform is Ubuntu 20.04 using ROS2 foxy.

Any clue, including clues on how to debug this?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-03-08 13:36:51 -0500

Jan Wielemaker gravatar image

After a lot of searching in the rcl and rcutils sources and some gdb breakpoints, I got it working. Key are

  • Initialize logging right after creating the rcl context, notably __before__ creating a node in this context.
  • Use rcl_logging_configure_with_output_handler() with rcl_logging_multiple_output_handler as handler, also __before__ creating a node.
  • Make sure options.enable_rosout is true for rcl_node_init(). This is by default the case, but it was set to false in my code based on rclpy (which I guess sets it somewhere else).
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2021-03-08 07:19:02 -0500

Seen: 135 times

Last updated: Mar 08 '21