/** * {@inheritdoc} * * @param array $record */ protected function write(array $record) { $postData = $this->slackRecord->getSlackData($record); $postString = json_encode($postData); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $this->webhookUrl); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); if (defined('CURLOPT_SAFE_UPLOAD')) { curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true); } curl_setopt($ch, CURLOPT_POSTFIELDS, array('payload' => $postString)); Curl\Util::execute($ch); }
/** * Prepares content data * * @param array $record * @return array */ protected function prepareContentData($record) { $dataArray = $this->slackRecord->getSlackData($record); $dataArray['token'] = $this->token; if (!empty($dataArray['attachments'])) { $dataArray['attachments'] = json_encode($dataArray['attachments']); } return $dataArray; }
public function testAddsLongAttachmentWithContextAndExtra() { $level = Logger::ERROR; $levelName = Logger::getLevelName($level); $record = new SlackRecord($this->channel, 'Monolog', true, null, false, true); $loggerRecord = $this->getRecord($level, 'test', array('test' => 1)); $loggerRecord['extra'] = array('tags' => array('web')); $data = $record->getSlackData($loggerRecord); $expectedFields = array(array('title' => 'Level', 'value' => $levelName, 'short' => true), array('title' => 'tags', 'value' => '["web"]', 'short' => false), array('title' => 'test', 'value' => 1, 'short' => false)); $attachment = $data['attachments'][0]; $this->assertArrayHasKey('title', $attachment); $this->assertArrayHasKey('fields', $attachment); $this->assertCount(3, $attachment['fields']); $this->assertSame('Message', $attachment['title']); $this->assertSame($expectedFields, $attachment['fields']); }