Skip to content

Reading Logging Data in a Prefect Task #9495

Answered by zanieb
AlexanderKri asked this question in Q&A
Discussion options

You must be logged in to vote

You could read the logs from the API with the client

import asyncio

from prefect import flow, task, get_client, runtime, get_run_logger
from prefect.server.schemas.filters import LogFilter
from prefect.logging.handlers import APILogHandler


@flow
def example():
    check_logs.submit()
    logger = get_run_logger()
    logger.info("test")


@task
async def check_logs():
    async with get_client() as client:
        for _ in range(5):
            # Ensure any pending logs are sent
            await APILogHandler.aflush()
            logs = await client.read_logs(
                LogFilter(flow_run_id={"any_": [runtime.flow_run.id]})
            )

            for log in logs:
           …

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@AlexanderKri
Comment options

@zanieb
Comment options

Answer selected by AlexanderKri
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants