updated-packages
This commit is contained in:
@@ -11,16 +11,16 @@
|
||||
|
||||
namespace Symfony\Component\HttpKernel\DataCollector;
|
||||
|
||||
use Symfony\Component\Debug\Exception\SilencedErrorContext;
|
||||
use Symfony\Component\ErrorHandler\Exception\SilencedErrorContext;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
|
||||
|
||||
/**
|
||||
* LogDataCollector.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @final since Symfony 4.4
|
||||
*/
|
||||
class LoggerDataCollector extends DataCollector implements LateDataCollectorInterface
|
||||
{
|
||||
@@ -41,8 +41,10 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param \Throwable|null $exception
|
||||
*/
|
||||
public function collect(Request $request, Response $response, \Exception $exception = null)
|
||||
public function collect(Request $request, Response $response/* , \Throwable $exception = null */)
|
||||
{
|
||||
$this->currentRequest = $this->requestStack && $this->requestStack->getMasterRequest() !== $request ? $request : null;
|
||||
}
|
||||
@@ -55,7 +57,7 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
|
||||
if ($this->logger instanceof DebugLoggerInterface) {
|
||||
$this->logger->clear();
|
||||
}
|
||||
$this->data = array();
|
||||
$this->data = [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,51 +68,48 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
|
||||
if (null !== $this->logger) {
|
||||
$containerDeprecationLogs = $this->getContainerDeprecationLogs();
|
||||
$this->data = $this->computeErrorsCount($containerDeprecationLogs);
|
||||
$this->data['compiler_logs'] = $this->getContainerCompilerLogs();
|
||||
// get compiler logs later (only when they are needed) to improve performance
|
||||
$this->data['compiler_logs'] = [];
|
||||
$this->data['compiler_logs_filepath'] = $this->containerPathPrefix.'Compiler.log';
|
||||
$this->data['logs'] = $this->sanitizeLogs(array_merge($this->logger->getLogs($this->currentRequest), $containerDeprecationLogs));
|
||||
$this->data = $this->cloneVar($this->data);
|
||||
}
|
||||
$this->currentRequest = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the logs.
|
||||
*
|
||||
* @return array An array of logs
|
||||
*/
|
||||
public function getLogs()
|
||||
{
|
||||
return isset($this->data['logs']) ? $this->data['logs'] : array();
|
||||
return $this->data['logs'] ?? [];
|
||||
}
|
||||
|
||||
public function getPriorities()
|
||||
{
|
||||
return isset($this->data['priorities']) ? $this->data['priorities'] : array();
|
||||
return $this->data['priorities'] ?? [];
|
||||
}
|
||||
|
||||
public function countErrors()
|
||||
{
|
||||
return isset($this->data['error_count']) ? $this->data['error_count'] : 0;
|
||||
return $this->data['error_count'] ?? 0;
|
||||
}
|
||||
|
||||
public function countDeprecations()
|
||||
{
|
||||
return isset($this->data['deprecation_count']) ? $this->data['deprecation_count'] : 0;
|
||||
return $this->data['deprecation_count'] ?? 0;
|
||||
}
|
||||
|
||||
public function countWarnings()
|
||||
{
|
||||
return isset($this->data['warning_count']) ? $this->data['warning_count'] : 0;
|
||||
return $this->data['warning_count'] ?? 0;
|
||||
}
|
||||
|
||||
public function countScreams()
|
||||
{
|
||||
return isset($this->data['scream_count']) ? $this->data['scream_count'] : 0;
|
||||
return $this->data['scream_count'] ?? 0;
|
||||
}
|
||||
|
||||
public function getCompilerLogs()
|
||||
{
|
||||
return isset($this->data['compiler_logs']) ? $this->data['compiler_logs'] : array();
|
||||
return $this->cloneVar($this->getContainerCompilerLogs($this->data['compiler_logs_filepath'] ?? null));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,16 +120,20 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
|
||||
return 'logger';
|
||||
}
|
||||
|
||||
private function getContainerDeprecationLogs()
|
||||
private function getContainerDeprecationLogs(): array
|
||||
{
|
||||
if (null === $this->containerPathPrefix || !file_exists($file = $this->containerPathPrefix.'Deprecations.log')) {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
if ('' === $logContent = trim(file_get_contents($file))) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$bootTime = filemtime($file);
|
||||
$logs = array();
|
||||
foreach (unserialize(file_get_contents($file)) as $log) {
|
||||
$log['context'] = array('exception' => new SilencedErrorContext($log['type'], $log['file'], $log['line'], $log['trace'], $log['count']));
|
||||
$logs = [];
|
||||
foreach (unserialize($logContent) as $log) {
|
||||
$log['context'] = ['exception' => new SilencedErrorContext($log['type'], $log['file'], $log['line'], $log['trace'], $log['count'])];
|
||||
$log['timestamp'] = $bootTime;
|
||||
$log['priority'] = 100;
|
||||
$log['priorityName'] = 'DEBUG';
|
||||
@@ -143,29 +146,29 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
|
||||
return $logs;
|
||||
}
|
||||
|
||||
private function getContainerCompilerLogs()
|
||||
private function getContainerCompilerLogs(string $compilerLogsFilepath = null): array
|
||||
{
|
||||
if (null === $this->containerPathPrefix || !file_exists($file = $this->containerPathPrefix.'Compiler.log')) {
|
||||
return array();
|
||||
if (!file_exists($compilerLogsFilepath)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$logs = array();
|
||||
foreach (file($file, FILE_IGNORE_NEW_LINES) as $log) {
|
||||
$logs = [];
|
||||
foreach (file($compilerLogsFilepath, \FILE_IGNORE_NEW_LINES) as $log) {
|
||||
$log = explode(': ', $log, 2);
|
||||
if (!isset($log[1]) || !preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\\\\[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)++$/', $log[0])) {
|
||||
$log = array('Unknown Compiler Pass', implode(': ', $log));
|
||||
$log = ['Unknown Compiler Pass', implode(': ', $log)];
|
||||
}
|
||||
|
||||
$logs[$log[0]][] = array('message' => $log[1]);
|
||||
$logs[$log[0]][] = ['message' => $log[1]];
|
||||
}
|
||||
|
||||
return $logs;
|
||||
}
|
||||
|
||||
private function sanitizeLogs($logs)
|
||||
private function sanitizeLogs(array $logs)
|
||||
{
|
||||
$sanitizedLogs = array();
|
||||
$silencedLogs = array();
|
||||
$sanitizedLogs = [];
|
||||
$silencedLogs = [];
|
||||
|
||||
foreach ($logs as $log) {
|
||||
if (!$this->isSilencedOrDeprecationErrorLog($log)) {
|
||||
@@ -174,7 +177,7 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
|
||||
continue;
|
||||
}
|
||||
|
||||
$message = $log['message'];
|
||||
$message = '_'.$log['message'];
|
||||
$exception = $log['context']['exception'];
|
||||
|
||||
if ($exception instanceof SilencedErrorContext) {
|
||||
@@ -184,10 +187,10 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
|
||||
$silencedLogs[$h] = true;
|
||||
|
||||
if (!isset($sanitizedLogs[$message])) {
|
||||
$sanitizedLogs[$message] = $log + array(
|
||||
$sanitizedLogs[$message] = $log + [
|
||||
'errorCount' => 0,
|
||||
'scream' => true,
|
||||
);
|
||||
];
|
||||
}
|
||||
$sanitizedLogs[$message]['errorCount'] += $exception->count;
|
||||
|
||||
@@ -199,10 +202,10 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
|
||||
if (isset($sanitizedLogs[$errorId])) {
|
||||
++$sanitizedLogs[$errorId]['errorCount'];
|
||||
} else {
|
||||
$log += array(
|
||||
$log += [
|
||||
'errorCount' => 1,
|
||||
'scream' => false,
|
||||
);
|
||||
];
|
||||
|
||||
$sanitizedLogs[$errorId] = $log;
|
||||
}
|
||||
@@ -211,7 +214,7 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
|
||||
return array_values($sanitizedLogs);
|
||||
}
|
||||
|
||||
private function isSilencedOrDeprecationErrorLog(array $log)
|
||||
private function isSilencedOrDeprecationErrorLog(array $log): bool
|
||||
{
|
||||
if (!isset($log['context']['exception'])) {
|
||||
return false;
|
||||
@@ -223,32 +226,32 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($exception instanceof \ErrorException && \in_array($exception->getSeverity(), array(E_DEPRECATED, E_USER_DEPRECATED), true)) {
|
||||
if ($exception instanceof \ErrorException && \in_array($exception->getSeverity(), [\E_DEPRECATED, \E_USER_DEPRECATED], true)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function computeErrorsCount(array $containerDeprecationLogs)
|
||||
private function computeErrorsCount(array $containerDeprecationLogs): array
|
||||
{
|
||||
$silencedLogs = array();
|
||||
$count = array(
|
||||
$silencedLogs = [];
|
||||
$count = [
|
||||
'error_count' => $this->logger->countErrors($this->currentRequest),
|
||||
'deprecation_count' => 0,
|
||||
'warning_count' => 0,
|
||||
'scream_count' => 0,
|
||||
'priorities' => array(),
|
||||
);
|
||||
'priorities' => [],
|
||||
];
|
||||
|
||||
foreach ($this->logger->getLogs($this->currentRequest) as $log) {
|
||||
if (isset($count['priorities'][$log['priority']])) {
|
||||
++$count['priorities'][$log['priority']]['count'];
|
||||
} else {
|
||||
$count['priorities'][$log['priority']] = array(
|
||||
$count['priorities'][$log['priority']] = [
|
||||
'count' => 1,
|
||||
'name' => $log['priorityName'],
|
||||
);
|
||||
];
|
||||
}
|
||||
if ('WARNING' === $log['priorityName']) {
|
||||
++$count['warning_count'];
|
||||
|
Reference in New Issue
Block a user