ros / ros_comm

ROS communications-related packages, including core client libraries (roscpp, rospy, roslisp) and graph introspection tools (rostopic, rosnode, rosservice, rosparam).
http://wiki.ros.org/ros_comm
753 stars 911 forks source link

Fixed ROSCONSOLE_FORMAT with microseconds #2370

Closed peci1 closed 4 weeks ago

peci1 commented 7 months ago

Currently, using the %f modifier for microseconds in ROSCONSOLE_FORMAT only works for C++ nodes. Python nodes do not interpret it:

$ export ROSCONSOLE_FORMAT='[${severity}] [${time:%d/%m/%Y %T.%f}] [${node}]: ${message}'

$ rosrun joint_state_publisher_gui joint_state_publisher_gui  # Python node
[INFO] [20/02/2024 15:19:57.%f, 0.000000] [/joint_state_publisher_gui]: Centering

$ rosrun tf2_ros static_transform_publisher 0 0 0 0 0 0 a b  # C++ node
[ INFO] [20/02/2024 14:41:05.796267] [/static_transform_publisher_1708440065774087215]: Spinning until killed publishing a to b

That is because the Python part calls time.strftime(), which uses the integer seconds. If, on the other hand, datetime is used, it uses a fractional seconds representation and is this capable of printing the microseconds.

This PR fixes the issue by switching to datetime objects. It also updates the unit test to test the feature.

peci1 commented 7 months ago

This PR is similar to https://github.com/ros/ros_comm/pull/2367 but chose the other mentioned approach by using datetime. This PR also fixes both places where time strings can appear. Moreover, this PR adds a unit test.

rafa-martin commented 7 months ago

I think they will merge this feature...

peci1 commented 7 months ago

@rafa-martin Thanks for stopping by. Would you be able to review this PR? In the low maintenance mode Noetic has, non-maintainer reviews are almost a requirement to get things moving.

peci1 commented 7 months ago

Thanks!