ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Monolog\Handler\SlackWebhookHandler Class Reference

Sends notifications through Slack Webhooks. More...

+ Inheritance diagram for Monolog\Handler\SlackWebhookHandler:
+ Collaboration diagram for Monolog\Handler\SlackWebhookHandler:

Public Member Functions

 __construct ($webhookUrl, $channel=null, $username=null, $useAttachment=true, $iconEmoji=null, $useShortAttachment=false, $includeContextAndExtra=false, $level=Logger::CRITICAL, $bubble=true, array $excludeFields=array())
 
 getSlackRecord ()
 
 getWebhookUrl ()
 
 setFormatter (FormatterInterface $formatter)
 {{Sets the formatter.
Parameters
FormatterInterface$formatter
Returns
self
}} More...
 
 getFormatter ()
 {{Gets the formatter.
Returns
FormatterInterface
}} More...
 
- Public Member Functions inherited from Monolog\Handler\AbstractProcessingHandler
 handle (array $record)
 {Handles a record.All records may be passed to this method, and the handler should discard those that it does not want to handle.The return value of this function controls the bubbling process of the handler stack. Unless the bubbling is interrupted (by returning true), the Logger class will keep on calling further handlers in the stack with a given log record.
Parameters
array$recordThe record to handle
Returns
bool true means that this handler handled the record, and that bubbling is not permitted. false means the record was either not processed or that this handler allows bubbling.
} More...
 
- Public Member Functions inherited from Monolog\Handler\AbstractHandler
 __construct ($level=Logger::DEBUG, $bubble=true)
 
 isHandling (array $record)
 {Checks whether the given record will be handled by this handler.This is mostly done for performance reasons, to avoid calling processors for nothing.Handlers should still check the record levels within handle(), returning false in isHandling() is no guarantee that handle() will not be called, and isHandling() might not be called for a given record.
Parameters
array$recordPartial log record containing only a level key
Returns
bool
} More...
 
 handleBatch (array $records)
 {Handles a set of records at once.
Parameters
array$recordsThe records to handle (an array of record arrays)
} More...
 
 close ()
 Closes the handler. More...
 
 pushProcessor ($callback)
 {Adds a processor in the stack.
Parameters
callable$callback
Returns
self
} More...
 
 popProcessor ()
 {Removes the processor on top of the stack and returns it.
Returns
callable
} More...
 
 setFormatter (FormatterInterface $formatter)
 {Sets the formatter.
Parameters
FormatterInterface$formatter
Returns
self
} More...
 
 getFormatter ()
 {Gets the formatter.
Returns
FormatterInterface
} More...
 
 setLevel ($level)
 Sets minimum logging level at which this handler will be triggered. More...
 
 getLevel ()
 Gets minimum logging level at which this handler will be triggered. More...
 
 setBubble ($bubble)
 Sets the bubbling behavior. More...
 
 getBubble ()
 Gets the bubbling behavior. More...
 
 __destruct ()
 
 reset ()
 
 isHandling (array $record)
 Checks whether the given record will be handled by this handler. More...
 
 handle (array $record)
 Handles a record. More...
 
 handleBatch (array $records)
 Handles a set of records at once. More...
 
 pushProcessor ($callback)
 Adds a processor in the stack. More...
 
 popProcessor ()
 Removes the processor on top of the stack and returns it. More...
 
 setFormatter (FormatterInterface $formatter)
 Sets the formatter. More...
 
 getFormatter ()
 Gets the formatter. More...
 
 reset ()
 

Protected Member Functions

 write (array $record)
 {Writes the record down to the log of the implementing handler.
Parameters
array$record
Returns
void
} More...
 
- Protected Member Functions inherited from Monolog\Handler\AbstractProcessingHandler
 write (array $record)
 Writes the record down to the log of the implementing handler. More...
 
 processRecord (array $record)
 Processes a record. More...
 
- Protected Member Functions inherited from Monolog\Handler\AbstractHandler
 getDefaultFormatter ()
 Gets the default formatter. More...
 

Private Attributes

 $webhookUrl
 
 $slackRecord
 

Additional Inherited Members

- Protected Attributes inherited from Monolog\Handler\AbstractHandler
 $level = Logger::DEBUG
 
 $bubble = true
 
 $formatter
 
 $processors = array()
 

Detailed Description

Sends notifications through Slack Webhooks.

Author
Haralan Dobrev hkdob.nosp@m.rev@.nosp@m.gmail.nosp@m..com
See also
https://api.slack.com/incoming-webhooks

Definition at line 24 of file SlackWebhookHandler.php.

Constructor & Destructor Documentation

◆ __construct()

Monolog\Handler\SlackWebhookHandler::__construct (   $webhookUrl,
  $channel = null,
  $username = null,
  $useAttachment = true,
  $iconEmoji = null,
  $useShortAttachment = false,
  $includeContextAndExtra = false,
  $level = Logger::CRITICAL,
  $bubble = true,
array  $excludeFields = array() 
)
Parameters
string$webhookUrlSlack Webhook URL
string | null$channelSlack channel (encoded ID or name)
string | null$usernameName of a bot
bool$useAttachmentWhether the message should be added to Slack as attachment (plain text otherwise)
string | null$iconEmojiThe emoji name to use (or null)
bool$useShortAttachmentWhether the the context/extra messages added to Slack as attachments are in a short style
bool$includeContextAndExtraWhether the attachment should include context and extra data
int$levelThe minimum logging level at which this handler will be triggered
bool$bubbleWhether the messages that are handled can bubble up the stack or not
array$excludeFieldsDot separated list of fields to exclude from slack message. E.g. ['context.field1', 'extra.field2']

Definition at line 50 of file SlackWebhookHandler.php.

51 {
52 parent::__construct($level, $bubble);
53
54 $this->webhookUrl = $webhookUrl;
55
56 $this->slackRecord = new SlackRecord(
57 $channel,
58 $username,
59 $useAttachment,
60 $iconEmoji,
61 $useShortAttachment,
62 $includeContextAndExtra,
63 $excludeFields,
64 $this->formatter
65 );
66 }

References Monolog\Handler\AbstractHandler\$bubble, Monolog\Handler\AbstractHandler\$level, and Monolog\Handler\SlackWebhookHandler\$webhookUrl.

Member Function Documentation

◆ getFormatter()

Monolog\Handler\SlackWebhookHandler::getFormatter ( )

{{Gets the formatter.

Returns
FormatterInterface
}}

Reimplemented from Monolog\Handler\AbstractHandler.

Definition at line 113 of file SlackWebhookHandler.php.

114 {
115 $formatter = parent::getFormatter();
116 $this->slackRecord->setFormatter($formatter);
117
118 return $formatter;
119 }

References Monolog\Handler\AbstractHandler\$formatter.

◆ getSlackRecord()

Monolog\Handler\SlackWebhookHandler::getSlackRecord ( )

◆ getWebhookUrl()

Monolog\Handler\SlackWebhookHandler::getWebhookUrl ( )

Definition at line 73 of file SlackWebhookHandler.php.

74 {
75 return $this->webhookUrl;
76 }

References Monolog\Handler\SlackWebhookHandler\$webhookUrl.

◆ setFormatter()

Monolog\Handler\SlackWebhookHandler::setFormatter ( FormatterInterface  $formatter)

{{Sets the formatter.

Parameters
FormatterInterface$formatter
Returns
self
}}

Reimplemented from Monolog\Handler\AbstractHandler.

Definition at line 105 of file SlackWebhookHandler.php.

106 {
107 parent::setFormatter($formatter);
108 $this->slackRecord->setFormatter($formatter);
109
110 return $this;
111 }

References Monolog\Handler\AbstractHandler\$formatter.

◆ write()

Monolog\Handler\SlackWebhookHandler::write ( array  $record)
protected

{Writes the record down to the log of the implementing handler.

Parameters
array$record
Returns
void
}

Parameters
array$record

Reimplemented from Monolog\Handler\AbstractProcessingHandler.

Definition at line 83 of file SlackWebhookHandler.php.

84 {
85 $postData = $this->slackRecord->getSlackData($record);
86 $postString = json_encode($postData);
87
88 $ch = curl_init();
89 $options = array(
90 CURLOPT_URL => $this->webhookUrl,
91 CURLOPT_POST => true,
92 CURLOPT_RETURNTRANSFER => true,
93 CURLOPT_HTTPHEADER => array('Content-type: application/json'),
94 CURLOPT_POSTFIELDS => $postString
95 );
96 if (defined('CURLOPT_SAFE_UPLOAD')) {
97 $options[CURLOPT_SAFE_UPLOAD] = true;
98 }
99
100 curl_setopt_array($ch, $options);
101
103 }
static execute($ch, $retries=5, $closeAfterDone=true)
Executes a CURL request with optional retries and exception on failure.
Definition: Util.php:32
if($session===NULL) $postData

References PHPMailer\PHPMailer\$options, $postData, and Monolog\Handler\Curl\Util\execute().

+ Here is the call graph for this function:

Field Documentation

◆ $slackRecord

Monolog\Handler\SlackWebhookHandler::$slackRecord
private

◆ $webhookUrl

Monolog\Handler\SlackWebhookHandler::$webhookUrl
private

The documentation for this class was generated from the following file: