Andreas Nord
03/18/2024, 3:00 PMMarvin
03/18/2024, 3:00 PMPREFECT_LOGGING_[PATH]_[TO]_[KEY]
, where [PATH]_[TO]_[KEY]
corresponds to the nested address of the logging setting you want to change.
Here's an example of how to set the log level to DEBUG; you can adapt it to set it to WARNING:
python
import os
# Set environment variable for logging level to WARNING
os.environ["PREFECT_LOGGING_LEVEL"] = "WARNING"
Before starting your flow run, make sure to set the above environment variable in your Python environment or in the operating system. This will modify the logging level for the entire flow run.
For more details on Prefect logging and how to configure it, you can visit the Prefect documentation.
If you want to set the log level for a more granular scope or just for a specific task run, you can use the get_run_logger
method to retrieve a logger instance and then set its level:
python
from prefect import get_run_logger
logger = get_run_logger()
logger.setLevel("WARNING")
Although not explicitly stated in the documentation excerpts provided, the get_run_logger
approach is commonly used within tasks to control the logging level for individual task runs.