namespace Symfony\Component\HttpKernel\DataCollector;
+use Symfony\Component\Debug\Exception\SilencedErrorContext;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
*/
class LoggerDataCollector extends DataCollector implements LateDataCollectorInterface
{
- private $errorNames = array(
- E_DEPRECATED => 'E_DEPRECATED',
- E_USER_DEPRECATED => 'E_USER_DEPRECATED',
- E_NOTICE => 'E_NOTICE',
- E_USER_NOTICE => 'E_USER_NOTICE',
- E_STRICT => 'E_STRICT',
- E_WARNING => 'E_WARNING',
- E_USER_WARNING => 'E_USER_WARNING',
- E_COMPILE_WARNING => 'E_COMPILE_WARNING',
- E_CORE_WARNING => 'E_CORE_WARNING',
- E_USER_ERROR => 'E_USER_ERROR',
- E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR',
- E_COMPILE_ERROR => 'E_COMPILE_ERROR',
- E_PARSE => 'E_PARSE',
- E_ERROR => 'E_ERROR',
- E_CORE_ERROR => 'E_CORE_ERROR',
- );
-
private $logger;
public function __construct($logger = null)
return isset($this->data['deprecation_count']) ? $this->data['deprecation_count'] : 0;
}
+ public function countWarnings()
+ {
+ return isset($this->data['warning_count']) ? $this->data['warning_count'] : 0;
+ }
+
public function countScreams()
{
return isset($this->data['scream_count']) ? $this->data['scream_count'] : 0;
private function sanitizeLogs($logs)
{
- $errorContextById = array();
$sanitizedLogs = array();
foreach ($logs as $log) {
- $context = $this->sanitizeContext($log['context']);
-
- if (isset($context['type'], $context['file'], $context['line'], $context['level'])) {
- $errorId = md5("{$context['type']}/{$context['line']}/{$context['file']}\x00{$log['message']}", true);
- $silenced = !($context['type'] & $context['level']);
- if (isset($this->errorNames[$context['type']])) {
- $context = array_merge(array('name' => $this->errorNames[$context['type']]), $context);
- }
+ if (!$this->isSilencedOrDeprecationErrorLog($log)) {
+ $log['context'] = $log['context'] ? $this->cloneVar($log['context']) : $log['context'];
+ $sanitizedLogs[] = $log;
- if (isset($errorContextById[$errorId])) {
- if (isset($errorContextById[$errorId]['errorCount'])) {
- ++$errorContextById[$errorId]['errorCount'];
- } else {
- $errorContextById[$errorId]['errorCount'] = 2;
- }
+ continue;
+ }
- if (!$silenced && isset($errorContextById[$errorId]['scream'])) {
- unset($errorContextById[$errorId]['scream']);
- $errorContextById[$errorId]['level'] = $context['level'];
- }
+ $exception = $log['context']['exception'];
+ $errorId = md5("{$exception->getSeverity()}/{$exception->getLine()}/{$exception->getFile()}".($exception instanceof \Exception ? "\0".$exception->getMessage() : ''), true);
- continue;
- }
+ if (isset($sanitizedLogs[$errorId])) {
+ ++$sanitizedLogs[$errorId]['errorCount'];
+ } else {
+ $log['context'] = $log['context'] ? $this->cloneVar($log['context']) : $log['context'];
- $errorContextById[$errorId] = &$context;
- if ($silenced) {
- $context['scream'] = true;
- }
+ $log += array(
+ 'errorCount' => 1,
+ 'scream' => $exception instanceof SilencedErrorContext,
+ );
- $log['context'] = &$context;
- unset($context);
- } else {
- $log['context'] = $context;
+ $sanitizedLogs[$errorId] = $log;
}
-
- $sanitizedLogs[] = $log;
}
- return $sanitizedLogs;
+ return array_values($sanitizedLogs);
}
- private function sanitizeContext($context)
+ private function isSilencedOrDeprecationErrorLog(array $log)
{
- if (is_array($context)) {
- foreach ($context as $key => $value) {
- $context[$key] = $this->sanitizeContext($value);
- }
-
- return $context;
+ if (!isset($log['context']['exception'])) {
+ return false;
}
- if (is_resource($context)) {
- return sprintf('Resource(%s)', get_resource_type($context));
- }
+ $exception = $log['context']['exception'];
- if (is_object($context)) {
- if ($context instanceof \Exception) {
- return sprintf('Exception(%s): %s', get_class($context), $context->getMessage());
- }
+ if ($exception instanceof SilencedErrorContext) {
+ return true;
+ }
- return sprintf('Object(%s)', get_class($context));
+ if ($exception instanceof \ErrorException && in_array($exception->getSeverity(), array(E_DEPRECATED, E_USER_DEPRECATED), true)) {
+ return true;
}
- return $context;
+ return false;
}
private function computeErrorsCount()
$count = array(
'error_count' => $this->logger->countErrors(),
'deprecation_count' => 0,
+ 'warning_count' => 0,
'scream_count' => 0,
'priorities' => array(),
);
'name' => $log['priorityName'],
);
}
+ if ('WARNING' === $log['priorityName']) {
+ ++$count['warning_count'];
+ }
- if (isset($log['context']['type'], $log['context']['level'])) {
- if (E_DEPRECATED === $log['context']['type'] || E_USER_DEPRECATED === $log['context']['type']) {
- ++$count['deprecation_count'];
- } elseif (!($log['context']['type'] & $log['context']['level'])) {
+ if ($this->isSilencedOrDeprecationErrorLog($log)) {
+ if ($log['context']['exception'] instanceof SilencedErrorContext) {
++$count['scream_count'];
+ } else {
+ ++$count['deprecation_count'];
}
}
}