devorto/slack-logger

使用 Psr/LoggerInterface 将错误/通知等信息记录到 Slack。

1.0.1 2019-10-25 10:34 UTC

This package is auto-updated.

Last update: 2024-09-25 21:53:13 UTC


README

使用此实现 Prs/Log/LoggerInterface 的类将错误/通知/警告等信息发送到 Slack。

有关日志接口或日志级别的更多信息,请参阅 他们的github

设置 webhook

在使用此功能之前,您需要在 Slack 中设置 webhook 应用程序并将其连接到您想要使用的频道。

  1. 转到 https://api.slack.com/apps
  2. 点击右上角的“新建应用”按钮。
  3. 填写“应用名称”(这将是 Slack 中的发送者名称)
  4. 填写您想要安装的“开发 Slack 工作空间”。
  5. 点击“创建应用”。
  6. 在“添加功能和功能”部分中选择“入站 Webhooks”。
  7. 将右侧的“激活入站 Webhooks”设置为“开启”。
  8. 这将展开新的选项,现在点击页面底部的“添加新 Webhook 到工作空间”。
  9. 这将带您到一个新页面,选择您想要消息发布的频道。
  10. 点击“安装”。
  11. 这将带您回到 webhook 页面,现在在页面底部复制 webhook URL。这个 URL 是下面示例中所需的。

示例

<?php

$slack = new \Devorto\Logger\Slack(
	'<paste-webhook-url-here>',
	'My Test App',
	'https://test.example.com' // Optional app url.
);

// Use one of the available log level methods:
$slack->critical('Help something went critical.');

// You can also drop an Exception in here.
$slack->critical(new Exception('Test'));

在 Slack 中生成此内容: Example