Skip to content

[launch] provide default console and filesystem logging for executed processes #104

@wjwwood

Description

@wjwwood

Currently in launch an executed process does not have anything printed to the console and nothing is logged to a file.

Some of the examples will create custom event handlers for this:

# Setup a custom event handler for all stdout/stderr from processes.
# Later, this will be a configurable, but always present, extension to the LaunchService.
def on_output(event: launch.Event) -> None:
for line in event.text.decode().splitlines():
print('[{}] {}'.format(
cast(launch.events.process.ProcessIO, event).process_name, line))
ld.add_action(launch.actions.RegisterEventHandler(launch.event_handlers.OnProcessIO(
# this is the action ^ and this, the event handler ^
on_stdout=on_output,
on_stderr=on_output,
)))

The "default launch description" provided by launch_ros also creates an event handler to cause executed processes to print to the console if configured to do so (with the output= option to ExecuteProcess and it's derived classes like Node):

def _on_process_output(event: launch.Event, *, file_name: Text, prefix_output: bool):
typed_event = cast(launch.events.process.ProcessIO, event)
text = event.text.decode()
if typed_event.execute_process_action.output == 'screen':
if prefix_output:
for line in text.splitlines():
print('[{}] {}'.format(event.process_name, line))
else:
print(text, end='')
elif typed_event.execute_process_action.output == 'log':
if file_name == 'stderr':
if prefix_output:
for line in text.splitlines():
print('[{}:{}] {}'.format(event.process_name, file_name, line))
else:
print(text, end='')
# TODO(wjwwood): implement file logging

But even this doesn't handle writing process output to a log file:

# TODO(wjwwood): implement file logging

Ideally, there would be some facility for this built into launch and launch_ros could additionally configure it to write files to something like ROS_HOME where as it might go to ~/.launch_logs (or something like that) instead. The user could further configure this default event handler if desired.

The user would still be able to provide their own event handler for output from process, to be run along with the default or instead of it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestreadyWork is about to start (Kanban column)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions