-
First off install the python package
slacker-log-handler
and add it to your requirements file.flask ... slacker-log-handler
-
Generate a slack token.
-
Add a
SlackLogHandler
instance to your app logger, I use the layout mentioned in the flask docs.if not app.debug: from slacker_log_handler import SlackerLogHandler slack_handler = SlackerLogHandler('YOUR-SLACK-TOKEN', 'YOUR-SLACK-CHANNEL', stack_trace=True, username='USERNAME (like: site-bot)') slack_handler.setFormatter(Formatter(app.config['LOGGING_FORMAT'])) file_handler.setLevel(logging.ERROR) app.logger.addHandler(slack_handler)
-
To test your integration, open a flask shell and type something like this:
from app import app app.logging.error("ERROR")
... A message should pop up in your the slack channel you specified.
-
Done!
Last active
May 9, 2021 04:20
-
-
Save marteinn/18bd85db1a908361858ab6976294680d to your computer and use it in GitHub Desktop.
Logging Flask Exceptions to Slack
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment