【问题标题】:Send logs to Slack from Python从 Python 将日志发送到 Slack
【发布时间】:2019-03-18 20:48:01
【问题描述】:

是否可以将日志从内置 logging 模块重定向到 Slack 通道,而不是标准输出或文件。

我在想可能有一些方法可以使用 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】:

PyPI 上有一个包“slack-log-handler”。

它包含一个可供python日志模块使用的“LogHandler”。

【讨论】:

  • 我喜欢 slacker-log-handler 已经有一段时间了。然而,它现在似乎是一个死项目(20 年 10 月)。它强制six 回到 1.11.0,这在我的 python 3.8 虚拟环境中破坏了pip。它还利用了slacker python slack library,它本身已被存档/弃用。如果你走那条路,Caveat Emptor。
猜你喜欢
  • 2021-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-26
  • 1970-01-01
  • 2017-05-28
相关资源
最近更新 更多