This message was deleted.
# ask-marvin
s
This message was deleted.
m
To specify an exception handler for all of your flows and send exceptions to Slack, you can follow these steps: 1. Create a new logging handler in your
logging.yml
file. This file contains the existing log handlers: the
console
handler, and the
prefect server
handler that sends logs to the API. You can create a new handler that catches exceptions and sends them to Slack. Here is an example of what the
handlers
section might look like:
Copy code
yaml
handlers:
    console:
        level: 0
        class: prefect.logging.handlers.PrefectConsoleHandler
        formatter: standard
        styles:
            # styles omitted for brevity

    prefect server:
        level: 0
        class: prefect.logging.handlers.PrefectServerHandler

    slack:
        level: 0
        class: YourSlackHandlerClass # replace with your Slack handler class
        formatter: standard
2. Configure a notification in your Prefect server. Go to the Notifications page and select Create Notification or the + button. Notifications are structured just as you would describe them to someone. You can choose which run states should trigger a notification, tags to filter which flow runs are covered by the notification, and whether to send an email, a Slack message, Microsoft Teams message, or other services. For Slack notifications, the configuration requires webhook credentials for your Slack and the channel to which the message is sent. For example, to get a Slack message if a flow with a
daily-etl
tag fails, the notification will read: "If a run of
daily-etl
fails, send a Slack message to
#channel
." Please note that you will need to implement the Slack handler class (
YourSlackHandlerClass
in the example above) yourself. This class should inherit from the base logging.Handler class in Python's logging module, and override the
emit
method to send a message to Slack whenever it receives a log record. For more information, you can refer to these resources: - How to stream prefect logs to a file - Prefect Notifications Guide