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 26 of file ErrorHandler.php.
◆ __construct()
◆ codeToString()
static Monolog\ErrorHandler::codeToString |
( |
|
$code | ) |
|
|
staticprivate |
Definition at line 173 of file ErrorHandler.php.
References $code.
185 return 'E_CORE_ERROR';
187 return 'E_CORE_WARNING';
188 case E_COMPILE_ERROR:
189 return 'E_COMPILE_ERROR';
190 case E_COMPILE_WARNING:
191 return 'E_COMPILE_WARNING';
193 return 'E_USER_ERROR';
195 return 'E_USER_WARNING';
197 return 'E_USER_NOTICE';
200 case E_RECOVERABLE_ERROR:
201 return 'E_RECOVERABLE_ERROR';
203 return 'E_DEPRECATED';
204 case E_USER_DEPRECATED:
205 return 'E_USER_DEPRECATED';
208 return 'Unknown PHP error';
◆ defaultErrorLevelMap()
Monolog\ErrorHandler::defaultErrorLevelMap |
( |
| ) |
|
|
protected |
◆ handleError()
Monolog\ErrorHandler::handleError |
( |
|
$code, |
|
|
|
$message, |
|
|
|
$file = '' , |
|
|
|
$line = 0 , |
|
|
|
$context = array() |
|
) |
| |
Definition at line 140 of file ErrorHandler.php.
References $code, and $file.
142 if (!(error_reporting() &
$code)) {
147 $this->logger->log($level, self::codeToString(
$code).
': '.$message, array(
'code' =>
$code,
'message' => $message,
'file' =>
$file,
'line' => $line));
149 if ($this->previousErrorHandler ===
true) {
151 } elseif ($this->previousErrorHandler) {
152 return call_user_func($this->previousErrorHandler,
$code, $message,
$file, $line, $context);
◆ handleException()
Monolog\ErrorHandler::handleException |
( |
|
$e | ) |
|
Definition at line 122 of file ErrorHandler.php.
References exit.
125 $this->uncaughtExceptionLevel === null ?
LogLevel::ERROR : $this->uncaughtExceptionLevel,
126 sprintf(
'Uncaught Exception %s: "%s" at %s line %s', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()),
127 array(
'exception' => $e)
130 if ($this->previousExceptionHandler) {
131 call_user_func($this->previousExceptionHandler, $e);
◆ handleFatalError()
Monolog\ErrorHandler::handleFatalError |
( |
| ) |
|
Definition at line 159 of file ErrorHandler.php.
161 $this->reservedMemory = null;
163 $lastError = error_get_last();
164 if ($lastError && in_array($lastError[
'type'], self::$fatalErrors)) {
167 'Fatal Error ('.self::codeToString($lastError[
'type']).
'): '.$lastError[
'message'],
168 array(
'code' => $lastError[
'type'],
'message' => $lastError[
'message'],
'file' => $lastError[
'file'],
'line' => $lastError[
'line'])
◆ 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 56 of file ErrorHandler.php.
Referenced by Monolog\Handler\PHPConsoleHandlerTest\testError().
62 if ($exceptionLevel !==
false) {
63 $handler->registerExceptionHandler($exceptionLevel);
◆ registerErrorHandler()
Monolog\ErrorHandler::registerErrorHandler |
( |
array |
$levelMap = array() , |
|
|
|
$callPrevious = true , |
|
|
|
$errorTypes = -1 |
|
) |
| |
Definition at line 81 of file ErrorHandler.php.
83 $prev = set_error_handler(array($this,
'handleError'), $errorTypes);
86 $this->previousErrorHandler = $prev ?:
true;
◆ registerExceptionHandler()
Monolog\ErrorHandler::registerExceptionHandler |
( |
|
$level = null , |
|
|
|
$callPrevious = true |
|
) |
| |
Definition at line 72 of file ErrorHandler.php.
74 $prev = set_exception_handler(array($this,
'handleException'));
75 $this->uncaughtExceptionLevel = $level;
76 if ($callPrevious && $prev) {
77 $this->previousExceptionHandler = $prev;
◆ registerFatalHandler()
Monolog\ErrorHandler::registerFatalHandler |
( |
|
$level = null , |
|
|
|
$reservedMemorySize = 20 |
|
) |
| |
Definition at line 90 of file ErrorHandler.php.
92 register_shutdown_function(array($this,
'handleFatalError'));
94 $this->reservedMemory = str_repeat(
' ', 1024 * $reservedMemorySize);
95 $this->fatalLevel = $level;
◆ $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 |
◆ $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: