ÖmerFİ
09/27/2025, 2:19 PMMarvin
09/27/2025, 2:19 PMMarvin
09/27/2025, 2:23 PMfrom 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.
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.
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