Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[WebProfilerBundle] enhance logs display

  • Loading branch information...
commit 3e6c940495a3d435e106c67b5f74bc9f74a2ff9f 1 parent 71dc07c
@nicolas-grekas nicolas-grekas authored
View
15 src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/logger.html.twig
@@ -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
2  src/Symfony/Component/Debug/ErrorHandler.php
@@ -278,7 +278,7 @@ public function handleFatal()
'line' => $error['line'],
);
- self::$loggers['emergency']->emerg($error['message'], $fatal);
+ self::$loggers['emergency']->emergency($error['message'], $fatal);
}
if (!$this->displayErrors) {
View
17 src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php
@@ -73,6 +73,11 @@ public function getLogs()
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 @@ private function computeErrorsCount()
'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 @@ private function computeErrorsCount()
}
}
+ ksort($count['priorities']);
+
return $count;
}
}
View
23 src/Symfony/Component/HttpKernel/Tests/DataCollector/LoggerDataCollectorTest.php
@@ -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 @@ public function testCollect($nb, $logs, $expectedLogs, $expectedDeprecationCount
$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 @@ public function getCollectTestData()
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')),
),
);
}
Please sign in to comment.
Something went wrong with that request. Please try again.