webthink/monolog-slack
Composer 安装命令:
composer require webthink/monolog-slack
包简介
This package contains handlers/processors for sending logs of monolog to a slack channel.
README 文档
README
Notice I have created another package that contains a collection of Monolog handlers that can send your logs using a PSR-18 clients. The package is monolog-http
I will focus my efforts on the package above. If you are using the current package let me know WDYT.
Give a ⭐ to monolog-http if you like it.
Description
This is a package that can help you send logs through monolog to Slack using webhooks. Monolog already has a handler for Slack using Webhooks but I am not in favor of it for these reasons:
It has some bugs
- Slack accepts 2000 characters. For more details see. Current package is not able to send more than 2000 characters but it is able to send until 2000 characters and be well formatted.
Flexibility
- The Handler on this package allows you to pass your own PSR-18 client that can be configured in your own way.
Performance
- SlackWebhookHandler does not have timeouts and it executes retries when slack service is down see Because you are allowed to pass your own PSR-18 client you can have it configured in your own way.
Formatting
- Current package gives you the ability to add a custom formatter to the
SlackwebhookHandlerin order to format Attachments. Monolog allows you to pass a formatter to SlackHandlers but the formatter is applied only to simple messages of slack and they are not applied for Attachments. - I have created my own custom formatters. I like the formatting of Slack Records that I have more than the one that monolog has.
Install
You can install this package through composer
$ composer require webthink/monolog-slack
Documentation
Simple initialization
You can initialize a SlackWebhookHandler simple with the following lines:
$client = new PSR18Client(); // PSR18Client does not exist. Use your own implementation. $requestFactory = new PSR17RequestFactory(); // PSR18Client does not exist. Use your own implementation. $handler = new SlackWebhookHandler($client, $requestFactory, 'your_webhook_url');
Formatters
Inject custom formatter
Now if you need to pass a custom slack formatter then you can to do the following:
$handler->setFormatter($yourFormatter);
- Note-1: The formatter passed inside the slack handler must be an instance of
SlackFormatterInterface. - Note-2: If you do not pass a custom Formatter SlackWebhookHandler uses the
SlackLineFormatterby default.
SlackLineFormatter
SlackShortAttachmentFormatter
SlackLongAttachmentFormatter
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
- Run
composer installfrom bash. - Run
composer testsfrom bash.
webthink/monolog-slack 适用场景与选型建议
webthink/monolog-slack 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 105.46k 次下载、GitHub Stars 达 11, 最近一次更新时间为 2018 年 03 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 webthink/monolog-slack 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 webthink/monolog-slack 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 105.46k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-03-24