1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-02-24 06:52:34 +01:00

Stop sending logs when the chrome header size limit has been reached, fixes #172

This commit is contained in:
Jordi Boggiano 2013-04-23 11:37:26 +02:00
parent 7e56792987
commit 6275edbe75
2 changed files with 35 additions and 1 deletions

View File

@ -32,6 +32,15 @@ class ChromePHPHandler extends AbstractProcessingHandler
protected static $initialized = false;
/**
* Tracks whether we sent too much data
*
* Chrome limits the headers to 256KB, so when we sent 240KB we stop sending
*
* @var Boolean
*/
protected static $overflowed = false;
protected static $json = array(
'version' => self::VERSION,
'columns' => array('label', 'log', 'backtrace', 'type'),
@ -90,6 +99,10 @@ class ChromePHPHandler extends AbstractProcessingHandler
*/
protected function send()
{
if (self::$overflowed) {
return;
}
if (!self::$initialized) {
self::$sendHeaders = $this->headersAccepted();
self::$json['request_uri'] = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
@ -98,7 +111,13 @@ class ChromePHPHandler extends AbstractProcessingHandler
}
$json = @json_encode(self::$json);
$this->sendHeader(self::HEADER_NAME, base64_encode(utf8_encode($json)));
$data = base64_encode(utf8_encode($json));
if (strlen($data) > 240*1024) {
self::$overflowed = true;
return;
}
$this->sendHeader(self::HEADER_NAME, $data);
}
/**

View File

@ -46,6 +46,20 @@ class ChromePHPHandlerTest extends TestCase
$this->assertEquals($expected, $handler->getHeaders());
}
public function testHeadersOverflow()
{
$handler = new TestChromePHPHandler();
$handler->handle($this->getRecord(Logger::DEBUG));
$handler->handle($this->getRecord(Logger::WARNING, str_repeat('a', 150*1024)));
$headersBefore = $handler->getHeaders();
// overflow chrome headers limit
$handler->handle($this->getRecord(Logger::WARNING, str_repeat('a', 100*1024)));
// check the headers did not change
$this->assertEquals($headersBefore, $handler->getHeaders());
}
public function testConcurrentHandlers()
{
$handler = new TestChromePHPHandler();
@ -83,6 +97,7 @@ class TestChromePHPHandler extends ChromePHPHandler
public static function reset()
{
self::$initialized = false;
self::$overflowed = false;
self::$json['rows'] = array();
}