<@ULVA73B9P> - if I use native python logging - do...
# marvin-ai
j
@Marvin - if I use native python logging - do those logs get passed to prefect server or do I have to use the prefect logger specifically to get logs into the prefect ui server
m
thought for 123.7 seconds
Short answer: Not by default. In Prefect 3.x, only logs emitted via
prefect.logging.get_run_logger()
(inside a running flow/task) are automatically sent to the Prefect API and shown in the UI. Plain
logging.getLogger(...)
won’t reach the UI unless you configure Prefect to capture those loggers or attach Prefect’s API log handler yourself. What to use: - Inside flows/tasks, prefer `get_run_logger()`:
Copy code
from prefect import flow, task
from prefect.logging import get_run_logger

@task
def do_work():
    logger = get_run_logger()
    <http://logger.info|logger.info>("This will appear in the Prefect UI")

@flow(log_prints=True)  # optional: capture print() as logs
def my_flow():
    do_work()
    print("This will also appear in the UI because log_prints=True")

if __name__ == "__main__":
    my_flow()
If you need to capture native/third‑party loggers: - Enable extra loggers via settings (so they’re wired to the API handler):
Copy code
export PREFECT_LOGGING_EXTRA_LOGGERS="myapp,urllib3"
- Or manually attach Prefect’s API log handler:
Copy code
import logging
from prefect.logging.handlers import APILogHandler

logger = logging.getLogger("myapp")
logger.setLevel(<http://logging.INFO|logging.INFO>)
logger.addHandler(APILogHandler())  # will send logs to the Prefect API when a run context is active
Notes: -
print()
is not logged unless you set
log_prints=True
on the `@flow`/`@task` decorator. -
prefect.logging.get_logger()
returns a standard logger with Prefect formatting, but it won’t send to the API unless you attach
APILogHandler
or include it in
PREFECT_LOGGING_EXTRA_LOGGERS
. Docs: - Add logging to flows and tasks - Advanced logging customization - prefect.logging.loggers API - prefect.logging.handlers API