[Debug] More aggressively aggregate silenced notices per file+line

This commit is contained in:
Nicolas Grekas 2017-11-10 09:13:48 +01:00
parent deb499ebaf
commit 9ab7559fb5

View File

@ -409,21 +409,24 @@ class ErrorHandler
$errorAsException = self::$toStringException; $errorAsException = self::$toStringException;
self::$toStringException = null; self::$toStringException = null;
} elseif (!$throw && !($type & $level)) { } elseif (!$throw && !($type & $level)) {
if (isset(self::$silencedErrorCache[$message])) { if (!isset(self::$silencedErrorCache[$id = $file.':'.$line])) {
$lightTrace = null;
$errorAsException = self::$silencedErrorCache[$message];
++$errorAsException->count;
} else {
$lightTrace = $this->tracedErrors & $type ? $this->cleanTrace(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3), $type, $file, $line, false) : array(); $lightTrace = $this->tracedErrors & $type ? $this->cleanTrace(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3), $type, $file, $line, false) : array();
$errorAsException = new SilencedErrorContext($type, $file, $line, $lightTrace); $errorAsException = new SilencedErrorContext($type, $file, $line, $lightTrace);
} elseif (isset(self::$silencedErrorCache[$id][$message])) {
$lightTrace = null;
$errorAsException = self::$silencedErrorCache[$id][$message];
++$errorAsException->count;
} else {
$errorAsException = null;
} }
if (100 < ++self::$silencedErrorCount) { if (100 < ++self::$silencedErrorCount) {
self::$silencedErrorCache = $lightTrace = array(); self::$silencedErrorCache = $lightTrace = array();
self::$silencedErrorCount = 1; self::$silencedErrorCount = 1;
} }
self::$silencedErrorCache[$message] = $errorAsException; if ($errorAsException) {
self::$silencedErrorCache[$id][$message] = $errorAsException;
}
if (null === $lightTrace) { if (null === $lightTrace) {
return; return;
} }
@ -494,13 +497,13 @@ class ErrorHandler
$this->loggers[$type][0], $this->loggers[$type][0],
($type & $level) ? $this->loggers[$type][1] : LogLevel::DEBUG, ($type & $level) ? $this->loggers[$type][1] : LogLevel::DEBUG,
$logMessage, $logMessage,
array('exception' => $errorAsException), $errorAsException ? array('exception' => $errorAsException) : array(),
); );
} else { } else {
try { try {
$this->isRecursive = true; $this->isRecursive = true;
$level = ($type & $level) ? $this->loggers[$type][1] : LogLevel::DEBUG; $level = ($type & $level) ? $this->loggers[$type][1] : LogLevel::DEBUG;
$this->loggers[$type][0]->log($level, $logMessage, array('exception' => $errorAsException)); $this->loggers[$type][0]->log($level, $logMessage, $errorAsException ? array('exception' => $errorAsException) : array());
} finally { } finally {
$this->isRecursive = false; $this->isRecursive = false;
} }