ROS2: get current log path (Foxy and later)
I am running ROS2 Foxy on Ubuntu 20.04. I'd like to configure a callback to be automatically invoked when the current log reaches a certain size. I tried to implement this myself using a timer, but the problem is that I can't seem to get the current log path. In Python, I tried from launch.logging import launch_config
, and then current_log_path = pathlib.Path(launch_config.get_log_file_path()).parent
. This docs for this function say that it returns the current log path. However, I observed that calling this function actually creates a new, empty log directory under the log root. The new directory doesn't contain a launch.log file. For example, after a call to this function, I see the following two log directories:
2022-06-16-19-02-12-792736-bb92d7fcf2e1-1 2022-06-16-19-02-15-186825-bb92d7fcf2e1-43
The first of these, ending in -1, contains launch.log, but the one ending in -43 is empty. Calls to the get_log_file_path
method above return 2022-06-16-19-02-15-186825-bb92d7fcf2e1-43
, i.e., the new, empty directory.
Am I misusing get_log_file_path
? Is there a different way to get the current log path in ROS2? I saw some answers about doing this with roslaunch
, but I believe that's only for ROS1, not ROS2. I also tried moving my call to launch_config
to my launch file, but it had the same side-effects as above.
Thanks in advance!