Skip to content

Commit 7a0ab29

Browse files
[Debug] generalized ErrorHandler
1 parent eed04b1 commit 7a0ab29

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

DataCollector/LoggerDataCollector.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\HttpKernel\DataCollector;
1313

14-
use Symfony\Component\Debug\ErrorHandler;
1514
use Symfony\Component\HttpFoundation\Request;
1615
use Symfony\Component\HttpFoundation\Response;
1716
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
@@ -99,7 +98,11 @@ public function getName()
9998
private function sanitizeLogs($logs)
10099
{
101100
foreach ($logs as $i => $log) {
102-
$logs[$i]['context'] = $this->sanitizeContext($log['context']);
101+
$context = $this->sanitizeContext($log['context']);
102+
if (isset($context['type'], $context['level']) && !($context['type'] & $context['level'])) {
103+
$context['scream'] = true;
104+
}
105+
$logs[$i]['context'] = $context;
103106
}
104107

105108
return $logs;
@@ -145,10 +148,10 @@ private function computeErrorsCount()
145148
);
146149
}
147150

148-
if (isset($log['context']['type'])) {
149-
if (ErrorHandler::TYPE_DEPRECATION === $log['context']['type']) {
151+
if (isset($log['context']['type'], $log['context']['level'])) {
152+
if (E_DEPRECATED === $log['context']['type'] || E_USER_DEPRECATED === $log['context']['type']) {
150153
++$count['deprecation_count'];
151-
} elseif (isset($log['context']['scream'])) {
154+
} elseif (!($log['context']['type'] & $log['context']['level'])) {
152155
++$count['scream_count'];
153156
}
154157
}

Tests/DataCollector/LoggerDataCollectorTest.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Component\HttpKernel\Tests\DataCollector;
1313

1414
use Symfony\Component\HttpKernel\DataCollector\LoggerDataCollector;
15-
use Symfony\Component\HttpKernel\Debug\ErrorHandler;
1615

1716
class LoggerDataCollectorTest extends \PHPUnit_Framework_TestCase
1817
{
@@ -66,14 +65,20 @@ public function getCollectTestData()
6665
array(
6766
1,
6867
array(
69-
array('message' => 'foo', 'context' => array('type' => ErrorHandler::TYPE_DEPRECATION), 'priority' => 100, 'priorityName' => 'DEBUG'),
70-
array('message' => 'foo2', 'context' => array('type' => ErrorHandler::TYPE_DEPRECATION), 'priority' => 100, 'priorityName' => 'DEBUG'),
71-
array('message' => 'foo3', 'context' => array('type' => E_USER_WARNING, 'scream' => 0), 'priority' => 100, 'priorityName' => 'DEBUG'),
68+
array('message' => 'foo', 'context' => array('type' => E_DEPRECATED, 'level' => E_ALL), 'priority' => 100, 'priorityName' => 'DEBUG'),
69+
array('message' => 'foo2', 'context' => array('type' => E_USER_DEPRECATED, 'level' => E_ALL), 'priority' => 100, 'priorityName' => 'DEBUG'),
7270
),
7371
null,
7472
2,
73+
0,
74+
array(100 => array('count' => 2, 'name' => 'DEBUG')),
75+
),
76+
array(
77+
1,
78+
array(array('message' => 'foo3', 'context' => array('type' => E_USER_WARNING, 'level' => 0), 'priority' => 100, 'priorityName' => 'DEBUG')),
79+
array(array('message' => 'foo3', 'context' => array('type' => E_USER_WARNING, 'level' => 0, 'scream' => true), 'priority' => 100, 'priorityName' => 'DEBUG')),
80+
0,
7581
1,
76-
array(100 => array('count' => 3, 'name' => 'DEBUG')),
7782
),
7883
);
7984
}

0 commit comments

Comments
 (0)