4 * This file is part of the Monolog package.
6 * (c) Jordi Boggiano <j.boggiano@seld.be>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Monolog\Handler;
17 * Sends notifications through Slack's Slackbot
19 * @author Haralan Dobrev <hkdobrev@gmail.com>
20 * @see https://slack.com/apps/A0F81R8ET-slackbot
22 class SlackbotHandler extends AbstractProcessingHandler
25 * The slug of the Slack team
43 * @param string $slackTeam Slack team slug
44 * @param string $token Slackbot token
45 * @param string $channel Slack channel (encoded ID or name)
46 * @param int $level The minimum logging level at which this handler will be triggered
47 * @param bool $bubble Whether the messages that are handled can bubble up the stack or not
49 public function __construct($slackTeam, $token, $channel, $level = Logger::CRITICAL, $bubble = true)
51 parent::__construct($level, $bubble);
53 $this->slackTeam = $slackTeam;
54 $this->token = $token;
55 $this->channel = $channel;
61 * @param array $record
63 protected function write(array $record)
65 $slackbotUrl = sprintf(
66 'https://%s.slack.com/services/hooks/slackbot?token=%s&channel=%s',
73 curl_setopt($ch, CURLOPT_URL, $slackbotUrl);
74 curl_setopt($ch, CURLOPT_POST, true);
75 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
76 curl_setopt($ch, CURLOPT_POSTFIELDS, $record['message']);
78 Curl\Util::execute($ch);