Connect native python loggers to ros2 logging
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')
LOGGER.info('This message does NOT show up')
ROS_LOGGER.info('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.