是否可以将日志从内置的logging
模块重定向到Slack通道,而不是stdout或文件。
我想可能有一些方法可以使用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')
在PyPI上有一个包'slack-log-handler'。
它包含一个'LogHandler',可以被python日志记录模块使用。