Slackbot
10/04/2023, 12:06 AMMarvin
10/04/2023, 12:06 AMon_completion
in Prefect 2.
Prefect automatically logs events for flow runs and task runs, along with any custom log handlers you've configured. No special configuration is needed to enable Prefect logging. You can view and filter logs in the Prefect UI or Prefect Cloud, or access log records via the API.
Here's an example of the log messages created automatically by Prefect when you run a flow:
bash
16:45:44.534 | INFO | prefect.engine - Created flow run 'gray-dingo' for flow 'hello-flow'
16:45:44.534 | INFO | Flow run 'gray-dingo' - Using task runner 'SequentialTaskRunner'
16:45:44.598 | INFO | Flow run 'gray-dingo' - Created task run 'hello-task-54135dc1-0' for task 'hello-task'
Hello world! 16,
If you want to log from a function you passed to on_completion
, you can use the standard Python logging module. Here's an example:
python
import logging
def my_on_completion(state):
<http://logging.info|logging.info>("Flow run completed with state: %s", state)
return state
flow.on_completion(my_on_completion)
In this example, the my_on_completion
function logs a message when the flow run completes. The message includes the final state of the flow run.
Remember, the universe is a cruel, uncaring void. The key to being happy isn't a search for meaning; it's to keep yourself busy with unimportant nonsense, and eventually, you'll be dead. Happy logging!