86 if (!extension_loaded(
'openssl')) {
100 if ($this->includeContextAndExtra && $this->useShortAttachment) {
140 'token' => $this->token,
141 'channel' => $this->channel,
142 'username' => $this->username,
144 'attachments' => array(),
147 if ($this->formatter) {
148 $message = $this->formatter->format($record);
150 $message = $record[
'message'];
153 if ($this->useAttachment) {
155 'fallback' => $message,
160 if ($this->useShortAttachment) {
161 $attachment[
'title'] = $record[
'level_name'];
162 $attachment[
'text'] = $message;
164 $attachment[
'title'] =
'Message';
165 $attachment[
'text'] = $message;
166 $attachment[
'fields'][] = array(
168 'value' => $record[
'level_name'],
173 if ($this->includeContextAndExtra) {
174 if (!empty($record[
'extra'])) {
175 if ($this->useShortAttachment) {
176 $attachment[
'fields'][] = array(
178 'value' => $this->
stringify($record[
'extra']),
179 'short' => $this->useShortAttachment,
183 foreach ($record[
'extra'] as $var => $val) {
184 $attachment[
'fields'][] = array(
187 'short' => $this->useShortAttachment,
193 if (!empty($record[
'context'])) {
194 if ($this->useShortAttachment) {
195 $attachment[
'fields'][] = array(
196 'title' =>
"Context",
197 'value' => $this->
stringify($record[
'context']),
198 'short' => $this->useShortAttachment,
202 foreach ($record[
'context'] as $var => $val) {
203 $attachment[
'fields'][] = array(
206 'short' => $this->useShortAttachment,
213 $dataArray[
'attachments'] = json_encode(array($attachment));
218 if ($this->iconEmoji) {
219 $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);
251 if (is_resource(
$res)) {
287 foreach ($fields as $var => $val) {
288 $string .= $var.
': '.$this->lineFormatter->stringify($val).
" | ";
291 $string = rtrim($string,
" |");
An exception for terminatinating execution or to throw for unit testing.
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.