Ask Your Question

Connect native python loggers to ros2 logging

asked 2021-10-05 15:11:16 -0500

nealtanner gravatar image

I am using libraries (some of my own, some 3rd party) that already make use of python's native logging module. How do I direct log traffic generated by these libraries to ROS2's logging system that shows up on /rosout?

I have confirmed that if I create a logger within the library using rclpy, then the messages show up as expected. However, I would like to be able to access log traffic without having to introduce rclpy as a dependency within the library.

LOGGER = logging.getLogger(__name__)
ROS_LOGGER = rclpy.logging.get_logger('my_module')'This message does NOT show up')'This message DOES show up')

For reference, under ROS1 I was able to accomplish this by adding rospy.roslogging.RosStreamHandler() and rospy.roslogging.RosOutHandler() as handlers to python's native root logger.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-11-21 18:05:50 -0500

RFRIEDM_Trimble gravatar image

It appears that ROS2 uses python logging under the hood. Each node in a python package sets the logger name to be the same as the node name. You can see this by doing this inside your node:

print("ROS Node logger name:", self.get_logger().name)

However, in the other python libraries, if they use logging.getLogger(__name__), they return <package_name>.<filename>.

If the ROS node's logger name was <package_name> it would be fine.

I have not yet figured out a way to make this work.

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-10-05 15:11:16 -0500

Seen: 33 times

Last updated: Nov 21 '21