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:
parent
7e56792987
commit
6275edbe75
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user