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

Text log splitting / rotation in ROS 2

asked 2023-03-10 08:52:13 -0500

ahopsu gravatar image

updated 2023-03-10 12:47:59 -0500

kscottz gravatar image

Hi!

This question has seemingly been existing already for years (for ROS1), but I still haven't find any document or examples of how to split or rotate the log files in ROS2 (either from launch file, or directly from ROS2 run command line arguments, or even from code).

This is the only example(Issue 230: https://github.com/ros2/launch/issues...) I found to be related to this topic, but no where is told how to properly set this RotationHandler in launch file (as the launch_counters.py example does not seem to be a proper ROS2 launch file). Attempts to define it in launch file leads either to errors or non-effective results.

This is really an issue for an automated production systems where there is no possibility to be clearing the ROS logs all the time. Even if the ROS_LOG_DIR is set with some specific value, the ~/.ros/log/ directory also fills up with logs, if ROS2 launch is used. Disabling the logging completely is also not a very good idea, as then you can't solve afterwards what went wrong with the production.

Another question: How to define a own specific logging level? Something into between INFO and DEBUG? As otherwise the DEBUG level will output way too much unnecessary rcl system info into the logs.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-03-12 04:38:37 -0500

jrtg gravatar image

updated 2023-03-12 14:17:49 -0500

Hi,

Re. your fist question:

I think the link you mention might be ROS 2 python only. There is currently no rotating log functionality for c++, though it could probably be added without too much effort:

If you are using c++, logging is configured from rclcpp::init(), which ultimately calls rcl_logging_external_initialize, see here.

External logging uses the spdlog library. The logger is created here. Spdlog supports rotating log files, so if you change logger creation to something similar to this, you should have rotating log files.

That would obviously be a local hack, and you need to compile ROS 2 from source. To make this into a full feature, one should:

  • File an issue in the rcl_logging repository to discuss the best option to configure this (environment variable / command line argument / configuration file / other?),

  • In case of a configuration file: first check if there are existing implementations, e.g. this, and discuss whether it would be best to use these or to implement something custom (e.g. to avoid an extra dependency).

  • Change accordingly:

Given you state that this request has "been existing already for years" and it being "really an issue", maybe you should give it a go? :-) It shouldn't be ultimately difficult nor time-consuming, given above info.

Possible alternative solution

  • Disable external logging through the environment variable (refer to the docs),
  • Have something read the /rosout topic and write it to file,
    • I think rosbag could be used, though files are not in .csv by default, see here for info wrt conversion.
  • Write a script to restart your reader whenever you want the logfile to rotate.
  • This has the benefit of being a process-agnostic logger (i.e. gathers all log info of all nodes in a ROS 2 network, instead of having one log file per process),
  • It does not contain log info from non-node loggers (the ones created by rclcpp::get_logger("name")), only messages from node loggers (node->get_logger()).

Re. your 2nd question:

You can specify loglevels on a per-name basis, e.g.:

ros2 run package node --ros-args --log-level DEBUG --log-level rcl:=INFO --log-level rclcpp:=INFO

This sets default loglevel to DEBUG, but disables anything below INFO for rcl and rclcpp.

edit flag offensive delete link more

Comments

Thank you very much for the effort put in the answer! Yes, I have thought that there is no a straight-forward option to make this happen without building the ROS2 from source. Thank you for the well described steps I need to do for that.

Using the rosout topic also has some downsides as you mentioned. I need to check, what is the most convenient way to go for now. At least your answer to the second question is a solution to one problem I have been trying resolve for a very long time :) Thank you for that!

ahopsu gravatar image ahopsu  ( 2023-03-12 15:31:50 -0500 )edit

I can add here, that I ended up using Docker's log rotation feature, as the end application will be run in Docker container anyways, and the log rotation in Docker is quite easy to setup.

ahopsu gravatar image ahopsu  ( 2023-03-23 14:52:17 -0500 )edit

Question Tools

3 followers

Stats

Asked: 2023-03-10 08:52:13 -0500

Seen: 701 times

Last updated: Mar 12 '23