Robert Szomolanyi
03/17/2026, 4:48 PMMarvin
03/17/2026, 4:48 PMMarvin
03/17/2026, 4:53 PMprefect config set PREFECT_LOGGING_EXTRA_LOGGERS="pycdt"
- Or set the env var:
export PREFECT_LOGGING_EXTRA_LOGGERS=pycdt
2) Remove your manual handler addition:
# Do not do this — it causes duplicates if Prefect is also attaching a handler
# app_logger.addHandler(APILogHandler())
3) Just use the logger normally:
app_logger = logging.getLogger("pycdt")
app_logger.setLevel(<http://logging.INFO|logging.INFO>)
<http://app_logger.info|app_logger.info>("hello") # will appear once in the Prefect UI
If you must add the handler in code, guard against duplicates and disable propagation:
from prefect.logging.handlers import APILogHandler
import logging
app_logger = logging.getLogger("pycdt")
app_logger.propagate = False
if not any(isinstance(h, APILogHandler) for h in app_logger.handlers):
app_logger.addHandler(APILogHandler())
Docs and source:
- Logging customization (includes EXTRA_LOGGERS): How to customize Prefect logging
- APILogHandler reference: prefect.logging.handlers
- Default logging configuration code: configuration.py, logging.yml
Quick check to confirm the cause:
- Run your flow once, then inspect handlers at runtime:
logger = logging.getLogger("pycdt")
print(logger.handlers) # If you see two APILogHandler instances, that’s the duplication.
Question to confirm next step:
- Are the duplicates showing up in the Prefect UI, your console, or both? And do you have PREFECT_LOGGING_EXTRA_LOGGERS set or a custom logging.yml in your Prefect profile?