Setting logging directory per Node in Foxy
Hi, is there a way to set up my logger, so that it outputs log files into different directories?
For example, let's say I have a my_node
node, and I would like for it to log it's contents to ./ros/logs/my_node/
like
auto logger = rclcpp::get_logger("my_node");
logger.set_logging_directory(path_to_logging_dir/my_node) // (i know this doesn't exist right now, it's just an example)
is there a way to access the logging internals to do that?
I know that spdlog
library has basic_file_sink
ROS2 uses spdlog
underneath, so maybe there is an access to it?
I've seen
https://answers.ros.org/question/357765/how-do-i-set-the-logging-directory-in-foxy/ but this is per launch file, and I want to separate on my node level, via rclcpp. I have also seen
https://docs.ros.org/en/foxy/Tutorials/Logging-and-logger-configuration.html, but here the default variables only respond to the main ros directory.
Asked by Serafadam on 2021-05-17 07:44:44 UTC
Answers
It's a bit late, but it looks like this feature has been implemented in the latest ROS2 release, Galactic Geochelone!
Check it out here: ROS2 Galactic, Updates to ROS2, "Ability to Specify Per-Logger Log Levels"
Asked by Spectre on 2021-05-31 13:20:23 UTC
Comments
I'm afraid logging levels don't have much to do in this case
Asked by Serafadam on 2021-06-01 03:51:38 UTC
Comments
Or is the encapsulation by launch file the correct way to do things?
Asked by Serafadam on 2021-05-17 07:48:50 UTC
I see an API for getting the log directory, but I don't see one for setting it. https://github.com/ros2/rcl_logging/blob/8d5ad0f9f32c1c3399122e28cf3e70f89ff0bc2f/rcl_logging_interface/include/rcl_logging_interface/rcl_logging_interface.h#L117
Maybe there's a way to set the directory in the file
rcl_logging_external_initialize()
? Even then I think logging affects the whole process, so if an API was added to rclcpp it may affect all nodes in the process.Asked by sloretz on 2021-05-17 13:02:52 UTC
You could try splitting your nodes into individual launch files, and then make a "master" launch file that references the others. Is this something feasible for you to try?
Asked by Spectre on 2021-05-17 13:14:04 UTC
After some thinking, I think doing this via launch file seems the cleanest solution for this case.
Asked by Serafadam on 2021-05-18 08:48:47 UTC