Carlos Alberto da Costa Filho
04/09/2026, 1:06 AMMarvin
04/09/2026, 1:06 AMMarvin
04/09/2026, 1:09 AMflow_run_id (which task logs are), it will appear in the parent flow’s logs.
- No: There isn’t a way to make a log appear in a task run’s UI view but not in the parent flow’s UI view. Once it’s in the API, it shows up in both scopes.
- Your workaround is valid: use print() for high-frequency/per-epoch messages and set log_prints=False on that task so those prints stay in stdout/container logs only. Use the Prefect logger just for the final summary line.
Example
from prefect import flow, task
from prefect.logging import get_run_logger
@task(log_prints=False) # prints won't be captured by Prefect
def trial():
for epoch in range(5):
print(f"epoch {epoch} metrics...") # stdout-only, not in Prefect UI
logger = get_run_logger()
<http://logger.info|logger.info>("Finished trial with best metric=...") # 1 line in UI
@flow
def orchestrate():
trial()
if __name__ == "__main__":
orchestrate()
Optional nuance (if you prefer not to switch to print):
- You can keep using the Prefect logger but prevent specific records from going to the API by setting extra={"send_to_api": False}. Those logs will still go to any local/console handler but won’t appear in the Prefect UI at either the task or flow level.
from prefect.logging import get_run_logger
@task
def trial():
logger = get_run_logger()
# High-frequency logs: console-only; not sent to Prefect API/UI
<http://logger.info|logger.info>("epoch details ...", extra={"send_to_api": False})
# Final summary: sent to Prefect API/UI
<http://logger.info|logger.info>("Finished trial with best metric=...")
Notes on `log_prints`:
- log_prints=True patches print() to the Prefect logger (so prints appear in the UI).
- log_prints=False leaves prints on stdout only.
- A task’s explicit log_prints overrides the flow’s setting; if left as None, it inherits.