1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-12 16:14:08 +02:00

Truncate messages if they reach the max length of GELF messages, fixes #751

This commit is contained in:
Jordi Boggiano
2016-04-02 13:53:47 +01:00
parent 15e21f38aa
commit 6bc1a444db
2 changed files with 46 additions and 2 deletions

View File

@@ -197,6 +197,24 @@ class GelfMessageFormatterTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('pair', $message_array['_EXTkey']);
}
public function testFormatWithLargeData()
{
$formatter = new GelfMessageFormatter();
$record = array(
'level' => Logger::ERROR,
'level_name' => 'ERROR',
'channel' => 'meh',
'context' => array('exception' => str_repeat(' ', 32767)),
'datetime' => new \DateTime("@0"),
'extra' => array('key' => str_repeat(' ', 32767)),
'message' => 'log'
);
$message = $formatter->format($record);
$messageArray = $message->toArray();
$this->assertLessThanOrEqual(32766, strlen($messageArray['_key']));
$this->assertLessThanOrEqual(32766, strlen($messageArray['_ctxt_exception']));
}
private function isLegacy()
{
return interface_exists('\Gelf\IMessagePublisher');