1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-07-31 10:20:14 +02:00

Truncate single messages if they go over the hipchat limit, fixes #629

This commit is contained in:
Jordi Boggiano
2016-04-10 12:31:24 +01:00
parent 6c21baf553
commit ccdc8b530c
2 changed files with 18 additions and 0 deletions

View File

@@ -143,6 +143,14 @@ class HipChatHandler extends SocketHandler
'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 ($this->version == self::API_V1) {
$dataArray['room_id'] = $this->room;

View File

@@ -150,6 +150,16 @@ class HipChatHandlerTest extends TestCase
$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
*/