mirror of
https://github.com/Seldaek/monolog.git
synced 2025-07-31 18:30:15 +02:00
Merge pull request #1080 from open-sausages/pulls/1/error-trace
ENHANCEMENT Ensure 'trace' is captured for fatal non-exceptions
This commit is contained in:
@@ -38,6 +38,7 @@ class ErrorHandler
|
|||||||
private $hasFatalErrorHandler;
|
private $hasFatalErrorHandler;
|
||||||
private $fatalLevel;
|
private $fatalLevel;
|
||||||
private $reservedMemory;
|
private $reservedMemory;
|
||||||
|
private $lastFatalTrace;
|
||||||
private static $fatalErrors = array(E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR);
|
private static $fatalErrors = array(E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR);
|
||||||
|
|
||||||
public function __construct(LoggerInterface $logger)
|
public function __construct(LoggerInterface $logger)
|
||||||
@@ -156,6 +157,13 @@ class ErrorHandler
|
|||||||
if (!$this->hasFatalErrorHandler || !in_array($code, self::$fatalErrors, true)) {
|
if (!$this->hasFatalErrorHandler || !in_array($code, self::$fatalErrors, true)) {
|
||||||
$level = isset($this->errorLevelMap[$code]) ? $this->errorLevelMap[$code] : LogLevel::CRITICAL;
|
$level = isset($this->errorLevelMap[$code]) ? $this->errorLevelMap[$code] : LogLevel::CRITICAL;
|
||||||
$this->logger->log($level, self::codeToString($code).': '.$message, array('code' => $code, 'message' => $message, 'file' => $file, 'line' => $line));
|
$this->logger->log($level, self::codeToString($code).': '.$message, array('code' => $code, 'message' => $message, 'file' => $file, 'line' => $line));
|
||||||
|
} else {
|
||||||
|
// http://php.net/manual/en/function.debug-backtrace.php
|
||||||
|
// As of 5.3.6, DEBUG_BACKTRACE_IGNORE_ARGS option was added.
|
||||||
|
// Any version less than 5.3.6 must use the DEBUG_BACKTRACE_IGNORE_ARGS constant value '2'.
|
||||||
|
$trace = debug_backtrace((PHP_VERSION_ID < 50306) ? 2 : DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||||
|
array_shift($trace); // Exclude handleError from trace
|
||||||
|
$this->lastFatalTrace = $trace;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->previousErrorHandler === true) {
|
if ($this->previousErrorHandler === true) {
|
||||||
@@ -177,7 +185,7 @@ class ErrorHandler
|
|||||||
$this->logger->log(
|
$this->logger->log(
|
||||||
$this->fatalLevel === null ? LogLevel::ALERT : $this->fatalLevel,
|
$this->fatalLevel === null ? LogLevel::ALERT : $this->fatalLevel,
|
||||||
'Fatal Error ('.self::codeToString($lastError['type']).'): '.$lastError['message'],
|
'Fatal Error ('.self::codeToString($lastError['type']).'): '.$lastError['message'],
|
||||||
array('code' => $lastError['type'], 'message' => $lastError['message'], 'file' => $lastError['file'], 'line' => $lastError['line'])
|
array('code' => $lastError['type'], 'message' => $lastError['message'], 'file' => $lastError['file'], 'line' => $lastError['line'], 'trace' => $this->lastFatalTrace)
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($this->logger instanceof Logger) {
|
if ($this->logger instanceof Logger) {
|
||||||
|
Reference in New Issue
Block a user