Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send logs to Slack from Python

Is it possible to redirect logs from the built in logging module to a Slack channel, rather than stdout or a file.

I was thinking there might be some way to do this using the Slack API client:

import logging
from slackclient import SlackClient

slack_token = 'MY-TOKEN-HERE'
sc = SlackClient(slack_token)

logging.basicConfig(...)  # Some slack magic???

logging.debug('This message should go to a slack channel')
logging.info('So should this')
logging.warning('And this, too')
like image 955
snakeoilsales Avatar asked Oct 28 '25 08:10

snakeoilsales


1 Answers

There is a package ‘slack-log-handler’ on PyPI.

It contains a ‘LogHandler’ which can be used by the python logging module.

like image 198
rfkortekaas Avatar answered Oct 31 '25 00:10

rfkortekaas