ROS2 hack to enable DEBUG logging during 'ros2 launch'
Problem
When you ros2 launch
a ROS package, the default logging level is often set to INFO
, hence you wont see useful info when an error is encountered, e.g.:
[INFO] [launch]: All log files can be found below /home/user/.ros/log/2025-01-24-03-53-34-995687-user-desktop-2530786
[INFO] [launch]: Default logging verbosity is set to INFO
[ERROR] [launch]: Caught exception in launch (see debug for traceback): substitution args not supported: No module named 'roslaunch'
Solution
There is a feature request to allow setting the logging level for ros2 launch
via a command line argument. That is not implemented.
You either have the option of significantly modifying the launch file (see the feature request for details) or you can use the following hack:
At the top of your launch file, add the following Python code:
import logging
logging.root.setLevel(logging.DEBUG)
While the Default logging verbosity is set to INFO
message will still be printed (since it is executed before your Python file), most modules will now log at DEBUG
level.
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow