99 if ($this->includeContextAndExtra) {
106 $dataArray = array();
109 if ($this->username) {
113 if ($this->channel) {
117 if ($this->formatter && !$this->useAttachment) {
118 $message = $this->formatter->format($record);
123 if ($this->useAttachment) {
129 'mrkdwn_in' => array(
'fields'),
130 'ts' => $record[
'datetime']->getTimestamp()
133 if ($this->useShortAttachment) {
134 $attachment[
'title'] = $record[
'level_name'];
136 $attachment[
'title'] =
'Message';
141 if ($this->includeContextAndExtra) {
142 foreach (array(
'extra',
'context') as
$key) {
143 if (empty($record[$key])) {
147 if ($this->useShortAttachment) {
154 $attachment[
'fields'] = array_merge(
155 $attachment[
'fields'],
162 $dataArray[
'attachments'] = array($attachment);
167 if ($this->userIcon) {
168 if (filter_var($this->userIcon, FILTER_VALIDATE_URL)) {
171 $dataArray[
'icon_emoji'] =
":{$this->userIcon}:";
189 return self::COLOR_DANGER;
191 return self::COLOR_WARNING;
193 return self::COLOR_GOOD;
195 return self::COLOR_DEFAULT;
208 $normalized = $this->normalizerFormatter->format($fields);
209 $prettyPrintFlag = defined(
'JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 128;
211 $hasSecondDimension = count(array_filter($normalized,
'is_array'));
212 $hasNonNumericKeys = !count(array_filter(array_keys($normalized),
'is_numeric'));
214 return $hasSecondDimension || $hasNonNumericKeys
215 ? json_encode($normalized, $prettyPrintFlag)
216 : json_encode($normalized);
239 $value = is_array($value)
240 ? sprintf(
'```%s```', $this->
stringify($value))
244 'title' => ucfirst(
$title),
260 foreach ($this->normalizerFormatter->format($data) as
$key => $value) {
277 $keys = explode(
'.', $field);
279 $lastKey = end(
$keys);
281 if (!isset($node[$key])) {
284 if ($lastKey === $key) {
288 $node = &$node[
$key];
const ERROR
Runtime errors.
getSlackData(array $record)
generateAttachmentField($title, $value)
Generates attachment field.
catch(Exception $e) $message
getAttachmentColor($level)
Returned a Slack message attachment color associated with provided level.
__construct($channel=null, $username=null, $useAttachment=true, $userIcon=null, $useShortAttachment=false, $includeContextAndExtra=false, array $excludeFields=array(), FormatterInterface $formatter=null)
Slack record utility helping to log to Slack webhooks or API.
excludeFields(array $record)
Get a copy of record with fields excluded according to $this->excludeFields.
generateAttachmentFields(array $data)
Generates a collection of attachment fields from array.
const WARNING
Exceptional occurrences that are not errors.
stringify($fields)
Stringifies an array of key/value pairs to be used in attachment fields.
setFormatter(FormatterInterface $formatter)
Sets the formatter.
const INFO
Interesting events.