|
| 1 | +diff -Nuar a/vendor/monolog/monolog/src/Monolog/Handler/SlackHandler.php b/vendor/monolog/monolog/src/Monolog/Handler/SlackHandler.php |
| 2 | +index 643b003..ac2af02 100644 |
| 3 | +--- a/vendor/monolog/monolog/src/Monolog/Handler/SlackHandler.php |
| 4 | ++++ b/vendor/monolog/monolog/src/Monolog/Handler/SlackHandler.php |
| 5 | +@@ -70,15 +70,16 @@ class SlackHandler extends SocketHandler |
| 6 | + private $lineFormatter; |
| 7 | + |
| 8 | + /** |
| 9 | +- * @param string $token Slack API token |
| 10 | +- * @param string $channel Slack channel (encoded ID or name) |
| 11 | +- * @param string $username Name of a bot |
| 12 | +- * @param bool $useAttachment Whether the message should be added to Slack as attachment (plain text otherwise) |
| 13 | +- * @param string|null $iconEmoji The emoji name to use (or null) |
| 14 | +- * @param int $level The minimum logging level at which this handler will be triggered |
| 15 | +- * @param bool $bubble Whether the messages that are handled can bubble up the stack or not |
| 16 | +- * @param bool $useShortAttachment Whether the the context/extra messages added to Slack as attachments are in a short style |
| 17 | +- * @param bool $includeContextAndExtra Whether the attachment should include context and extra data |
| 18 | ++ * @param string $token Slack API token |
| 19 | ++ * @param string $channel Slack channel (encoded ID or name) |
| 20 | ++ * @param string $username Name of a bot |
| 21 | ++ * @param bool $useAttachment Whether the message should be added to Slack as attachment (plain text otherwise) |
| 22 | ++ * @param string|null $iconEmoji The emoji name to use (or null) |
| 23 | ++ * @param int $level The minimum logging level at which this handler will be triggered |
| 24 | ++ * @param bool $bubble Whether the messages that are handled can bubble up the stack or not |
| 25 | ++ * @param bool $useShortAttachment Whether the the context/extra messages added to Slack as attachments are in a short style |
| 26 | ++ * @param bool $includeContextAndExtra Whether the attachment should include context and extra data |
| 27 | ++ * @throws MissingExtensionException If no OpenSSL PHP extension configured |
| 28 | + */ |
| 29 | + public function __construct($token, $channel, $username = 'Monolog', $useAttachment = true, $iconEmoji = null, $level = Logger::CRITICAL, $bubble = true, $useShortAttachment = false, $includeContextAndExtra = false) |
| 30 | + { |
| 31 | +@@ -95,7 +96,8 @@ class SlackHandler extends SocketHandler |
| 32 | + $this->useAttachment = $useAttachment; |
| 33 | + $this->useShortAttachment = $useShortAttachment; |
| 34 | + $this->includeContextAndExtra = $includeContextAndExtra; |
| 35 | +- if ($this->includeContextAndExtra) { |
| 36 | ++ |
| 37 | ++ if ($this->includeContextAndExtra && $this->useShortAttachment) { |
| 38 | + $this->lineFormatter = new LineFormatter; |
| 39 | + } |
| 40 | + } |
| 41 | +@@ -139,35 +141,26 @@ class SlackHandler extends SocketHandler |
| 42 | + 'channel' => $this->channel, |
| 43 | + 'username' => $this->username, |
| 44 | + 'text' => '', |
| 45 | +- 'attachments' => array() |
| 46 | ++ 'attachments' => array(), |
| 47 | + ); |
| 48 | + |
| 49 | + if ($this->useAttachment) { |
| 50 | + $attachment = array( |
| 51 | + 'fallback' => $record['message'], |
| 52 | +- 'color' => $this->getAttachmentColor($record['level']) |
| 53 | ++ 'color' => $this->getAttachmentColor($record['level']), |
| 54 | ++ 'fields' => array(), |
| 55 | + ); |
| 56 | + |
| 57 | + if ($this->useShortAttachment) { |
| 58 | +- $attachment['fields'] = array( |
| 59 | +- array( |
| 60 | +- 'title' => $record['level_name'], |
| 61 | +- 'value' => $record['message'], |
| 62 | +- 'short' => false |
| 63 | +- ) |
| 64 | +- ); |
| 65 | ++ $attachment['title'] = $record['level_name']; |
| 66 | ++ $attachment['text'] = $record['message']; |
| 67 | + } else { |
| 68 | +- $attachment['fields'] = array( |
| 69 | +- array( |
| 70 | +- 'title' => 'Message', |
| 71 | +- 'value' => $record['message'], |
| 72 | +- 'short' => false |
| 73 | +- ), |
| 74 | +- array( |
| 75 | +- 'title' => 'Level', |
| 76 | +- 'value' => $record['level_name'], |
| 77 | +- 'short' => true |
| 78 | +- ) |
| 79 | ++ $attachment['title'] = 'Message'; |
| 80 | ++ $attachment['text'] = $record['message']; |
| 81 | ++ $attachment['fields'][] = array( |
| 82 | ++ 'title' => 'Level', |
| 83 | ++ 'value' => $record['level_name'], |
| 84 | ++ 'short' => true, |
| 85 | + ); |
| 86 | + } |
| 87 | + |
| 88 | +@@ -177,7 +170,7 @@ class SlackHandler extends SocketHandler |
| 89 | + $attachment['fields'][] = array( |
| 90 | + 'title' => "Extra", |
| 91 | + 'value' => $this->stringify($record['extra']), |
| 92 | +- 'short' => $this->useShortAttachment |
| 93 | ++ 'short' => $this->useShortAttachment, |
| 94 | + ); |
| 95 | + } else { |
| 96 | + // Add all extra fields as individual fields in attachment |
| 97 | +@@ -185,7 +178,7 @@ class SlackHandler extends SocketHandler |
| 98 | + $attachment['fields'][] = array( |
| 99 | + 'title' => $var, |
| 100 | + 'value' => $val, |
| 101 | +- 'short' => $this->useShortAttachment |
| 102 | ++ 'short' => $this->useShortAttachment, |
| 103 | + ); |
| 104 | + } |
| 105 | + } |
| 106 | +@@ -196,7 +189,7 @@ class SlackHandler extends SocketHandler |
| 107 | + $attachment['fields'][] = array( |
| 108 | + 'title' => "Context", |
| 109 | + 'value' => $this->stringify($record['context']), |
| 110 | +- 'short' => $this->useShortAttachment |
| 111 | ++ 'short' => $this->useShortAttachment, |
| 112 | + ); |
| 113 | + } else { |
| 114 | + // Add all context fields as individual fields in attachment |
| 115 | +@@ -204,7 +197,7 @@ class SlackHandler extends SocketHandler |
| 116 | + $attachment['fields'][] = array( |
| 117 | + 'title' => $var, |
| 118 | + 'value' => $val, |
| 119 | +- 'short' => $this->useShortAttachment |
| 120 | ++ 'short' => $this->useShortAttachment, |
| 121 | + ); |
| 122 | + } |
| 123 | + } |
| 124 | +@@ -248,6 +241,10 @@ class SlackHandler extends SocketHandler |
| 125 | + protected function write(array $record) |
| 126 | + { |
| 127 | + parent::write($record); |
| 128 | ++ $res = $this->getResource(); |
| 129 | ++ if (is_resource($res)) { |
| 130 | ++ @fread($res, 2048); |
| 131 | ++ } |
| 132 | + $this->closeSocket(); |
| 133 | + } |
| 134 | + |
| 135 | +@@ -275,8 +272,7 @@ class SlackHandler extends SocketHandler |
| 136 | + /** |
| 137 | + * Stringifies an array of key/value pairs to be used in attachment fields |
| 138 | + * |
| 139 | +- * @param array $fields |
| 140 | +- * @access protected |
| 141 | ++ * @param array $fields |
| 142 | + * @return string |
| 143 | + */ |
| 144 | + protected function stringify($fields) |
| 145 | +diff -Nuar a/vendor/monolog/monolog/src/Monolog/Handler/SocketHandler.php b/vendor/monolog/monolog/src/Monolog/Handler/SocketHandler.php |
| 146 | +index a3e7252e..e4c3c37f 100644 |
| 147 | +--- a/vendor/monolog/monolog/src/Monolog/Handler/SocketHandler.php |
| 148 | ++++ b/vendor/monolog/monolog/src/Monolog/Handler/SocketHandler.php |
| 149 | +@@ -41,6 +41,15 @@ class SocketHandler extends AbstractProcessingHandler |
| 150 | + $this->connectionTimeout = (float) ini_get('default_socket_timeout'); |
| 151 | + } |
| 152 | + |
| 153 | ++ /** |
| 154 | ++ * @return resource|null |
| 155 | ++ */ |
| 156 | ++ protected function getResource() |
| 157 | ++ { |
| 158 | ++ return $this->resource; |
| 159 | ++ } |
| 160 | ++ |
| 161 | ++ |
| 162 | + /** |
| 163 | + * Connect (if necessary) and write to the socket |
| 164 | + * |
0 commit comments