<@ULVA73B9P> flow A calls task B, task B calls tas...
# ask-marvin
ö
@Marvin flow A calls task B, task B calls task C. In UI, I see all logs in the flow, but when I select task B, I cannot see logs produced by task C but B
m
thought for 222.7 seconds
Short answer: that’s expected. - The flow run view aggregates logs from the flow and all child runs (tasks and subflows). - A task run view only shows logs emitted by that specific task run. Logs from another task (e.g., C) won’t appear under B, even if B called C. You’ll see C’s logs on the task C run. Ways to get the behavior you want: 1) If you want C’s messages to appear under task B - Make C a normal helper function (not a task) and log via the current run’s logger.
Copy code
from prefect import flow, task, get_run_logger

def do_c_logic(x):
    logger = get_run_logger()
    <http://logger.info|logger.info>("C helper starting")
    # ... work ...
    <http://logger.info|logger.info>("C helper done")
    return x + 1

@task(log_prints=True)
def task_b(x: int):
    logger = get_run_logger()
    <http://logger.info|logger.info>("B starting")
    y = do_c_logic(x)  # logs will be attributed to task B
    <http://logger.info|logger.info>(f"B done: {y}")
    return y

@flow
def flow_a():
    return task_b(1)
2) If you want C as its own task (separate retries/caching/state) - Keep C as a task; call it from B (or better, from the flow). Its logs will live under task C’s run.
Copy code
from prefect import flow, task, get_run_logger

@task
def task_c(x):
    logger = get_run_logger()
    <http://logger.info|logger.info>("C doing work")
    return x + 1

@task
def task_b(x):
    # Creates a separate task run for C; C’s logs appear under task C
    y = task_c(x)           # sync
    # or: y = task_c.submit(x)   # async/concurrent
    return y

@flow
def flow_a():
    return task_b(1)
3) If you want hierarchical grouping with its own “parent” log view - Model B as a subflow. Subflow B’s log view will include its tasks (like C), giving you a logical grouping.
Copy code
from prefect import flow, task, get_run_logger

@task
def task_c(x):
    logger = get_run_logger()
    <http://logger.info|logger.info>("C doing work")
    return x + 1

@flow
def subflow_b(x):
    logger = get_run_logger()
    <http://logger.info|logger.info>("B (subflow) starting")
    y = task_c(x)
    <http://logger.info|logger.info>("B (subflow) done")
    return y

@flow
def flow_a():
    return subflow_b(1)
A couple of tips: - Use
get_run_logger()
inside tasks and helpers so logs are scoped to the current run. -
log_prints=True
on `@flow`/`@task` captures plain
print()
into Prefect logs. Questions to confirm so I can tailor this: - Are B and C both decorated with
@task
? - How exactly are you invoking C from B (direct call vs
.submit
)? - Are you on Prefect 3.x? Docs: - Tasks: Tasks - Flows and subflows: Flows and subflows - Logging: Logging