From 976259bb5b789b2ccfa60b23f6d3283662f52c35 Mon Sep 17 00:00:00 2001 From: raph Date: Thu, 17 Sep 2015 09:52:52 +0200 Subject: [PATCH] Use `text` and `title` fields for SlackHandler According to slack documentation (https://api.slack.com/docs/attachments), an attachment may have a title and a text. The log message and title should use these fields. One of the benefits of using these two properties instead of adding a field is that it's shortened (with a "show more" button) and expandable by slack. It adds a bit of hierarchy in the attachement. Message is the content. Extra and context are additional fields. --- src/Monolog/Handler/SlackHandler.php | 29 ++++++++++------------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/src/Monolog/Handler/SlackHandler.php b/src/Monolog/Handler/SlackHandler.php index 643b003b..61245ffa 100644 --- a/src/Monolog/Handler/SlackHandler.php +++ b/src/Monolog/Handler/SlackHandler.php @@ -145,29 +145,20 @@ class SlackHandler extends SocketHandler if ($this->useAttachment) { $attachment = array( 'fallback' => $record['message'], - 'color' => $this->getAttachmentColor($record['level']) + 'color' => $this->getAttachmentColor($record['level']), + 'fields' => array() ); if ($this->useShortAttachment) { - $attachment['fields'] = array( - array( - 'title' => $record['level_name'], - 'value' => $record['message'], - 'short' => false - ) - ); + $attachment['title'] = $record['level_name']; + $attachment['text'] = $record['message']; } else { - $attachment['fields'] = array( - array( - 'title' => 'Message', - 'value' => $record['message'], - 'short' => false - ), - array( - 'title' => 'Level', - 'value' => $record['level_name'], - 'short' => true - ) + $attachment['title'] = 'Message'; + $attachment['text'] = $record['message']; + $attachment['fields'][] = array( + 'title' => 'Level', + 'value' => $record['level_name'], + 'short' => true ); }