ErrorHandler
in package
Monolog error handler
A facility to enable logging of runtime errors, exceptions and fatal errors.
Quick setup: ErrorHandler::register($logger);
Tags
Table of Contents
- $errorLevelMap : array<int, \Psr\Log\LogLevel::*>
- $fatalErrors : array<string|int, int>
- $fatalLevel : \Psr\Log\LogLevel::*
- $handleOnlyReportedErrors : bool
- $hasFatalErrorHandler : bool
- $lastFatalData : array{type: int, message: string, file: string, line: int, trace: mixed}|null
- $logger : LoggerInterface
- $previousErrorHandler : callable|true|null
- $previousExceptionHandler : callable|null
- $reservedMemory : string|null
- $uncaughtExceptionLevelMap : array<class-string, \Psr\Log\LogLevel::*>
- __construct() : mixed
- handleError() : bool
- handleFatalError() : void
- register() : ErrorHandler
- Registers a new ErrorHandler for a given Logger
- registerErrorHandler() : $this
- registerExceptionHandler() : $this
- registerFatalHandler() : self
- defaultErrorLevelMap() : array<int, \Psr\Log\LogLevel::*>
- defaultExceptionLevelMap() : array<class-string, \Psr\Log\LogLevel::*>
- codeToString() : string
- handleException() : void
Properties
$errorLevelMap
private
array<int, \Psr\Log\LogLevel::*>
$errorLevelMap
= []
an array of E_* constant to LogLevel::* constant mapping
$fatalErrors
private
static array<string|int, int>
$fatalErrors
= [E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR]
$fatalLevel
private
\Psr\Log\LogLevel::*
$fatalLevel
= PsrLogLogLevel::ALERT
$handleOnlyReportedErrors
private
bool
$handleOnlyReportedErrors
= true
$hasFatalErrorHandler
private
bool
$hasFatalErrorHandler
= false
$lastFatalData
private
array{type: int, message: string, file: string, line: int, trace: mixed}|null
$lastFatalData
= null
$logger
private
LoggerInterface
$logger
$previousErrorHandler
private
callable|true|null
$previousErrorHandler
= null
$previousExceptionHandler
private
callable|null
$previousExceptionHandler
= null
$reservedMemory
private
string|null
$reservedMemory
= null
$uncaughtExceptionLevelMap
private
array<class-string, \Psr\Log\LogLevel::*>
$uncaughtExceptionLevelMap
= []
an array of class name to LogLevel::* constant mapping
Methods
__construct()
public
__construct(LoggerInterface $logger) : mixed
Parameters
- $logger : LoggerInterface
Return values
mixed —handleError()
public
handleError(int $code, string $message[, string $file = '' ], int $line[, array<string|int, mixed> $context = [] ]) : bool
Parameters
- $code : int
- $message : string
- $file : string = ''
- $line : int
- $context : array<string|int, mixed> = []
Tags
Return values
bool —handleFatalError()
public
handleFatalError() : void
Tags
Return values
void —register()
Registers a new ErrorHandler for a given Logger
public
static register(LoggerInterface $logger[, array<int, \Psr\Log\LogLevel::*>|false $errorLevelMap = [] ][, array<class-string, \Psr\Log\LogLevel::*>|false $exceptionLevelMap = [] ][, \Psr\Log\LogLevel::*|null|false $fatalLevel = null ]) : ErrorHandler
By default it will handle errors, exceptions and fatal errors
Parameters
- $logger : LoggerInterface
- $errorLevelMap : array<int, \Psr\Log\LogLevel::*>|false = []
-
an array of E_* constant to LogLevel::* constant mapping, or false to disable error handling
- $exceptionLevelMap : array<class-string, \Psr\Log\LogLevel::*>|false = []
-
an array of class name to LogLevel::* constant mapping, or false to disable exception handling
- $fatalLevel : \Psr\Log\LogLevel::*|null|false = null
-
a LogLevel::* constant, null to use the default LogLevel::ALERT or false to disable fatal error handling
Return values
ErrorHandler —registerErrorHandler()
public
registerErrorHandler([array<int, \Psr\Log\LogLevel::*> $levelMap = [] ][, bool $callPrevious = true ][, int $errorTypes = -1 ][, bool $handleOnlyReportedErrors = true ]) : $this
Parameters
- $levelMap : array<int, \Psr\Log\LogLevel::*> = []
-
an array of E_* constant to LogLevel::* constant mapping
- $callPrevious : bool = true
- $errorTypes : int = -1
- $handleOnlyReportedErrors : bool = true
Return values
$this —registerExceptionHandler()
public
registerExceptionHandler([array<class-string, \Psr\Log\LogLevel::*> $levelMap = [] ][, bool $callPrevious = true ]) : $this
Parameters
- $levelMap : array<class-string, \Psr\Log\LogLevel::*> = []
-
an array of class name to LogLevel::* constant mapping
- $callPrevious : bool = true
Return values
$this —registerFatalHandler()
public
registerFatalHandler([\Psr\Log\LogLevel::*|null $level = null ][, int $reservedMemorySize = 20 ]) : self
Parameters
- $level : \Psr\Log\LogLevel::*|null = null
-
a LogLevel::* constant, null to use the default LogLevel::ALERT
- $reservedMemorySize : int = 20
-
Amount of KBs to reserve in memory so that it can be freed when handling fatal errors giving Monolog some room in memory to get its job done
Return values
self —defaultErrorLevelMap()
protected
defaultErrorLevelMap() : array<int, \Psr\Log\LogLevel::*>
Return values
array<int, \Psr\Log\LogLevel::*> —defaultExceptionLevelMap()
protected
defaultExceptionLevelMap() : array<class-string, \Psr\Log\LogLevel::*>
Return values
array<class-string, \Psr\Log\LogLevel::*> —codeToString()
private
static codeToString(int $code) : string
Parameters
- $code : int
Return values
string —handleException()
private
handleException(Throwable $e) : void
Parameters
- $e : Throwable