101 throw new \InvalidArgumentException(
'The supplied name is too long. HipChat\'s v1 API supports names up to 15 UTF-8 characters.');
138 'notify' => $this->version == self::API_V1 ?
139 ($this->notify ? 1 : 0) :
140 ($this->notify ?
'true' :
'false'),
141 'message' => $record[
'formatted'],
142 'message_format' => $this->format,
147 if (function_exists(
'mb_substr')) {
148 $dataArray[
'message'] = mb_substr($dataArray[
'message'], 0, static::MAXIMUM_MESSAGE_LENGTH).
' [truncated]';
150 $dataArray[
'message'] = substr($dataArray[
'message'], 0, static::MAXIMUM_MESSAGE_LENGTH).
' [truncated]';
155 if ($this->version == self::API_V1) {
161 if ($this->version == self::API_V1 || $this->name !==
null) {
162 $dataArray[
'from'] = (string) $this->name;
165 return http_build_query($dataArray);
176 if ($this->version == self::API_V1) {
177 $header =
"POST /v1/rooms/message?format=json&auth_token={$this->token} HTTP/1.1\r\n";
180 $room = rawurlencode($this->room);
181 $header =
"POST /v2/room/{$room}/notification?auth_token={$this->token} HTTP/1.1\r\n";
184 $header .=
"Host: {$this->host}\r\n";
185 $header .=
"Content-Type: application/x-www-form-urlencoded\r\n";
186 $header .=
"Content-Length: " . strlen($content) .
"\r\n";
219 protected function write(array $record)
234 if (is_resource(
$res)) {
252 foreach ($batchRecords as $batchRecord) {
254 $this->
write($batchRecord);
277 $batchRecords = array();
279 $formattedMessages = array();
287 if ($record[
'level'] >
$level) {
288 $level = $record[
'level'];
289 $levelName = $record[
'level_name'];
292 if (
null === $datetime) {
293 $datetime = $record[
'datetime'];
298 $formattedMessages[] = $this->
getFormatter()->format($record);
299 $formattedMessageStr = implode(
'', $formattedMessages);
301 $batchRecord = array(
302 'message' => $messageStr,
303 'formatted' => $formattedMessageStr,
304 'context' => array(),
311 $lastFormattedMessage = array_pop($formattedMessages);
313 $batchRecord[
'formatted'] = implode(
'', $formattedMessages);
315 $batchRecords[] = $batchRecord;
317 $formattedMessages = array($lastFormattedMessage);
323 if (
null !== $batchRecord) {
324 $batchRecords[] = $batchRecord;
328 foreach ($batchRecords as &$batchRecord) {
329 $batchRecord = array_merge(
333 'level_name' => $levelName,
334 'datetime' => $datetime,
339 return $batchRecords;
359 if (function_exists(
'mb_strlen')) {
360 return (mb_strlen($str) <= $length);
363 return (strlen($str) <= $length);
An exception for terminatinating execution or to throw for unit testing.
getFormatter()
{Gets the formatter.FormatterInterface}
isHandling(array $record)
{Checks whether the given record will be handled by this handler.This is mostly done for performance ...
processRecord(array $record)
Processes a record.
Sends notifications through the hipchat api to a hipchat room.
const MAXIMUM_NAME_LENGTH
The maximum allowed length for the name used in the "from" field.
generateDataStream($record)
{}
__construct($token, $room, $name='Monolog', $notify=false, $level=Logger::CRITICAL, $bubble=true, $useSSL=true, $format='text', $host='api.hipchat.com', $version=self::API_V1)
buildContent($record)
Builds the body of API call.
buildHeader($content)
Builds the header of the API Call.
const API_V1
Use API version 1.
handleBatch(array $records)
{{Handles a set of records at once.}}
write(array $record)
{Connect (if necessary) and write to the socket.UnexpectedValueException RuntimeException}
const MAXIMUM_MESSAGE_LENGTH
The maximum allowed length for the message.
finalizeWrite()
Finalizes the request by reading some bytes and then closing the socket.
const API_V2
Use API version v2.
validateStringLength($str, $length)
Validates the length of a string.
combineRecords($records)
Combines multiple records into one.
getAlertColor($level)
Assigns a color to each level of log records.
Stores to any socket - uses fsockopen() or pfsockopen().
closeSocket()
Close socket, if open.
const ERROR
Runtime errors.
const CRITICAL
Critical conditions.
const WARNING
Exceptional occurrences that are not errors.
const INFO
Interesting events.
const DEBUG
Detailed debug information.
foreach($_POST as $key=> $value) $res