Monolog error handler.
More...
|
static | $fatalErrors = array(E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR) |
|
Monolog error handler.
A facility to enable logging of runtime errors, exceptions and fatal errors.
Quick setup: ErrorHandler::register($logger);
- Author
- Jordi Boggiano j.bog.nosp@m.gian.nosp@m.o@sel.nosp@m.d.be
Definition at line 28 of file ErrorHandler.php.
◆ __construct()
◆ codeToString()
static Monolog\ErrorHandler::codeToString |
( |
|
$code | ) |
|
|
staticprivate |
Definition at line 202 of file ErrorHandler.php.
References $code.
214 return 'E_CORE_ERROR';
216 return 'E_CORE_WARNING';
217 case E_COMPILE_ERROR:
218 return 'E_COMPILE_ERROR';
219 case E_COMPILE_WARNING:
220 return 'E_COMPILE_WARNING';
222 return 'E_USER_ERROR';
224 return 'E_USER_WARNING';
226 return 'E_USER_NOTICE';
229 case E_RECOVERABLE_ERROR:
230 return 'E_RECOVERABLE_ERROR';
232 return 'E_DEPRECATED';
233 case E_USER_DEPRECATED:
234 return 'E_USER_DEPRECATED';
237 return 'Unknown PHP error';
◆ defaultErrorLevelMap()
Monolog\ErrorHandler::defaultErrorLevelMap |
( |
| ) |
|
|
protected |
◆ handleError()
Monolog\ErrorHandler::handleError |
( |
|
$code, |
|
|
|
$message, |
|
|
|
$file = '' , |
|
|
|
$line = 0 , |
|
|
|
$context = array() |
|
) |
| |
Definition at line 151 of file ErrorHandler.php.
References $code, $context, and $message.
153 if ($this->handleOnlyReportedErrors && !(error_reporting() &
$code)) {
158 if (!$this->hasFatalErrorHandler || !in_array(
$code, self::$fatalErrors,
true)) {
160 $this->logger->log($level, self::codeToString(
$code).
': '.
$message, array(
'code' =>
$code,
'message' => $message,
'file' => $file,
'line' => $line));
165 $trace = debug_backtrace((PHP_VERSION_ID < 50306) ? 2 : DEBUG_BACKTRACE_IGNORE_ARGS);
167 $this->lastFatalTrace = $trace;
170 if ($this->previousErrorHandler ===
true) {
172 } elseif ($this->previousErrorHandler) {
173 return call_user_func($this->previousErrorHandler,
$code, $message, $file, $line,
$context);
catch(Exception $e) $message
◆ handleException()
Monolog\ErrorHandler::handleException |
( |
|
$e | ) |
|
Definition at line 133 of file ErrorHandler.php.
References exit.
136 $this->uncaughtExceptionLevel === null ?
LogLevel::ERROR : $this->uncaughtExceptionLevel,
137 sprintf(
'Uncaught Exception %s: "%s" at %s line %s',
Utils::getClass($e), $e->getMessage(), $e->getFile(), $e->getLine()),
138 array(
'exception' => $e)
141 if ($this->previousExceptionHandler) {
142 call_user_func($this->previousExceptionHandler, $e);
◆ handleFatalError()
Monolog\ErrorHandler::handleFatalError |
( |
| ) |
|
Definition at line 180 of file ErrorHandler.php.
References $handler.
182 $this->reservedMemory = null;
184 $lastError = error_get_last();
185 if ($lastError && in_array($lastError[
'type'], self::$fatalErrors,
true)) {
188 'Fatal Error ('.self::codeToString($lastError[
'type']).
'): '.$lastError[
'message'],
189 array(
'code' => $lastError[
'type'],
'message' => $lastError[
'message'],
'file' => $lastError[
'file'],
'line' => $lastError[
'line'],
'trace' => $this->lastFatalTrace)
192 if ($this->logger instanceof Logger) {
193 foreach ($this->logger->getHandlers() as
$handler) {
194 if (
$handler instanceof AbstractHandler) {
◆ register()
static Monolog\ErrorHandler::register |
( |
LoggerInterface |
$logger, |
|
|
|
$errorLevelMap = array() , |
|
|
|
$exceptionLevel = null , |
|
|
|
$fatalLevel = null |
|
) |
| |
|
static |
Registers a new ErrorHandler for a given Logger.
By default it will handle errors, exceptions and fatal errors
- Parameters
-
LoggerInterface | $logger | |
array | false | $errorLevelMap | an array of E_* constant to LogLevel::* constant mapping, or false to disable error handling |
int | false | $exceptionLevel | a LogLevel::* constant, or false to disable exception handling |
int | false | $fatalLevel | a LogLevel::* constant, or false to disable fatal error handling |
- Returns
- ErrorHandler
Definition at line 61 of file ErrorHandler.php.
References $handler.
Referenced by Monolog\Handler\PHPConsoleHandlerTest\testError().
64 class_exists(
'\\Psr\\Log\\LogLevel',
true);
70 if ($exceptionLevel !==
false) {
71 $handler->registerExceptionHandler($exceptionLevel);
◆ registerErrorHandler()
Monolog\ErrorHandler::registerErrorHandler |
( |
array |
$levelMap = array() , |
|
|
|
$callPrevious = true , |
|
|
|
$errorTypes = -1 , |
|
|
|
$handleOnlyReportedErrors = true |
|
) |
| |
Definition at line 89 of file ErrorHandler.php.
91 $prev = set_error_handler(array($this,
'handleError'), $errorTypes);
94 $this->previousErrorHandler = $prev ?:
true;
$handleOnlyReportedErrors
◆ registerExceptionHandler()
Monolog\ErrorHandler::registerExceptionHandler |
( |
|
$level = null , |
|
|
|
$callPrevious = true |
|
) |
| |
Definition at line 80 of file ErrorHandler.php.
82 $prev = set_exception_handler(array($this,
'handleException'));
83 $this->uncaughtExceptionLevel = $level;
84 if ($callPrevious && $prev) {
85 $this->previousExceptionHandler = $prev;
◆ registerFatalHandler()
Monolog\ErrorHandler::registerFatalHandler |
( |
|
$level = null , |
|
|
|
$reservedMemorySize = 20 |
|
) |
| |
Definition at line 100 of file ErrorHandler.php.
102 register_shutdown_function(array($this,
'handleFatalError'));
104 $this->reservedMemory = str_repeat(
' ', 1024 * $reservedMemorySize);
105 $this->fatalLevel = $level;
106 $this->hasFatalErrorHandler =
true;
◆ $errorLevelMap
Monolog\ErrorHandler::$errorLevelMap |
|
private |
◆ $fatalErrors
Monolog\ErrorHandler::$fatalErrors = array(E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR) |
|
staticprivate |
◆ $fatalLevel
Monolog\ErrorHandler::$fatalLevel |
|
private |
◆ $handleOnlyReportedErrors
Monolog\ErrorHandler::$handleOnlyReportedErrors |
|
private |
◆ $hasFatalErrorHandler
Monolog\ErrorHandler::$hasFatalErrorHandler |
|
private |
◆ $lastFatalTrace
Monolog\ErrorHandler::$lastFatalTrace |
|
private |
◆ $logger
Monolog\ErrorHandler::$logger |
|
private |
◆ $previousErrorHandler
Monolog\ErrorHandler::$previousErrorHandler |
|
private |
◆ $previousExceptionHandler
Monolog\ErrorHandler::$previousExceptionHandler |
|
private |
◆ $reservedMemory
Monolog\ErrorHandler::$reservedMemory |
|
private |
◆ $uncaughtExceptionLevel
Monolog\ErrorHandler::$uncaughtExceptionLevel |
|
private |
The documentation for this class was generated from the following file: