85 if (!extension_loaded(
'openssl')) {
98 if ($this->includeContextAndExtra) {
126 return http_build_query($dataArray);
138 'token' => $this->token,
139 'channel' => $this->channel,
140 'username' => $this->username,
142 'attachments' => array()
145 if ($this->useAttachment) {
147 'fallback' => $record[
'message'],
151 if ($this->useShortAttachment) {
152 $attachment[
'fields'] = array(
154 'title' => $record[
'level_name'],
155 'value' => $record[
'message'],
160 $attachment[
'fields'] = array(
162 'title' =>
'Message',
163 'value' => $record[
'message'],
168 'value' => $record[
'level_name'],
174 if ($this->includeContextAndExtra) {
175 if (!empty($record[
'extra'])) {
176 if ($this->useShortAttachment) {
177 $attachment[
'fields'][] = array(
179 'value' => $this->
stringify($record[
'extra']),
180 'short' => $this->useShortAttachment
184 foreach ($record[
'extra'] as $var => $val) {
185 $attachment[
'fields'][] = array(
188 'short' => $this->useShortAttachment
194 if (!empty($record[
'context'])) {
195 if ($this->useShortAttachment) {
196 $attachment[
'fields'][] = array(
197 'title' =>
"Context",
198 'value' => $this->
stringify($record[
'context']),
199 'short' => $this->useShortAttachment
203 foreach ($record[
'context'] as $var => $val) {
204 $attachment[
'fields'][] = array(
207 'short' => $this->useShortAttachment
214 $dataArray[
'attachments'] = json_encode(array($attachment));
216 $dataArray[
'text'] = $record[
'message'];
219 if ($this->iconEmoji) {
220 $dataArray[
'icon_emoji'] =
":{$this->iconEmoji}:";
233 $header =
"POST /api/chat.postMessage HTTP/1.1\r\n";
234 $header .=
"Host: slack.com\r\n";
235 $header .=
"Content-Type: application/x-www-form-urlencoded\r\n";
236 $header .=
"Content-Length: " . strlen($content) .
"\r\n";
247 protected function write(array $record)
249 parent::write($record);
284 foreach ($fields as $var => $val) {
285 $string .= $var.
': '.$this->lineFormatter->stringify($val).
" | ";
288 $string = rtrim($string,
" |");
Exception can be thrown if an extension for an handler is missing.
Sends notifications through Slack API.
buildContent($record)
Builds the body of API call.
getAttachmentColor($level)
Returned a Slack message attachment color associated with provided level.
__construct($token, $channel, $username='Monolog', $useAttachment=true, $iconEmoji=null, $level=Logger::CRITICAL, $bubble=true, $useShortAttachment=false, $includeContextAndExtra=false)
stringify($fields)
Stringifies an array of key/value pairs to be used in attachment fields.
write(array $record)
{Connect (if necessary) and write to the socket.UnexpectedValueException RuntimeException}
buildHeader($content)
Builds the header of the API Call.
prepareContentData($record)
Prepares content data.
generateDataStream($record)
{}
Stores to any socket - uses fsockopen() or pfsockopen().
closeSocket()
Close socket, if open.
const ERROR
Runtime errors.
const CRITICAL
Critical conditions.
const WARNING
Exceptional occurrences that are not errors.
const INFO
Interesting events.