1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-24 01:56:18 +02:00

Merge branch '2.x' into main

This commit is contained in:
Jordi Boggiano
2022-06-09 11:04:38 +02:00
7 changed files with 172 additions and 14 deletions

View File

@@ -45,8 +45,8 @@ class ErrorHandler
private string|null $reservedMemory = null;
/** @var mixed|null */
private $lastFatalTrace = null;
/** @var ?array{type: int, message: string, file: string, line: int, trace: mixed} */
private array|null $lastFatalData = null;
private const FATAL_ERRORS = [E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR];
@@ -213,7 +213,7 @@ class ErrorHandler
} else {
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
array_shift($trace); // Exclude handleError from trace
$this->lastFatalTrace = $trace;
$this->lastFatalData = ['type' => $code, 'message' => $message, 'file' => $file, 'line' => $line, 'trace' => $trace];
}
if ($this->previousErrorHandler === true) {
@@ -233,12 +233,17 @@ class ErrorHandler
{
$this->reservedMemory = '';
$lastError = error_get_last();
if (is_array($this->lastFatalData)) {
$lastError = $this->lastFatalData;
} else {
$lastError = error_get_last();
}
if (is_array($lastError) && in_array($lastError['type'], self::FATAL_ERRORS, true)) {
$trace = $lastError['trace'] ?? null;
$this->logger->log(
$this->fatalLevel,
'Fatal Error ('.self::codeToString($lastError['type']).'): '.$lastError['message'],
['code' => $lastError['type'], 'message' => $lastError['message'], 'file' => $lastError['file'], 'line' => $lastError['line'], 'trace' => $this->lastFatalTrace]
['code' => $lastError['type'], 'message' => $lastError['message'], 'file' => $lastError['file'], 'line' => $lastError['line'], 'trace' => $trace]
);
if ($this->logger instanceof Logger) {