Documentation

ErrorHandler
in package

Monolog error handler

A facility to enable logging of runtime errors, exceptions and fatal errors.

Quick setup: ErrorHandler::register($logger);

Tags
author

Jordi Boggiano j.boggiano@seld.be

Table of Contents

Constants

FATAL_ERRORS  = [E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR]

Properties

$errorLevelMap  : array<int, LogLevel::*>
$fatalLevel  : string
$handleOnlyReportedErrors  : bool
$hasFatalErrorHandler  : bool
$lastFatalData  : array{type: int, message: string, file: string, line: int, trace: mixed}|null
$logger  : LoggerInterface
$previousErrorHandler  : Closure|true|null
$previousExceptionHandler  : Closure|null
$reservedMemory  : string|null
$uncaughtExceptionLevelMap  : array<class-string, LogLevel::*>

Methods

__construct()  : mixed
handleFatalError()  : void
register()  : static
Registers a new ErrorHandler for a given Logger
registerErrorHandler()  : $this
registerExceptionHandler()  : $this
registerFatalHandler()  : $this
defaultErrorLevelMap()  : array<int, LogLevel::*>
defaultExceptionLevelMap()  : array<class-string, LogLevel::*>
codeToString()  : string
handleError()  : bool
handleException()  : never

Constants

FATAL_ERRORS

private mixed FATAL_ERRORS = [E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR]

Properties

$errorLevelMap

private array<int, LogLevel::*> $errorLevelMap = []

an array of E_* constant to LogLevel::* constant mapping

$fatalLevel

private string $fatalLevel = \Psr\Log\LogLevel::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

$previousErrorHandler

private Closure|true|null $previousErrorHandler = null

$previousExceptionHandler

private Closure|null $previousExceptionHandler = null

$reservedMemory

private string|null $reservedMemory = null

$uncaughtExceptionLevelMap

private array<class-string, LogLevel::*> $uncaughtExceptionLevelMap = []

an array of class name to LogLevel::* constant mapping

Methods

handleFatalError()

public handleFatalError() : void
Tags
private

register()

Registers a new ErrorHandler for a given Logger

public static register(LoggerInterface $logger[, array<int, LogLevel::*>|false $errorLevelMap = [] ][, array<class-string, LogLevel::*>|false $exceptionLevelMap = [] ][, LogLevel::*|null|false $fatalLevel = null ]) : static

By default it will handle errors, exceptions and fatal errors

Parameters
$logger : LoggerInterface
$errorLevelMap : array<int, LogLevel::*>|false = []

an array of E_* constant to LogLevel::* constant mapping, or false to disable error handling

$exceptionLevelMap : array<class-string, LogLevel::*>|false = []

an array of class name to LogLevel::* constant mapping, or false to disable exception handling

$fatalLevel : LogLevel::*|null|false = null

a LogLevel::* constant, null to use the default LogLevel::ALERT or false to disable fatal error handling

Return values
static

registerErrorHandler()

public registerErrorHandler([array<int, LogLevel::*$levelMap = [] ][, bool $callPrevious = true ][, int $errorTypes = -1 ][, bool $handleOnlyReportedErrors = true ]) : $this
Parameters
$levelMap : array<int, 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, LogLevel::*$levelMap = [] ][, bool $callPrevious = true ]) : $this
Parameters
$levelMap : array<class-string, LogLevel::*> = []

an array of class name to LogLevel::* constant mapping

$callPrevious : bool = true
Return values
$this

registerFatalHandler()

public registerFatalHandler([LogLevel::*|null $level = null ][, int $reservedMemorySize = 20 ]) : $this
Parameters
$level : 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
$this

defaultErrorLevelMap()

protected defaultErrorLevelMap() : array<int, LogLevel::*>
Return values
array<int, LogLevel::*>

defaultExceptionLevelMap()

protected defaultExceptionLevelMap() : array<class-string, LogLevel::*>
Return values
array<class-string, LogLevel::*>

codeToString()

private static codeToString(int $code) : string
Parameters
$code : int
Return values
string

handleError()

private handleError(int $code, string $message[, string $file = '' ][, int $line = 0 ]) : bool
Parameters
$code : int
$message : string
$file : string = ''
$line : int = 0
Return values
bool

handleException()

private handleException(Throwable $e) : never
Parameters
$e : Throwable
Return values
never

        
On this page

Search results