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:
commit
8170db84b3
@ -62,12 +62,21 @@
|
|||||||
<td>
|
<td>
|
||||||
<form id="priority-form" action="" method="get" style="display: inline">
|
<form id="priority-form" action="" method="get" style="display: inline">
|
||||||
<input type="hidden" name="panel" value="logger">
|
<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(); ">
|
<select id="priority" name="priority" onchange="document.getElementById('priority-form').submit(); ">
|
||||||
{# values < 0 are custom levels #}
|
{# 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' } %}
|
{% for value, level in collector.priorities %}
|
||||||
<option value="{{ value }}"{{ value == priority ? ' selected' : '' }}>{{ text }}</option>
|
{% if not priority and value > 100 %}
|
||||||
|
{% set priority = value %}
|
||||||
|
{% endif %}
|
||||||
|
<option value="{{ value }}"{{ value == priority ? ' selected' : '' }}>{{ level.name }} ({{ level.count }})</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
{% if collector.countdeprecations %}
|
||||||
|
{% if not priority %}
|
||||||
|
{% set priority = "-100" %}
|
||||||
|
{% endif %}
|
||||||
|
<option value="-100"{{ "-100" == priority ? ' selected' : '' }}>DEPRECATION only ({{ collector.countdeprecations }})</option>
|
||||||
|
{% endif %}
|
||||||
</select>
|
</select>
|
||||||
<noscript>
|
<noscript>
|
||||||
<input type="submit" value="refresh">
|
<input type="submit" value="refresh">
|
||||||
|
@ -278,7 +278,7 @@ class ErrorHandler
|
|||||||
'line' => $error['line'],
|
'line' => $error['line'],
|
||||||
);
|
);
|
||||||
|
|
||||||
self::$loggers['emergency']->emerg($error['message'], $fatal);
|
self::$loggers['emergency']->emergency($error['message'], $fatal);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->displayErrors) {
|
if (!$this->displayErrors) {
|
||||||
|
@ -73,6 +73,11 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
|
|||||||
return isset($this->data['logs']) ? $this->data['logs'] : array();
|
return isset($this->data['logs']) ? $this->data['logs'] : array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getPriorities()
|
||||||
|
{
|
||||||
|
return isset($this->data['priorities']) ? $this->data['priorities'] : array();
|
||||||
|
}
|
||||||
|
|
||||||
public function countDeprecations()
|
public function countDeprecations()
|
||||||
{
|
{
|
||||||
return isset($this->data['deprecation_count']) ? $this->data['deprecation_count'] : 0;
|
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(),
|
'error_count' => $this->logger->countErrors(),
|
||||||
'deprecation_count' => 0,
|
'deprecation_count' => 0,
|
||||||
'scream_count' => 0,
|
'scream_count' => 0,
|
||||||
|
'priorities' => array(),
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($this->logger->getLogs() as $log) {
|
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 (isset($log['context']['type'])) {
|
||||||
if (ErrorHandler::TYPE_DEPRECATION === $log['context']['type']) {
|
if (ErrorHandler::TYPE_DEPRECATION === $log['context']['type']) {
|
||||||
++$count['deprecation_count'];
|
++$count['deprecation_count'];
|
||||||
@ -139,6 +154,8 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ksort($count['priorities']);
|
||||||
|
|
||||||
return $count;
|
return $count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ class LoggerDataCollectorTest extends \PHPUnit_Framework_TestCase
|
|||||||
/**
|
/**
|
||||||
* @dataProvider getCollectTestData
|
* @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 = $this->getMock('Symfony\Component\HttpKernel\Log\DebugLoggerInterface');
|
||||||
$logger->expects($this->once())->method('countErrors')->will($this->returnValue($nb));
|
$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($expectedLogs ? $expectedLogs : $logs, $c->getLogs());
|
||||||
$this->assertSame($expectedDeprecationCount, $c->countDeprecations());
|
$this->assertSame($expectedDeprecationCount, $c->countDeprecations());
|
||||||
$this->assertSame($expectedScreamCount, $c->countScreams());
|
$this->assertSame($expectedScreamCount, $c->countScreams());
|
||||||
|
|
||||||
|
if (isset($expectedPriorities)) {
|
||||||
|
$this->assertSame($expectedPriorities, $c->getPriorities());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCollectTestData()
|
public function getCollectTestData()
|
||||||
@ -40,35 +44,36 @@ class LoggerDataCollectorTest extends \PHPUnit_Framework_TestCase
|
|||||||
return array(
|
return array(
|
||||||
array(
|
array(
|
||||||
1,
|
1,
|
||||||
array(array('message' => 'foo', 'context' => array())),
|
array(array('message' => 'foo', 'context' => array(), 'priority' => 100, 'priorityName' => 'DEBUG')),
|
||||||
null,
|
null,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
1,
|
1,
|
||||||
array(array('message' => 'foo', 'context' => array('foo' => fopen(__FILE__, 'r')))),
|
array(array('message' => 'foo', 'context' => array('foo' => fopen(__FILE__, 'r')), 'priority' => 100, 'priorityName' => 'DEBUG')),
|
||||||
array(array('message' => 'foo', 'context' => array('foo' => 'Resource(stream)'))),
|
array(array('message' => 'foo', 'context' => array('foo' => 'Resource(stream)'), 'priority' => 100, 'priorityName' => 'DEBUG')),
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
1,
|
1,
|
||||||
array(array('message' => 'foo', 'context' => array('foo' => new \stdClass()))),
|
array(array('message' => 'foo', 'context' => array('foo' => new \stdClass()), 'priority' => 100, 'priorityName' => 'DEBUG')),
|
||||||
array(array('message' => 'foo', 'context' => array('foo' => 'Object(stdClass)'))),
|
array(array('message' => 'foo', 'context' => array('foo' => 'Object(stdClass)'), 'priority' => 100, 'priorityName' => 'DEBUG')),
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
1,
|
1,
|
||||||
array(
|
array(
|
||||||
array('message' => 'foo', 'context' => array('type' => ErrorHandler::TYPE_DEPRECATION)),
|
array('message' => 'foo', 'context' => array('type' => ErrorHandler::TYPE_DEPRECATION), 'priority' => 100, 'priorityName' => 'DEBUG'),
|
||||||
array('message' => 'foo2', 'context' => array('type' => ErrorHandler::TYPE_DEPRECATION)),
|
array('message' => 'foo2', 'context' => array('type' => ErrorHandler::TYPE_DEPRECATION), 'priority' => 100, 'priorityName' => 'DEBUG'),
|
||||||
array('message' => 'foo3', 'context' => array('type' => E_USER_WARNING, 'scream' => 0)),
|
array('message' => 'foo3', 'context' => array('type' => E_USER_WARNING, 'scream' => 0), 'priority' => 100, 'priorityName' => 'DEBUG'),
|
||||||
),
|
),
|
||||||
null,
|
null,
|
||||||
2,
|
2,
|
||||||
1,
|
1,
|
||||||
|
array(100 => array('count' => 3, 'name' => 'DEBUG')),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user