[GH-ISSUE #1332] Monolog Slack handler is not working #556

Closed
opened 2026-03-04 02:15:57 +03:00 by kerem · 5 comments
Owner

Originally created by @moda20 on GitHub (Jun 12, 2019).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/1332

hey !

I am trying to use slack handler in monolog but couldn't make it to work.

I created an APi key and integrated the app in my channel and gave it writes to write in it via the slack Web interface.

and i am using this code to send the error :
Note: this is a test code.

$slackHandler = new \Monolog\Handler\SlackHandler('xoxp********', '#debugerrors');
$slackHandler->setLevel(\Monolog\Logger::ERROR);
$slacklogger = new Monolog\Logger("debugerrors");
$slacklogger->pushHandler($slackHandler);
$Messages ="Logging";
$slacklogger->error($Messages);

I just ook that code straight from a tutorial, so I don't see where I could have gone wrong.

is this a recurring problem with slack ? emails and file saving do work.

Originally created by @moda20 on GitHub (Jun 12, 2019). Original GitHub issue: https://github.com/Seldaek/monolog/issues/1332 hey ! I am trying to use slack handler in monolog but couldn't make it to work. I created an APi key and integrated the app in my channel and gave it writes to write in it via the slack Web interface. and i am using this code to send the error : Note: this is a test code. ``` $slackHandler = new \Monolog\Handler\SlackHandler('xoxp********', '#debugerrors'); $slackHandler->setLevel(\Monolog\Logger::ERROR); $slacklogger = new Monolog\Logger("debugerrors"); $slacklogger->pushHandler($slackHandler); $Messages ="Logging"; $slacklogger->error($Messages); ``` I just ook that code straight from a tutorial, so I don't see where I could have gone wrong. is this a recurring problem with slack ? emails and file saving do work.
kerem 2026-03-04 02:15:57 +03:00
  • closed this issue
  • added the
    Support
    label
Author
Owner

@matthewpoer commented on GitHub (Jul 3, 2019):

I had issues with SlackHandler but found the SlackWebhookHandler very easy to work with, e.g.:

$this->log = new Monolog\Logger('log title');
$this->log->pushHandler(new Monolog\Handler\SlackWebhookHandler(
  SLACK_WEBHOOK_URL, // create URL in https://your-slack-app.slack.com/apps/A0F7XDUAZ-incoming-webhooks
  SLACK_CHANNEL, // e.g. #general
  'someUsername', // username, no @ prefix, can be made-up
  true, // use-attachment flag, affects formatting of message
  'red_circle', // iconEmoji flag, the avatar associated with the message, can be a custom icon
  false, // useShortAttachment flag, affects formatting of the message
  true, // includeContextAndExtra, how much of the context is sent into Slack channel
  Logger::WARNING // level of message to send in to Slack
));

<!-- gh-comment-id:508103805 --> @matthewpoer commented on GitHub (Jul 3, 2019): I had issues with `SlackHandler` but found the `SlackWebhookHandler` very easy to work with, e.g.: ```php $this->log = new Monolog\Logger('log title'); $this->log->pushHandler(new Monolog\Handler\SlackWebhookHandler( SLACK_WEBHOOK_URL, // create URL in https://your-slack-app.slack.com/apps/A0F7XDUAZ-incoming-webhooks SLACK_CHANNEL, // e.g. #general 'someUsername', // username, no @ prefix, can be made-up true, // use-attachment flag, affects formatting of message 'red_circle', // iconEmoji flag, the avatar associated with the message, can be a custom icon false, // useShortAttachment flag, affects formatting of the message true, // includeContextAndExtra, how much of the context is sent into Slack channel Logger::WARNING // level of message to send in to Slack )); ```
Author
Owner

@pnoeric commented on GitHub (Oct 2, 2019):

Just to add to what @matthewpoer said - yeah, SlackHandler seems out of date and non-functional, but SlackWebhookHandler works great and is very easy to set up on the Slack side.

<!-- gh-comment-id:537435475 --> @pnoeric commented on GitHub (Oct 2, 2019): Just to add to what @matthewpoer said - yeah, `SlackHandler` seems out of date and non-functional, but `SlackWebhookHandler` works great and is very easy to set up on the Slack side.
Author
Owner

@seferov commented on GitHub (Oct 30, 2019):

I just integrated Monolog\Handler\SlackHandler and it works!

$logger = new Logger('jira-ci');
$logger->pushHandler(new SlackHandler(
    getenv('SLACK_TOKEN'),
    getenv('SLACK_CHANNEL'),
    getenv('SLACK_USERNAME'),
    true,
    null,
    Logger::INFO
));
$logger->info('lorem ipsum');
<!-- gh-comment-id:547875826 --> @seferov commented on GitHub (Oct 30, 2019): I just integrated `Monolog\Handler\SlackHandler` and it works! ```php $logger = new Logger('jira-ci'); $logger->pushHandler(new SlackHandler( getenv('SLACK_TOKEN'), getenv('SLACK_CHANNEL'), getenv('SLACK_USERNAME'), true, null, Logger::INFO )); $logger->info('lorem ipsum'); ```
Author
Owner

@gmponos commented on GitHub (Dec 20, 2019):

If you guys are interested I have also created a package like this: https://github.com/gmponos/monolog-slack/

<!-- gh-comment-id:567855489 --> @gmponos commented on GitHub (Dec 20, 2019): If you guys are interested I have also created a package like this: https://github.com/gmponos/monolog-slack/
Author
Owner

@dinoluck commented on GitHub (Aug 11, 2021):

Since Slack deprecated Incoming Webhooks, is there a way to get SlackHandler working?

<!-- gh-comment-id:896988215 --> @dinoluck commented on GitHub (Aug 11, 2021): Since Slack deprecated Incoming Webhooks, is there a way to get SlackHandler working?
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#556
No description provided.