从Python发送日志到Slack

问题描述 投票:0回答:1

是否可以将日志从内置的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')
python python-3.x logging slack
1个回答
1
投票

PyPI上有一个包'slack-log-handler'。

它包含一个'LogHandler',可以被python日志记录模块使用。

© www.soinside.com 2019 - 2024. All rights reserved.