-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support setting log-level via command-line #383
Comments
@norro Could you provide more information about why this feature is needed and what it would do? |
Hello, I am also interested in this feature, for my use case I'd like to sometimes launch my system at logging level WARN, and sometimes at logging level ERROR (basically I'd like to easily switch between more or less verbose options). |
First of all, it's important not to mix up ROS 2 node arguments with ROS 2 cli arguments. Having said that, currently this can be achieved by explicitly declaring a launch argument and then using that argument to set def generate_launch_description():
return launch.LaunchDescription([
launch.actions.DeclareArgument(name='log_level', default_value='info'),
launch_ros.actions.Node(
# name, namespace, executable, etc.
arguments=['--ros-args', '--log-level', LaunchConfiguration('log_level')]
)
]) should do. It could be made implicit and applicable to all nodes, though in that case I wonder if it's worth all the plumbing instead of simply having |
Hi, thanks for the feedback. I had considered the suggestion above of passing log-level arguments down to individual nodes. An issue with this for me is when I am including other launch files from external packages, in which case I cannot add the extra arguments. I'd say it may get a bit unwieldy in general for larger projects, if every launch file needs to pass logging levels to every node, in order to achieve this global level of control over logging. As an alternative, the "environment variable sets default logging level" suggestion sounds good to me 👍 |
I have a slight preference for command line arguments over environment variables, but I think that would be ok too. Typically in ROS 1, this kind of thing was done with a launch argument as @hidmic suggested simply because you often did not want all nodes to change log level, but instead you wanted to target a specific node or namespace to change the level. This is increasingly important with larger systems. So at some point setting an env var before Alternatively we could have some special handling for |
This applies equally to name remapping and parameter overrides, which are also often done at runtime (desirable as a command line option). It would be very convenient to forward these options to all of the nodes, since these are things that are good candidates to change at runtime, and it is burdensome to have to edit the launch code to do so, even to add boilerplate to forward these options. There would be some edge cases that wouldn't make a ton of sense, especially for name remapping, which can be node specific like |
This way, you can set log level to nodes. Try this launch file. This worked for me.
|
Coming from Galactic, node logging has been introduced, which sets up log level to specific node, avoiding global log level From the last example, it looks like this: <...>
DeclareLaunchArgument(
"log_level",
default_value = TextSubstitution(text=str("WARN")),
description="Logging level"
),
launch_ros.actions.Node(
package="serverpublisher",
executable="talker",
name="custom_msg_publisher_to_Life_iteration_topic",
parameters=[
{"Parameter_Publisher": LaunchConfiguration('Parameter_launch_argument')}
],
output="screen",
arguments=['--ros-args', '--log-level', ['custom_msg_publisher_to_Life_iteration_topic:=', LaunchConfiguration('log_level')]]
), # change here
launch_ros.actions.Node(
package="serverpublisher",
executable="server",
name="custom_server_to_add_three_ints",
output="screen",
arguments=['--ros-args', '--log-level', ['custom_server_to_add_three_ints:=', LaunchConfiguration('log_level')]]
), # change here Slightly upsetting, from my understanding you cannot pass the Node |
Feature request
Feature description
Allow setting log-level via command line, similar as documented for
ros2 run
,ros2 service
, etc. see ros2/Tutorials/Logging-and-logger-configurationSteps to reproduce issue
Expected behavior
log level is set to debug
Actual behavior
ros2: error: unrecognized arguments: --ros-args --log-level debug
The text was updated successfully, but these errors were encountered: