Hi, is there a way to retrieve task logs using Pyt...
# flyte-support
l
Hi, is there a way to retrieve task logs using Python for an execution started via Python?
c
hey @little-printer-49833 you could use the
logging
library to dump logs to the terminal An example
Copy code
import logging
from flytekit import task, workflow

# Configure the logger
logging.basicConfig(
    level=<http://logging.INFO|logging.INFO>,  # Set the log level
    format='%(asctime)s - %(levelname)s - %(message)s',  # Set the log format
    handlers=[
        logging.StreamHandler(),  # Output logs to the console
        logging.FileHandler('flyte_local_execution.log')  # Output logs to a file
    ]
)

# Define a Flyte task with logging
@task
def my_flyte_task(x: int) -> int:
    <http://logging.info|logging.info>("Starting Flyte task with input: %d", x)
    result = x + 1
    <http://logging.info|logging.info>("Completed Flyte task with result: %d", result)
    return result

# Define a Flyte workflow
@workflow
def my_flyte_workflow(x: int) -> int:
    return my_flyte_task(x=x)