Viewing Execution Logs
To stream logs from a running or completed task execution in flyte-sdk, you can use the show_logs method on either a Run or an Action object. This provides a live-updating terminal UI or a raw text stream depending on your configuration.
Streaming Logs for a Run
When you have a Run name, you can retrieve the object and immediately start streaming logs. By default, this will show the logs for the most recent attempt of the primary action in the run.
from flyte.remote import Run
# Retrieve the run by its name
run = Run.get("a1b2c3d4e5f6g7h8")
# Stream logs to the console
run.show_logs(max_lines=50, show_ts=True)
The show_logs method uses AsyncLogViewer to create a scrolling window of logs in your terminal. Key parameters include:
max_lines: The number of lines to keep in the scrollback buffer (default is 100 forRun, 30 forAction).show_ts: Boolean to toggle visibility of timestamps.raw: IfTrue, disables the interactive viewer and prints logs directly to stdout.filter_system: IfTrue, hides system-level logs (e.g., Flyte internal orchestration logs).
Viewing Logs for Specific Actions and Attempts
A Run in flyte-sdk is composed of one or more Action objects. If a task retries, each retry is a new attempt within an Action. You can target specific actions and attempts for more granular debugging.
from flyte.remote import Action
# List all actions for a specific run to find the one you need
actions = Action.listall(for_run_name="a1b2c3d4e5f6g7h8")
for action in actions:
print(f"Action: {action.name}, Task: {action.task_name}, Phase: {action.phase}")
# Get a specific action and stream logs for the second attempt
action = Action.get(run_name="a1b2c3d4e5f6g7h8", name="n0")
action.show_logs(attempt=2, raw=True)
Note that the attempt parameter is 1-indexed.
Waiting for Logs to be Ready
In automated scripts, logs might not be available immediately after a run starts. You can use the wait method with wait_for="logs-ready" to block execution until the log stream is accessible.
from flyte.remote import Run
run = Run.get("a1b2c3d4e5f6g7h8")
# Block until logs are available on the remote server
run.wait(wait_for="logs-ready")
# Now safe to stream
run.show_logs()
Troubleshooting
Missing Logs in Notebooks
The AsyncLogViewer uses rich.live for interactive updates. In Jupyter environments, this requires ipywidgets. If ipywidgets is not installed, flyte-sdk will log a warning and automatically fall back to raw=True output.
Logs Not Found
If you attempt to view logs for a run that has just started, you may encounter a LogsNotYetAvailableError. This typically happens when the underlying container has not yet started or the logging sidecar has not initialized. Use run.wait(wait_for="logs-ready") to handle this gracefully.
System Log Noise
If your logs are cluttered with [flyte] prefixes or orchestration details, set filter_system=True in show_logs. This filters out log lines where the originator is identified as SYSTEM or the message contains internal Flyte markers.