mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-07 05:36:45 +02:00
Merge branch '1.x'
This commit is contained in:
@@ -33,6 +33,11 @@ class ChromePHPHandler extends AbstractProcessingHandler
|
|||||||
* Header name
|
* Header name
|
||||||
*/
|
*/
|
||||||
const HEADER_NAME = 'X-ChromeLogger-Data';
|
const HEADER_NAME = 'X-ChromeLogger-Data';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regular expression to detect supported browsers (matches any Chrome, or Firefox 43+)
|
||||||
|
*/
|
||||||
|
const USER_AGENT_REGEX = '{\b(?:Chrome/\d+(?:\.\d+)*|Firefox/(?:4[3-9]|[5-9]\d|\d{3,})(?:\.\d)*)\b}';
|
||||||
|
|
||||||
protected static $initialized = false;
|
protected static $initialized = false;
|
||||||
|
|
||||||
@@ -178,8 +183,7 @@ class ChromePHPHandler extends AbstractProcessingHandler
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// matches any Chrome, or Firefox 43+
|
return preg_match(self::USER_AGENT_REGEX, $_SERVER['HTTP_USER_AGENT']);
|
||||||
return preg_match('{\b(?:Chrome/\d+(?:\.\d+)*|Firefox/(?:4[3-9]|[5-9]\d|\d{3,})(?:\.\d)*)\b}', $_SERVER['HTTP_USER_AGENT']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -143,6 +143,14 @@ class HipChatHandler extends SocketHandler
|
|||||||
'color' => $this->getAlertColor($record['level']),
|
'color' => $this->getAlertColor($record['level']),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!$this->validateStringLength($dataArray['message'], static::MAXIMUM_MESSAGE_LENGTH)) {
|
||||||
|
if (function_exists('mb_substr')) {
|
||||||
|
$dataArray['message'] = mb_substr($dataArray['message'], 0, static::MAXIMUM_MESSAGE_LENGTH).' [truncated]';
|
||||||
|
} else {
|
||||||
|
$dataArray['message'] = substr($dataArray['message'], 0, static::MAXIMUM_MESSAGE_LENGTH).' [truncated]';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// if we are using the legacy API then we need to send some additional information
|
// if we are using the legacy API then we need to send some additional information
|
||||||
if ($this->version == self::API_V1) {
|
if ($this->version == self::API_V1) {
|
||||||
$dataArray['room_id'] = $this->room;
|
$dataArray['room_id'] = $this->room;
|
||||||
|
@@ -211,8 +211,20 @@ class GelfMessageFormatterTest extends \PHPUnit_Framework_TestCase
|
|||||||
);
|
);
|
||||||
$message = $formatter->format($record);
|
$message = $formatter->format($record);
|
||||||
$messageArray = $message->toArray();
|
$messageArray = $message->toArray();
|
||||||
$this->assertLessThanOrEqual(32766, strlen($messageArray['_key']));
|
|
||||||
$this->assertLessThanOrEqual(32766, strlen($messageArray['_ctxt_exception']));
|
// 200 for padding + metadata
|
||||||
|
$length = 200;
|
||||||
|
|
||||||
|
foreach ($messageArray as $key => $value) {
|
||||||
|
if (!in_array($key, array('level', 'timestamp'))) {
|
||||||
|
$length += strlen($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// in graylog2/gelf-php before 1.4.1 empty strings are filtered and won't be included in the message
|
||||||
|
// though it should be sufficient to ensure that the entire message length does not exceed the maximum
|
||||||
|
// length being allowed
|
||||||
|
$this->assertLessThanOrEqual(32766, $length, 'The message length is no longer than the maximum allowed length');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function isLegacy()
|
private function isLegacy()
|
||||||
|
@@ -150,6 +150,16 @@ class HipChatHandlerTest extends TestCase
|
|||||||
$this->assertRegexp('/message=Backup\+of\+database\+%22example%22\+finished\+in\+16\+minutes\./', $content);
|
$this->assertRegexp('/message=Backup\+of\+database\+%22example%22\+finished\+in\+16\+minutes\./', $content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testWriteTruncatesLongMessage()
|
||||||
|
{
|
||||||
|
$this->createHandler();
|
||||||
|
$this->handler->handle($this->getRecord(Logger::CRITICAL, str_repeat('abcde', 2000)));
|
||||||
|
fseek($this->res, 0);
|
||||||
|
$content = fread($this->res, 12000);
|
||||||
|
|
||||||
|
$this->assertRegexp('/message='.str_repeat('abcde', 1900).'\+%5Btruncated%5D/', $content);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider provideLevelColors
|
* @dataProvider provideLevelColors
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user