feature #10473 [WebProfilerBundle] enhance logs display (nicolas-grekas)

This PR was merged into the 2.5-dev branch.

Discussion
----------

[WebProfilerBundle] enhance logs display

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | none
| License       | MIT
| Doc PR        | none

Commits
-------

3e6c940 [WebProfilerBundle] enhance logs display
This commit is contained in:
Fabien Potencier 2014-03-18 14:44:19 +01:00
commit 8170db84b3
4 changed files with 44 additions and 13 deletions

View File

@ -62,12 +62,21 @@
<td>
<form id="priority-form" action="" method="get" style="display: inline">
<input type="hidden" name="panel" value="logger">
<label for="priority">Priority</label>
<label for="priority">Min. Priority</label>
<select id="priority" name="priority" onchange="document.getElementById('priority-form').submit(); ">
{# values < 0 are custom levels #}
{% for value, text in { 100: 'DEBUG', 200: 'INFO', 250: 'NOTICE', 300: 'WARNING', 400: 'ERROR', 500: 'CRITICAL', 550: 'ALERT', 600: 'EMERGENCY', '-100': 'DEPRECATION only' } %}
<option value="{{ value }}"{{ value == priority ? ' selected' : '' }}>{{ text }}</option>
{% for value, level in collector.priorities %}
{% if not priority and value > 100 %}
{% set priority = value %}
{% endif %}
<option value="{{ value }}"{{ value == priority ? ' selected' : '' }}>{{ level.name }} ({{ level.count }})</option>
{% endfor %}
{% if collector.countdeprecations %}
{% if not priority %}
{% set priority = "-100" %}
{% endif %}
<option value="-100"{{ "-100" == priority ? ' selected' : '' }}>DEPRECATION only ({{ collector.countdeprecations }})</option>
{% endif %}
</select>
<noscript>
<input type="submit" value="refresh">

View File

@ -278,7 +278,7 @@ class ErrorHandler
'line' => $error['line'],
);
self::$loggers['emergency']->emerg($error['message'], $fatal);
self::$loggers['emergency']->emergency($error['message'], $fatal);
}
if (!$this->displayErrors) {

View File

@ -73,6 +73,11 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
return isset($this->data['logs']) ? $this->data['logs'] : array();
}
public function getPriorities()
{
return isset($this->data['priorities']) ? $this->data['priorities'] : array();
}
public function countDeprecations()
{
return isset($this->data['deprecation_count']) ? $this->data['deprecation_count'] : 0;
@ -127,9 +132,19 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
'error_count' => $this->logger->countErrors(),
'deprecation_count' => 0,
'scream_count' => 0,
'priorities' => array(),
);
foreach ($this->logger->getLogs() as $log) {
if (isset($count['priorities'][$log['priority']])) {
++$count['priorities'][$log['priority']]['count'];
} else {
$count['priorities'][$log['priority']] = array(
'count' => 1,
'name' => $log['priorityName'],
);
}
if (isset($log['context']['type'])) {
if (ErrorHandler::TYPE_DEPRECATION === $log['context']['type']) {
++$count['deprecation_count'];
@ -139,6 +154,8 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
}
}
ksort($count['priorities']);
return $count;
}
}

View File

@ -19,7 +19,7 @@ class LoggerDataCollectorTest extends \PHPUnit_Framework_TestCase
/**
* @dataProvider getCollectTestData
*/
public function testCollect($nb, $logs, $expectedLogs, $expectedDeprecationCount, $expectedScreamCount)
public function testCollect($nb, $logs, $expectedLogs, $expectedDeprecationCount, $expectedScreamCount, $expectedPriorities = null)
{
$logger = $this->getMock('Symfony\Component\HttpKernel\Log\DebugLoggerInterface');
$logger->expects($this->once())->method('countErrors')->will($this->returnValue($nb));
@ -33,6 +33,10 @@ class LoggerDataCollectorTest extends \PHPUnit_Framework_TestCase
$this->assertSame($expectedLogs ? $expectedLogs : $logs, $c->getLogs());
$this->assertSame($expectedDeprecationCount, $c->countDeprecations());
$this->assertSame($expectedScreamCount, $c->countScreams());
if (isset($expectedPriorities)) {
$this->assertSame($expectedPriorities, $c->getPriorities());
}
}
public function getCollectTestData()
@ -40,35 +44,36 @@ class LoggerDataCollectorTest extends \PHPUnit_Framework_TestCase
return array(
array(
1,
array(array('message' => 'foo', 'context' => array())),
array(array('message' => 'foo', 'context' => array(), 'priority' => 100, 'priorityName' => 'DEBUG')),
null,
0,
0,
),
array(
1,
array(array('message' => 'foo', 'context' => array('foo' => fopen(__FILE__, 'r')))),
array(array('message' => 'foo', 'context' => array('foo' => 'Resource(stream)'))),
array(array('message' => 'foo', 'context' => array('foo' => fopen(__FILE__, 'r')), 'priority' => 100, 'priorityName' => 'DEBUG')),
array(array('message' => 'foo', 'context' => array('foo' => 'Resource(stream)'), 'priority' => 100, 'priorityName' => 'DEBUG')),
0,
0,
),
array(
1,
array(array('message' => 'foo', 'context' => array('foo' => new \stdClass()))),
array(array('message' => 'foo', 'context' => array('foo' => 'Object(stdClass)'))),
array(array('message' => 'foo', 'context' => array('foo' => new \stdClass()), 'priority' => 100, 'priorityName' => 'DEBUG')),
array(array('message' => 'foo', 'context' => array('foo' => 'Object(stdClass)'), 'priority' => 100, 'priorityName' => 'DEBUG')),
0,
0,
),
array(
1,
array(
array('message' => 'foo', 'context' => array('type' => ErrorHandler::TYPE_DEPRECATION)),
array('message' => 'foo2', 'context' => array('type' => ErrorHandler::TYPE_DEPRECATION)),
array('message' => 'foo3', 'context' => array('type' => E_USER_WARNING, 'scream' => 0)),
array('message' => 'foo', 'context' => array('type' => ErrorHandler::TYPE_DEPRECATION), 'priority' => 100, 'priorityName' => 'DEBUG'),
array('message' => 'foo2', 'context' => array('type' => ErrorHandler::TYPE_DEPRECATION), 'priority' => 100, 'priorityName' => 'DEBUG'),
array('message' => 'foo3', 'context' => array('type' => E_USER_WARNING, 'scream' => 0), 'priority' => 100, 'priorityName' => 'DEBUG'),
),
null,
2,
1,
array(100 => array('count' => 3, 'name' => 'DEBUG')),
),
);
}