ROS2 disable logging to file

asked 2021-02-14 05:56:06 -0500

grouchy gravatar image

On ROS2 Foxy, it seems rclcpp nodes create log files in ~/.ros/log. Is there any way to disable this file logging, but still log to stdout/stderr and /rosout?

The reason I want to do this is because I am running ROS2 on an embedded system and nodes should run for weeks or months, and I will need to rotate the log files occasionally because storage space is at a premium. Journald is a good way to do this, and is well documented. When ROS2 nodes are run under systemd, the stdout/stderr logging is enough to get everything working as I want it. I could delete the .ros/log directory every now and again on a cron job, but this feels like a hack. I would also like to minimize the amount of eMMC thrashing.

Here is a similar question for ROS 1, but the answer was fairly unsatisfactory. I was hoping ROS2 would be more geared toward production systems and thus would support this out of the box.

The concept page on logging mentions very little and the logging tutorial mentions how to change the log dir, but not how to disable it. Also, this functionality only works on Galactic.

It seems this file logging feature is actually relatively new, here is a discussion on adding the file logging feature from 2019. In this discussion, wjwwood mentioned

For production system [logging to systemd] makes sense though, and because of that it should be possible to disable file logging in favor of just printing to stdout/stderr.

Here is a long discussion on logging and the linked comment discusses modifying the rcl_logging_spdlog package is the way to go. This question confirms that recompiled is required. This seems like the best option for me right now? Looking at the default spdlog logger it looks like it doesn't support an external config file yet, but I guess this could be the way to go in the future.

edit retag flag offensive close merge delete

Comments

Here is a similar question for ROS 1, but the answer was fairly unsatisfactory

that question, and the answers, is from 2011 ..

Since then there have been quite a few changes: Disable logging to /rosout, Disable all logging, ros/ros_comm#139 and ros/rosconsole#8.

gvdhoorn gravatar image gvdhoorn  ( 2021-02-14 06:10:41 -0500 )edit

Thanks for the extra info @gvdhoorn. I didn't want to include too many links to ROS1-specific solutions in my question, because this question is about ROS2.

grouchy gravatar image grouchy  ( 2021-02-14 07:02:49 -0500 )edit

I know it is. I just wanted to help future readers.

It's unclear to me why you mention that Q&A at all, as it doesn't really matter here whether a question from 2011 gave a satisfactory answer for a ROS version you're not using.

gvdhoorn gravatar image gvdhoorn  ( 2021-02-14 07:13:05 -0500 )edit

I guess I wanted to show I'd searched for similar questions before posting a new one. I should have said: "Here is a similar question for ROS 1, but the answers are not applicable to ROS2"

grouchy gravatar image grouchy  ( 2021-02-14 07:17:51 -0500 )edit

Agreed that this is a missing feature. Especially because logging from launch scripts can be configured; e.g.:

output='screen' will prevent logging to file, and

output='own_log' will cause every node to log to it's own file inside a common folder.

The launch configuration of logging is however in addition to direct file logging. Meaning, that:

output='screen' causes logging to file to be disabled from launch, but logs from each node are still saved to file, and

output='own_log' causes every log file to be duplicated inside the launch directory.

rasmusan- gravatar image rasmusan-  ( 2021-04-15 09:09:54 -0500 )edit