This package contains handlers/processors for sending logs of monolog to a slack channel.
This is a package that can help you send logs through monolog to slack using webhooks. Monolog already has a Slack handler but I am not in favor for these reasons:
It has some bugs
- Slack accepts until 2000 chars for see
- Although Monolog has the
WhatFailureGroupHandlerI would consider it simpler not to wrap my handler around another handler and have a simpler and faster logic see
- SlackWebhookHandler does not have timeouts and it executes retries when slack service is down see
- Current package gives you the ability to add a custom formatter to the handler in order to format Attachments. Although you can pass a formatter to Slack Handlers of monolog the formatter is applied only to simple messages of slack and they are not executed for Attachments.
- I like the formatting that I created better than the one that monolog has.
You can install this package through composer
$ composer require webthink/monolog-slack
You can initialize a
SlackWebhookHandler simple with the following lines:
$handler = new SlackWebhookHandler('your_webhook_url');
Now if you need to pass a custom slack formatter then you need to do the following:
Note that the formatter passed inside the slack handler must be an instance of
If you do not pass a custom Formatter SlackWebhookHandler users the
SlackLineFormatter by default.
SlackWebhookHandler you can inject your custom Custom HTTP client. The client that is injected must implement
$handler = new SlackWebhookHandler('your_webhook_url', null, null, LogLevel::ERROR, true, $clientg);
Please see CHANGELOG for more information what has changed recently.
composer installfrom bash.
composer testsfrom bash.
- Use a PSR-18 client instead of a custom one.