Ask Your Question

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


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

1 Answer

Sort by » oldest newest most voted

answered 2022-06-27 04:09:43 -0500

Try xrgtn/nullfs. I tried xrgtn/nullfs with raspberry pi 4, ubuntu20.04 and ros2 foxy. It worked fine.

Detail procedure to install and test xrgtn/nullfs as follows.

(1)Install xrgtn/nullfs
sudo apt update
sudo apt install -y git libfuse-dev build-essential
git clone
cd nullfs/
make nullfs

(2)Make nullfs directry
mkdir ~/nulldir
./nullfs ~/nulldir/

(3)Change ROS_LOG_DIR
Add folowing lines at the end of ~/.bashrc
export ROS_LOG_DIR=~/nulldir
~/nullfs/nullfs ~/nulldir

source ~/.bashrc
Run any ROS/ROS2 program and check that no files in ~/.ros/log and ~/nulldir.

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-02-14 05:56:06 -0500

Seen: 682 times

Last updated: Jun 27