No, setting the logger globally (i.e. at a module scope) is not supported. You should define the logger and log messages within your tasks and flows instead. The following will raise a
from prefect import get_run_logger logger = get_run_logger() logger.info("Starting the script...")
Traceback (most recent call last): File "/Users/xxx/repos/orion/example.py", line 3, in <module> logger = get_run_logger() File "/Users/xxx/repos/orion/src/prefect/logging/loggers.py", line 91, in get_run_logger raise RuntimeError("There is no active flow or task run context.") RuntimeError: There is no active flow or task run context.
To avoid such issues, set your logger and add your logs exclusively within tasks, flows, and subflows using the
get_run_logger function, as described in this topic:
Prefect 1.0 allows logging exclusively within tasks. Adding logs outside of Prefect tasks is not supported.