[GH-ISSUE #514] Use Monolog with Slack #178

Closed
opened 2026-03-04 02:12:54 +03:00 by kerem · 10 comments
Owner

Originally created by @thangngoc89 on GitHub (Feb 25, 2015).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/514

I am using Laravel 5 and I have some issues with Slack Handler integration.
I set up a ChromePHP Handler and It works perfectly so I assume there is no problems with Laravel.

This is the way I set up Slack Handler

$monolog = Log::getMonolog();

$monolog->pushHandler($chromeHandler = new \Monolog\Handler\ChromePHPHandler());
$chromeHandler->setFormatter(new \Monolog\Formatter\ChromePHPFormatter());

$slackHandler = new \Monolog\Handler\SlackHandler('my-api-token', 'general');
$monolog->pushHandler($slackHandler);
$slackHandler->setFormatter(new \Monolog\Formatter\LineFormatter());

I get my api token from https://api.slack.com/web#auth.
Is there anything wrong with my config?
At the same time, ChromePHP works and Slack doesn't work.
I really can't make Monolog work with Slack.

Originally created by @thangngoc89 on GitHub (Feb 25, 2015). Original GitHub issue: https://github.com/Seldaek/monolog/issues/514 I am using Laravel 5 and I have some issues with Slack Handler integration. I set up a ChromePHP Handler and It works perfectly so I assume there is no problems with Laravel. This is the way I set up Slack Handler ``` php $monolog = Log::getMonolog(); $monolog->pushHandler($chromeHandler = new \Monolog\Handler\ChromePHPHandler()); $chromeHandler->setFormatter(new \Monolog\Formatter\ChromePHPFormatter()); $slackHandler = new \Monolog\Handler\SlackHandler('my-api-token', 'general'); $monolog->pushHandler($slackHandler); $slackHandler->setFormatter(new \Monolog\Formatter\LineFormatter()); ``` I get my api token from https://api.slack.com/web#auth. Is there anything wrong with my config? At the same time, ChromePHP works and Slack doesn't work. I really can't make Monolog work with Slack.
kerem closed this issue 2026-03-04 02:12:54 +03:00
Author
Owner

@Seldaek commented on GitHub (Feb 28, 2015):

Seems correct, but note that by default it logs only CRITICAL messages and above, so maybe you want to call ->setLevel on the handler as well to lower that to \Monolog\Logger::ERROR or something. That could explain why you don't get any messages on it.

<!-- gh-comment-id:76547477 --> @Seldaek commented on GitHub (Feb 28, 2015): Seems correct, but note that by default it logs only CRITICAL messages and above, so maybe you want to call `->setLevel` on the handler as well to lower that to `\Monolog\Logger::ERROR` or something. That could explain why you don't get any messages on it.
Author
Owner

@wodCZ commented on GitHub (Mar 9, 2015):

channel name must include the hashtag, so in your case:
$slackHandler = new \Monolog\Handler\SlackHandler('my-api-token', '#general');

<!-- gh-comment-id:77855564 --> @wodCZ commented on GitHub (Mar 9, 2015): channel name must include the hashtag, so in your case: `$slackHandler = new \Monolog\Handler\SlackHandler('my-api-token', '#general');`
Author
Owner

@thangngoc89 commented on GitHub (Mar 9, 2015):

@wodCZ I tried that, and setLevel to 100 / debug .... I gave up

<!-- gh-comment-id:77858393 --> @thangngoc89 commented on GitHub (Mar 9, 2015): @wodCZ I tried that, and setLevel to 100 / debug .... I gave up
Author
Owner

@wodCZ commented on GitHub (Mar 9, 2015):

@thangngoc89 try putting echo fread($this->resource, 1000); in Monolog/Handler/SocketHandler at line 243 end of method writeToSocket - this way I got response from Slack - that was that about nonexisting channel.

<!-- gh-comment-id:77859012 --> @wodCZ commented on GitHub (Mar 9, 2015): @thangngoc89 try putting `echo fread($this->resource, 1000);` in Monolog/Handler/SocketHandler at line 243 end of method `writeToSocket` - this way I got response from Slack - that was that about nonexisting channel.
Author
Owner

@thangngoc89 commented on GitHub (Mar 9, 2015):

@wodCZ Thanks you. Let's me try it

<!-- gh-comment-id:77859126 --> @thangngoc89 commented on GitHub (Mar 9, 2015): @wodCZ Thanks you. Let's me try it
Author
Owner

@thangngoc89 commented on GitHub (Mar 9, 2015):

@wodCZ now it works. I have no idea why it is?
I will push this to production server and hoping. ......

<!-- gh-comment-id:77860538 --> @thangngoc89 commented on GitHub (Mar 9, 2015): @wodCZ now it works. I have no idea why it is? I will push this to production server and hoping. ......
Author
Owner

@wodCZ commented on GitHub (Mar 9, 2015):

@thangngoc89 maybe some cache or whatever :)

<!-- gh-comment-id:77860790 --> @wodCZ commented on GitHub (Mar 9, 2015): @thangngoc89 maybe some cache or whatever :)
Author
Owner

@thangngoc89 commented on GitHub (Mar 9, 2015):

@wodCZ Yeah. Maybe. But anyway. Yeah

<!-- gh-comment-id:77861086 --> @thangngoc89 commented on GitHub (Mar 9, 2015): @wodCZ Yeah. Maybe. But anyway. Yeah
Author
Owner

@mprandot commented on GitHub (Jul 27, 2016):

where is 'api-key'? i can't find in slack documentation! 👎

<!-- gh-comment-id:235577128 --> @mprandot commented on GitHub (Jul 27, 2016): where is 'api-key'? i can't find in slack documentation! :-1:
Author
Owner

@fhusquinet commented on GitHub (Jul 29, 2016):

@mprandot
Info about authentication is here: https://api.slack.com/web

<!-- gh-comment-id:236141582 --> @fhusquinet commented on GitHub (Jul 29, 2016): @mprandot Info about authentication is here: https://api.slack.com/web
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/monolog#178
No description provided.