Paweł Biernat
12/05/2024, 9:43 AMFinished in state Completed() .Marvin
12/05/2024, 9:44 AMINFO level. You can adjust this setting in your Prefect configuration to a higher level like WARNING or ERROR to suppress INFO level logs, which include task completion messages. This configuration can be set globally or specifically for certain tasks and flows. This means you won't see the "Finished in state Completed()" logs. Here's more about this: Prefect 2.x Logging and Prefect 3.x Logging.
2. Using log_prints Option: Prefect provides the log_prints=False option at both the task and flow levels to disable automatic logging of print statements. While this is slightly different from your current request, it's good to know about such features if you ever want to disable print statement logs specifically.
You can explore the links provided to get a deeper understanding of how to customize your logging settings. This should help minimize the log output to your liking. Don't we all wish we could just tell our programs to keep things to themselves sometimes?
If you need further assistance configuring these, feel free to ask!Paweł Biernat
12/05/2024, 9:47 AMMarvin
12/05/2024, 9:47 AMtask.map in Prefect 3, you will use Python's standard logging configuration. Here's a simple example to help guide you:
python
import logging
from prefect import flow, task, get_run_logger
# Configure the root logger. This is a global change.
logging.basicConfig(level=logging.WARNING)
@task
def my_task(x):
logger = get_run_logger()
<http://logger.info|logger.info>(f"Processing {x}")
return x * 2
@flow
def my_flow():
# Temporarily change the log level
logger = logging.getLogger("prefect")
previous_level = logger.level
logger.setLevel(logging.WARNING) # Set a higher level to suppress INFO logs
results = my_task.map(range(10)) # Logs from these tasks will be at WARNING level
logger.setLevel(previous_level) # Reset back to the previous level
return results
if __name__ == "__main__":
my_flow()
In this example, I've changed the logging level to WARNING before the task.map call to suppress INFO-level logs like "Finished in state Completed()". After the map, it resets to the previous logging level.
For more about configuring Prefect's logging, you can refer to the Prefect 3.x Logging Documentation.
Who knew teaching a task to "shhh!" could be so rewarding?