Florent VanDeMoortele
11/18/2025, 6:09 PMMarvin
11/18/2025, 6:09 PMMarvin
11/18/2025, 6:12 PMget_run_logger() inside your @flow and @task code. It attaches run context (flow/task IDs, names) and automatically ships logs to Prefect Cloud so they show up on the run page.
- Use get_logger() anywhere outside a run context (module init, setup scripts, infra code). Those logs won’t appear in a specific flow/task run in Cloud unless you add your own handler.
Details:
- get_run_logger() requires an active flow/task run; calling it elsewhere raises an error. It returns a Prefect-aware logger adapter wired to the API handler so logs are sent to Cloud with the right metadata.
- get_logger() returns a standard Python logger (e.g., prefect.*). By default it logs to console; it’s not tied to a specific run.
Examples:
from prefect import flow, task, get_run_logger
from prefect.logging import get_logger
# Outside any run context
bootstrap_logger = get_logger("bootstrap")
<http://bootstrap_logger.info|bootstrap_logger.info>("Starting up...") # Console; not in a run's logs
@flow
def my_flow():
logger = get_run_logger()
<http://logger.info|logger.info>("Flow started") # Appears in this flow run’s logs in Cloud
do_work.submit()
@task
def do_work():
logger = get_run_logger()
<http://logger.info|logger.info>("Task message") # Appears in this task run’s logs in Cloud
Notes for your setup (Prefect 2 on Cloud, running on GCP):
- get_run_logger() logs will be batched and sent to Prefect Cloud by your worker/infra automatically.
- If you want third-party/library logs to appear in the run UI, emit them via get_run_logger() within the run (or configure logging to propagate appropriately—see guide below).
Docs:
- get_run_logger API
- get_logger API
- Logging guideNate
11/18/2025, 7:01 PM