ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
7

Selecting log level in ROS2 launch file

asked 2018-12-25 14:30:43 -0600

Teckel gravatar image

updated 2018-12-25 14:31:44 -0600

Nodes defined in launch file have the INFO log level as a default value I would like to know how to change it so that it also logs DEBUG level strings or other types of logging.

launch_ros.actions.Node(package='demo_nodes_cpp', node_executable='talker', output='screen', parameters=[config_file])

Thank you

edit retag flag offensive close merge delete

Comments

Any updates?

yossi_ov gravatar image yossi_ov  ( 2019-11-11 01:38:51 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
3

answered 2020-11-03 09:46:57 -0600

notarobot gravatar image

Hello, I have had the same issue and for me (on Eloquent) the following works:

logger = launch.substitutions.LaunchConfiguration("log_level")
launch.LaunchDescription([
      launch.actions.DeclareLaunchArgument(
            "log_level",
            default_value=["debug"],
            description="Logging level",
      ),
     launch_ros.actions.Node(
         package='demo_nodes_cpp',
         executable='talker',
         output='screen', 
         arguments=['--ros-args', '--log-level', logger]
    )
])

I got this idea from this open issue: https://github.com/ros2/launch/issues... and hopefully a more elegant solution will be available soon.

If anyone has an idea for a better solution in the meantime, please share!

edit flag offensive delete link more

Comments

1

This sets the level for all loggers including rcl which spams a lot. To set the logging level only for your node see here

(Available from galactic)

tnajjar gravatar image tnajjar  ( 2022-07-14 08:30:44 -0600 )edit

@tnajjar That is true. I found a solution by using the PythonExpression substitution.

    node_test = LifecycleNode(
        package="node_test",
        executable="note_test",
        name="note_test",
        namespace="",
        output="screen",
        ros_arguments=[
            "--log-level",
            PythonExpression(['"node_test:=" + "', log_level, '"']),
        ],
    )

But this is a very sinful piece of code because it allows a maleficent user to execute arbitrary Python code. Do you know any better solution?

LastStarDust gravatar image LastStarDust  ( 2023-02-13 02:33:09 -0600 )edit

you don't need PythonExpression

 arguments= [
    "--ros-args",
    "--log-level",
    "node_test:=debug",
]

this should work

tnajjar gravatar image tnajjar  ( 2023-02-16 08:04:53 -0600 )edit

@tnajjar That works if I want to keep the log level at "debug", but what if I want to change the log level as a command line argument?

If I write:

log_level_arg = DeclareLaunchArgument(
    "log-level",
    default_value=["debug"],
    description="Logging level",
)
log_level = LaunchConfiguration("log-level")

...

some_node = LifecycleNode(
    arguments= [
        "--ros-args",
        "--log-level",
        "some_node:=",
        log_level
    ]

then a white space is added between "some_node:=" and log_level and everything breaks down.

LastStarDust gravatar image LastStarDust  ( 2023-02-21 20:25:56 -0600 )edit
1

try:

some_node = LifecycleNode(
    arguments= [
        "--ros-args",
        "--log-level",
        ["some_node:=", log_level],
    ]
tnajjar gravatar image tnajjar  ( 2023-03-06 08:15:21 -0600 )edit

@tnajjar Thank you so much. That did the trick.

LastStarDust gravatar image LastStarDust  ( 2023-03-23 07:10:52 -0600 )edit
2

answered 2019-11-21 22:27:02 -0600

johnconn gravatar image

I know this question was asked before dashing was released, and that eloquent is being released soon with changed syntax...

But for dashing, you can use the following syntax:

  launch_ros.actions.Node(package='demo_nodes_cpp',
    node_executable='talker',
    output='screen', 
     parameters=[config_file],
    arguments=[('__log_level:=debug')])

This will set the log level to debug for every node being run in this process (rcl, rclcpp, the rmw layer). I don't know how to restrict the log changes to just "talker" node unfortunately. I think logging is still a work in progress.

edit flag offensive delete link more

Comments

Can anyone update on how to do this in Eloquent/Foxy? The direct translation to the new command line format does not work:

launch_ros.actions.Node(
    package='demo_nodes_cpp',
    executable='talker',
    output='screen', 
    arguments=[('--ros-args --log-level debug')]
)
rasmusan- gravatar image rasmusan-  ( 2020-09-10 03:33:34 -0600 )edit
2

The arguments must be given in a list of strings in Foxy as shown below.

launch_ros.actions.Node(
    package='demo_nodes_cpp',
    executable='talker',
    output='screen', 
    arguments=['--ros-args', '--log-level', 'debug']
)

The accepted answer achieves the same result as the above code.

trunc8 gravatar image trunc8  ( 2021-08-15 05:25:04 -0600 )edit

Question Tools

4 followers

Stats

Asked: 2018-12-25 14:30:43 -0600

Seen: 18,441 times

Last updated: Sep 10 '20