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 27 of file ErrorHandler.php.
◆ __construct()
◆ codeToString()
static Monolog\ErrorHandler::codeToString |
( |
|
$code | ) |
|
|
staticprivate |
Definition at line 190 of file ErrorHandler.php.
References $code.
202 return 'E_CORE_ERROR';
204 return 'E_CORE_WARNING';
205 case E_COMPILE_ERROR:
206 return 'E_COMPILE_ERROR';
207 case E_COMPILE_WARNING:
208 return 'E_COMPILE_WARNING';
210 return 'E_USER_ERROR';
212 return 'E_USER_WARNING';
214 return 'E_USER_NOTICE';
217 case E_RECOVERABLE_ERROR:
218 return 'E_RECOVERABLE_ERROR';
220 return 'E_DEPRECATED';
221 case E_USER_DEPRECATED:
222 return 'E_USER_DEPRECATED';
225 return 'Unknown PHP error';
◆ defaultErrorLevelMap()
Monolog\ErrorHandler::defaultErrorLevelMap |
( |
| ) |
|
|
protected |
◆ handleError()
Monolog\ErrorHandler::handleError |
( |
|
$code, |
|
|
|
$message, |
|
|
|
$file = '' , |
|
|
|
$line = 0 , |
|
|
|
$context = array() |
|
) |
| |
Definition at line 146 of file ErrorHandler.php.
References $code, $file, $message, and array.
148 if ($this->handleOnlyReportedErrors && !(error_reporting() &
$code)) {
153 if (!$this->hasFatalErrorHandler || !in_array(
$code, self::$fatalErrors,
true)) {
155 $this->logger->log($level, self::codeToString(
$code).
': '.
$message,
array(
'code' =>
$code,
'message' => $message,
'file' =>
$file,
'line' => $line));
158 if ($this->previousErrorHandler ===
true) {
160 } elseif ($this->previousErrorHandler) {
161 return call_user_func($this->previousErrorHandler,
$code, $message,
$file, $line, $context);
catch(Exception $e) $message
Create styles array
The data for the language used.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
◆ handleException()
Monolog\ErrorHandler::handleException |
( |
|
$e | ) |
|
Definition at line 128 of file ErrorHandler.php.
References array, and exit.
131 $this->uncaughtExceptionLevel === null ?
LogLevel::ERROR : $this->uncaughtExceptionLevel,
132 sprintf(
'Uncaught Exception %s: "%s" at %s line %s', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()),
133 array(
'exception' => $e)
136 if ($this->previousExceptionHandler) {
137 call_user_func($this->previousExceptionHandler, $e);
Create styles array
The data for the language used.
◆ handleFatalError()
Monolog\ErrorHandler::handleFatalError |
( |
| ) |
|
Definition at line 168 of file ErrorHandler.php.
References $handler, and array.
170 $this->reservedMemory = null;
172 $lastError = error_get_last();
173 if ($lastError && in_array($lastError[
'type'], self::$fatalErrors,
true)) {
176 'Fatal Error ('.self::codeToString($lastError[
'type']).
'): '.$lastError[
'message'],
177 array(
'code' => $lastError[
'type'],
'message' => $lastError[
'message'],
'file' => $lastError[
'file'],
'line' => $lastError[
'line'])
180 if ($this->logger instanceof Logger) {
181 foreach ($this->logger->getHandlers() as
$handler) {
182 if (
$handler instanceof AbstractHandler) {
Create styles array
The data for the language used.
◆ 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 59 of file ErrorHandler.php.
References $handler.
Referenced by Monolog\Handler\PHPConsoleHandlerTest\testError().
65 if ($exceptionLevel !==
false) {
66 $handler->registerExceptionHandler($exceptionLevel);
◆ registerErrorHandler()
Monolog\ErrorHandler::registerErrorHandler |
( |
array |
$levelMap = array() , |
|
|
|
$callPrevious = true , |
|
|
|
$errorTypes = -1 , |
|
|
|
$handleOnlyReportedErrors = true |
|
) |
| |
Definition at line 84 of file ErrorHandler.php.
References array.
86 $prev = set_error_handler(
array($this,
'handleError'), $errorTypes);
89 $this->previousErrorHandler = $prev ?:
true;
$handleOnlyReportedErrors
Create styles array
The data for the language used.
◆ registerExceptionHandler()
Monolog\ErrorHandler::registerExceptionHandler |
( |
|
$level = null , |
|
|
|
$callPrevious = true |
|
) |
| |
Definition at line 75 of file ErrorHandler.php.
References array.
77 $prev = set_exception_handler(
array($this,
'handleException'));
78 $this->uncaughtExceptionLevel = $level;
79 if ($callPrevious && $prev) {
80 $this->previousExceptionHandler = $prev;
Create styles array
The data for the language used.
◆ registerFatalHandler()
Monolog\ErrorHandler::registerFatalHandler |
( |
|
$level = null , |
|
|
|
$reservedMemorySize = 20 |
|
) |
| |
Definition at line 95 of file ErrorHandler.php.
References array.
97 register_shutdown_function(
array($this,
'handleFatalError'));
99 $this->reservedMemory = str_repeat(
' ', 1024 * $reservedMemorySize);
100 $this->fatalLevel = $level;
101 $this->hasFatalErrorHandler =
true;
Create styles array
The data for the language used.
◆ $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 |
◆ $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: