The solution from Michael!
from prefect import flow, task
from logging import getLogger
logger = getLogger("my-logger")
logger.setLevel("INFO")
@task
def my_task():
logger.info("Hello from the task")
@flow
def my_flow():
logger.info("Hello from the flow")
my_task()
my_flow()
Then run the flow with these environment variables:
PREFECT_LOGGING_LEVEL=WARNING PREFECT_LOGGING_EXTRA_LOGGERS=my-logger python flow.py
Results in only the custom loggers
12:40:19.285 | INFO | my-logger - Hello from the flow
12:40:19.315 | INFO | my-logger - Hello from the task