mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-08 06:06:40 +02:00
Merge pull request #507 from jamiel/master
#493 Include context in slack extra info.
This commit is contained in:
@@ -157,18 +157,48 @@ class SlackHandler extends SocketHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->includeExtra) {
|
if ($this->includeExtra) {
|
||||||
$extra = '';
|
|
||||||
foreach ($record['extra'] as $var => $val) {
|
if (!empty($record['extra'])) {
|
||||||
$extra .= $var.': '.$this->lineFormatter->stringify($val)." | ";
|
|
||||||
|
if ($this->useShortAttachment) {
|
||||||
|
|
||||||
|
$attachment['fields'][] = array(
|
||||||
|
'title' => "Extra",
|
||||||
|
'value' => $this->stringify($record['extra']),
|
||||||
|
'short' => $this->useShortAttachment
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Add all extra fields as individual fields in attachment
|
||||||
|
foreach ($record['extra'] as $var => $val) {
|
||||||
|
$attachment['fields'][] = array(
|
||||||
|
'title' => $var,
|
||||||
|
'value' => $val,
|
||||||
|
'short' => $this->useShortAttachment
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$extra = rtrim($extra, " |");
|
if (!empty($record['context'])) {
|
||||||
|
|
||||||
$attachment['fields'][] = array(
|
if ($this->useShortAttachment) {
|
||||||
'title' => "Extra",
|
|
||||||
'value' => $extra,
|
$attachment['fields'][] = array(
|
||||||
'short' => false
|
'title' => "Context",
|
||||||
);
|
'value' => $this->stringify($record['context']),
|
||||||
|
'short' => $this->useShortAttachment
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Add all context fields as individual fields in attachment
|
||||||
|
foreach ($record['context'] as $var => $val) {
|
||||||
|
$attachment['fields'][] = array(
|
||||||
|
'title' => $var,
|
||||||
|
'value' => $val,
|
||||||
|
'short' => $this->useShortAttachment
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$dataArray['attachments'] = json_encode(array($attachment));
|
$dataArray['attachments'] = json_encode(array($attachment));
|
||||||
@@ -231,4 +261,23 @@ class SlackHandler extends SocketHandler
|
|||||||
return '#e3e4e6';
|
return '#e3e4e6';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stringifys an array of key/value pairs to be used in attachment fields
|
||||||
|
*
|
||||||
|
* @param array $fields
|
||||||
|
* @access protected
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function stringify($fields)
|
||||||
|
{
|
||||||
|
$string = '';
|
||||||
|
foreach ($fields as $var => $val) {
|
||||||
|
$string .= $var.': '.$this->lineFormatter->stringify($val)." | ";
|
||||||
|
}
|
||||||
|
|
||||||
|
$string = rtrim($string, " |");
|
||||||
|
|
||||||
|
return $string;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user