1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-06 05:07:36 +02:00

make ErrorHandler extends LogLevel to avoid autoloading issue when error is triggered on compile

This commit is contained in:
Fabrice Kabongo
2017-02-21 14:00:49 +02:00
parent c82afaa303
commit 8140f6026f

View File

@@ -24,7 +24,7 @@ use Monolog\Handler\AbstractHandler;
* *
* @author Jordi Boggiano <j.boggiano@seld.be> * @author Jordi Boggiano <j.boggiano@seld.be>
*/ */
class ErrorHandler class ErrorHandler extends LogLevel
{ {
private $logger; private $logger;
@@ -104,21 +104,21 @@ class ErrorHandler
protected function defaultErrorLevelMap() protected function defaultErrorLevelMap()
{ {
return array( return array(
E_ERROR => LogLevel::CRITICAL, E_ERROR => self::CRITICAL,
E_WARNING => LogLevel::WARNING, E_WARNING => self::WARNING,
E_PARSE => LogLevel::ALERT, E_PARSE => self::ALERT,
E_NOTICE => LogLevel::NOTICE, E_NOTICE => self::NOTICE,
E_CORE_ERROR => LogLevel::CRITICAL, E_CORE_ERROR => self::CRITICAL,
E_CORE_WARNING => LogLevel::WARNING, E_CORE_WARNING => self::WARNING,
E_COMPILE_ERROR => LogLevel::ALERT, E_COMPILE_ERROR => self::ALERT,
E_COMPILE_WARNING => LogLevel::WARNING, E_COMPILE_WARNING => self::WARNING,
E_USER_ERROR => LogLevel::ERROR, E_USER_ERROR => self::ERROR,
E_USER_WARNING => LogLevel::WARNING, E_USER_WARNING => self::WARNING,
E_USER_NOTICE => LogLevel::NOTICE, E_USER_NOTICE => self::NOTICE,
E_STRICT => LogLevel::NOTICE, E_STRICT => self::NOTICE,
E_RECOVERABLE_ERROR => LogLevel::ERROR, E_RECOVERABLE_ERROR => self::ERROR,
E_DEPRECATED => LogLevel::NOTICE, E_DEPRECATED => self::NOTICE,
E_USER_DEPRECATED => LogLevel::NOTICE, E_USER_DEPRECATED => self::NOTICE,
); );
} }
@@ -128,7 +128,7 @@ class ErrorHandler
public function handleException($e) public function handleException($e)
{ {
$this->logger->log( $this->logger->log(
$this->uncaughtExceptionLevel === null ? LogLevel::ERROR : $this->uncaughtExceptionLevel, $this->uncaughtExceptionLevel === null ? self::ERROR : $this->uncaughtExceptionLevel,
sprintf('Uncaught Exception %s: "%s" at %s line %s', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()), sprintf('Uncaught Exception %s: "%s" at %s line %s', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()),
array('exception' => $e) array('exception' => $e)
); );
@@ -151,7 +151,7 @@ class ErrorHandler
// fatal error codes are ignored if a fatal error handler is present as well to avoid duplicate log entries // fatal error codes are ignored if a fatal error handler is present as well to avoid duplicate log entries
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] : self::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));
} }
@@ -172,7 +172,7 @@ class ErrorHandler
$lastError = error_get_last(); $lastError = error_get_last();
if ($lastError && in_array($lastError['type'], self::$fatalErrors, true)) { if ($lastError && in_array($lastError['type'], self::$fatalErrors, true)) {
$this->logger->log( $this->logger->log(
$this->fatalLevel === null ? LogLevel::ALERT : $this->fatalLevel, $this->fatalLevel === null ? self::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'])
); );