Skip to content

Commit

Permalink
Output message to the user when chrome logs have been truncated, refs S…
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek authored and mathroc committed Dec 30, 2013
1 parent 0d917d0 commit 0b1e6fc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
15 changes: 14 additions & 1 deletion src/Monolog/Handler/ChromePHPHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Monolog\Handler;

use Monolog\Formatter\ChromePHPFormatter;
use Monolog\Logger;

/**
* Handler sending logs to the ChromePHP extension (http://www.chromephp.com/)
Expand Down Expand Up @@ -115,8 +116,20 @@ protected function send()
if (strlen($data) > 240*1024) {
self::$overflowed = true;

return;
$record = array(
'message' => 'Incomplete logs, chrome header size limit reached',
'context' => array(),
'level' => Logger::WARNING,
'level_name' => Logger::getLevelName(Logger::WARNING),
'channel' => 'monolog',
'datetime' => new \DateTime(),
'extra' => array(),
);
self::$json['rows'][count(self::$json['rows']) - 1] = $this->getFormatter()->format($record);
$json = @json_encode(self::$json);
$data = base64_encode(utf8_encode($json));
}

$this->sendHeader(self::HEADER_NAME, $data);
}

Expand Down
32 changes: 29 additions & 3 deletions tests/Monolog/Handler/ChromePHPHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,39 @@ 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());
$expected = array(
'X-ChromePhp-Data' => base64_encode(utf8_encode(json_encode(array(
'version' => ChromePHPHandler::VERSION,
'columns' => array('label', 'log', 'backtrace', 'type'),
'rows' => array(
array(
'test',
'test',
'unknown',
'log',
),
array(
'test',
str_repeat('a', 150*1024),
'unknown',
'warn',
),
array(
'monolog',
'Incomplete logs, chrome header size limit reached',
'unknown',
'warn',
),
),
'request_uri' => '',
))))
);

$this->assertEquals($expected, $handler->getHeaders());
}

public function testConcurrentHandlers()
Expand Down

0 comments on commit 0b1e6fc

Please # to comment.