ros2 / launch

Tools for launching multiple processes and for writing tests involving multiple processes.
Apache License 2.0
124 stars 139 forks source link

Can't change log level of the launch file #726

Closed iftahnaf closed 1 year ago

iftahnaf commented 1 year ago

Bug report

We have a launch file that runs some nodes and executes a process.

We include RegisterEventHandler, and OnProcessExit that emits even Shutdown.

For some reason, it prints all the debug messages from the processing event.

When trying to change the default log level with rclpy.logging.set_logger_level('launch',20). it doesn't help and it print alot of DEBUG messages.

Everything is working and the simulation running, just prints a lot of DEBUG messages.

Required Info:

Steps to reproduce issue

Some part of the launch file:

...
time.sleep(1.0)

rclpy.logging.set_logger_level('launch', 20)

def generate_launch_description():

    proc_px4 = ExecuteProcess(
        cmd=['bash', '-c', f'cd /workspaces/drone/PX4-Autopilot && {mode} make px4_sitl gazebo-classic_iris__windy'],
        cwd='/tmp/px4',
        output='screen',
        emulate_tty=True
    )

    node_offboard = Node(
        package='px4_offboard',
        namespace='offboard_control',
        executable='offboard_control',
        output='screen',
        name='offboard_control',
        parameters=[offboard_parameters],
        emulate_tty=True
    )

    node_dds_agent = Node(
        package='micro_ros_agent',
        namespace='px4_offboard',
        executable='micro_ros_agent',
        name='micro_ros',
        output='screen',
        emulate_tty=True,
        arguments=['udp4', '--port', '8888']
    )

    recorder = ExecuteProcess(
        cmd=['ros2', 'bag', 'record', '-a', '-s', 'mcap','-o', f'db/{time.strftime("%Y-%m-%d_%H:%M:%S", time.gmtime())}'],
    )

    sys_shut_down = RegisterEventHandler(OnProcessExit(
        target_action=node_offboard,
        on_exit=[
                    LogInfo(msg=(f'{bcolors.OKGREEN}The Scenario has ended!{bcolors.ENDC}')),
                    EmitEvent(event=Shutdown(
                        reason='Finished'))
                ]       
    ))

    bridge_dir = get_package_share_directory('rosbridge_server')
    node_rosbridge =  IncludeLaunchDescription(launch_description_sources.FrontendLaunchDescriptionSource(bridge_dir + '/launch/rosbridge_websocket_launch.xml'))

    ld = LaunchDescription([proc_px4, node_offboard, node_dds_agent, node_rosbridge,recorder, sys_shut_down])
    return ld

Expected behavior

printing only INFO logs.

Actual behavior

log-level stays at DEBUG.

Additional information

For example, the printings in the terminal:

[DEBUG] [launch.launch_context]: emitting event synchronously: 'launch.events.process.ProcessStderr'
[DEBUG] [launch]: processing event: '<launch.events.process.process_stderr.ProcessStderr object at 0x7ff86e441cc0>'
[DEBUG] [launch]: processing event: '<launch.events.process.process_stderr.ProcessStderr object at 0x7ff86e441cc0>' ✓ '<launch.event_handlers.on_process_io.OnProcessIO object at 0x7ff86e6a8fd0>'
[offboard_control-2] [INFO] [1692878921.169354088] [offboard_control.offboard_control]: State = P1, Position = [-0.012, 0.004, 0.059]
[DEBUG] [launch.launch_context]: emitting event synchronously: 'launch.events.process.ProcessStdout'
[DEBUG] [launch]: processing event: '<launch.events.process.process_stdout.ProcessStdout object at 0x7ff86e441cc0>'
[DEBUG] [launch]: processing event: '<launch.events.process.process_stdout.ProcessStdout object at 0x7ff86e441cc0>' ✓ '<launch.event_handlers.on_process_io.OnProcessIO object at 0x7ff86e3fbc10>'
[DEBUG] [launch.launch_context]: emitting event synchronously: 'launch.events.process.ProcessStderr'
[DEBUG] [launch]: processing event: '<launch.events.process.process_stderr.ProcessStderr object at 0x7ff86e441cc0>'
[DEBUG] [launch]: processing event: '<launch.events.process.process_stderr.ProcessStderr object at 0x7ff86e441cc0>' ✓ '<launch.event_handlers.on_process_io.OnProcessIO object at 0x7ff86e6a8fd0>'
[offboard_control-2] [INFO] [1692878921.429540288] [offboard_control.offboard_control]: State = P1, Position = [-0.012, 0.003, 0.060]
[DEBUG] [launch.launch_context]: emitting event synchronously: 'launch.events.process.ProcessStderr'
[DEBUG] [launch]: processing event: '<launch.events.process.process_stderr.ProcessStderr object at 0x7ff86e441cc0>'
[DEBUG] [launch]: processing event: '<launch.events.process.process_stderr.ProcessStderr object at 0x7ff86e441cc0>' ✓ '<launch.event_handlers.on_process_io.OnProcessIO object at 0x7ff86e6a8fd0>'
[offboard_control-2] [INFO] [1692878921.689481670] [offboard_control.offboard_control]: State = P1, Position = [-0.008, 0.003, 0.058]
[DEBUG] [launch.launch_context]: emitting event synchronously: 'launch.events.process.ProcessStdout'
[DEBUG] [launch]: processing event: '<launch.events.process.process_stdout.ProcessStdout object at 0x7ff86e441cc0>'
[DEBUG] [launch]: processing event: '<launch.events.process.process_stdout.ProcessStdout object at 0x7ff86e441cc0>' ✓ '<launch.event_handlers.on_process_io.OnProcessIO object at 0x7ff86e3fbc10>'
[DEBUG] [launch.launch_context]: emitting event synchronously: 'launch.events.process.ProcessStderr'
[DEBUG] [launch]: processing event: '<launch.events.process.process_stderr.ProcessStderr object at 0x7ff86e441cc0>'
[DEBUG] [launch]: processing event: '<launch.events.process.process_stderr.ProcessStderr object at 0x7ff86e441cc0>' ✓ '<launch.event_handlers.on_process_io.OnProcessIO object at 0x7ff86e6a8fd0>'
[offboard_control-2] [INFO] [1692878921.949650595] [offboard_control.offboard_control]: State = P1, Position = [-0.008, 0.004, 0.059]
[DEBUG] [launch.launch_context]: emitting event synchronously: 'launch.events.process.ProcessStdout'
[DEBUG] [launch]: processing event: '<launch.events.process.process_stdout.ProcessStdout object at 0x7ff86e441cc0>'
[DEBUG] [launch]: processing event: '<launch.events.process.process_stdout.ProcessStdout object at 0x7ff86e441cc0>' ✓ '<launch.event_handlers.on_process_io.OnProcessIO object at 0x7ff86f2edd20>'
[bash-1] INFO  [commander] Takeoff detected
[DEBUG] [launch.launch_context]: emitting event synchronously: 'launch.events.process.ProcessStdout'
[DEBUG] [launch]: processing event: '<launch.events.process.process_stdout.ProcessStdout object at 0x7ff86e441cc0>'
[DEBUG] [launch]: processing event: '<launch.events.process.process_stdout.ProcessStdout object at 0x7ff86e441cc0>' ✓ '<launch.event_handlers.on_process_io.OnProcessIO object at 0x7ff86e3fbc10>'
[DEBUG] [launch.launch_context]: emitting event synchronously: 'launch.events.process.ProcessStderr'
[DEBUG] [launch]: processing event: '<launch.events.process.process_stderr.ProcessStderr object at 0x7ff86e441cc0>'
[DEBUG] [launch]: processing event: '<launch.events.process.process_stderr.ProcessStderr object at 0x7ff86e441cc0>' ✓ '<launch.event_handlers.on_process_io.OnProcessIO object at 0x7ff86e6a8fd0>'
[offboard_control-2] [INFO] [1692878922.209572708] [offboard_control.offboard_control]: State = P1, Position = [-0.008, 0.004, 0.062]
[DEBUG] [launch.launch_context]: emitting event synchronously: 'launch.events.process.ProcessStderr'
[DEBUG] [launch]: processing event: '<launch.events.process.process_stderr.ProcessStderr object at 0x7ff86e441cc0>'
[DEBUG] [launch]: processing event: '<launch.events.process.process_stderr.ProcessStderr object at 0x7ff86e441cc0>' ✓ '<launch.event_handlers.on_process_io.OnProcessIO object at 0x7ff86e6a8fd0>'
[offboard_control-2] [INFO] [1692878922.469167765] [offboard_control.offboard_control]: State = P1, Position = [-0.007, 0.007, 0.061]
[DEBUG] [launch.launch_context]: emitting event synchronously: 'launch.events.process.ProcessStdout'
[DEBUG] [launch]: processing event: '<launch.events.process.process_stdout.ProcessStdout object at 0x7ff86e441cc0>'
[DEBUG] [launch]: processing event: '<launch.events.process.process_stdout.ProcessStdout object at 0x7ff86e441cc0>' ✓ '<launch.event_handlers.on_process_io.OnProcessIO object at 0x7ff86e3fbc10>'
[DEBUG] [launch.launch_context]: emitting event synchronously: 'launch.events.process.ProcessStderr'
[DEBUG] [launch]: processing event: '<launch.events.process.process_stderr.ProcessStderr object at 0x7ff86e441cc0>'
[DEBUG] [launch]: processing event: '<launch.events.process.process_stderr.ProcessStderr object at 0x7ff86e441cc0>' ✓ '<launch.event_handlers.on_process_io.OnProcessIO object at 0x7ff86e6a8fd0>'
[offboard_control-2] [INFO] [1692878922.729625685] [offboard_control.offboard_control]: State = P1, Position = [-0.006, 0.007, 0.064]
iftahnaf commented 1 year ago

solved by adding:

launch.logging.launch_config.level = logging.INFO

after importing:

import launch.logging
import logging