Fr3nch13/CakePHP Utilities

ErrorLogger
in package
implements ErrorLoggerInterface uses InstanceConfigTrait

Log errors and unhandled exceptions to `Cake\Log\Log`

Table of Contents

Interfaces

ErrorLoggerInterface
Interface for error logging handlers.

Properties

$_config  : array<string, mixed>
Runtime config
$_configInitialized  : bool
Whether the config property has already been configured with defaults
$_defaultConfig  : array<string, mixed>
Default configuration values.

Methods

__construct()  : mixed
Constructor
configShallow()  : $this
Merge provided config with existing config. Unlike `config()` which does a recursive merge for nested keys, this method does a simple merge.
getConfig()  : mixed
Returns the config.
getConfigOrFail()  : mixed
Returns the config for this specific key.
getRequestContext()  : string
Get the request context for an error/exception trace.
log()  : bool
Log an error for an exception with optional request context.
logError()  : void
Log an error to Cake's Log subsystem
logException()  : void
Log an exception to Cake's Log subsystem
logMessage()  : bool
Log a an error message to the error logger.
setConfig()  : $this
Sets the config.
_configDelete()  : void
Deletes a single config key.
_configRead()  : mixed
Reads a config key.
_configWrite()  : void
Writes a config key.
getMessage()  : string
Generate the message for the exception

Properties

$_configInitialized

Whether the config property has already been configured with defaults

protected bool $_configInitialized = false

$_defaultConfig

Default configuration values.

protected array<string, mixed> $_defaultConfig = ['trace' => false]
  • trace Should error logs include stack traces?

Methods

__construct()

Constructor

public __construct([array<string, mixed> $config = [] ]) : mixed
Parameters
$config : array<string, mixed> = []

Config array.

configShallow()

Merge provided config with existing config. Unlike `config()` which does a recursive merge for nested keys, this method does a simple merge.

public configShallow(array<string, mixed>|string $key[, mixed|null $value = null ]) : $this

Setting a specific value:

$this->configShallow('key', $value);

Setting a nested value:

$this->configShallow('some.nested.key', $value);

Updating multiple config settings at the same time:

$this->configShallow(['one' => 'value', 'another' => 'value']);
Parameters
$key : array<string, mixed>|string

The key to set, or a complete array of configs.

$value : mixed|null = null

The value to set.

Return values
$this

getConfig()

Returns the config.

public getConfig([string|null $key = null ][, mixed $default = null ]) : mixed

Usage

Reading the whole config:

$this->getConfig();

Reading a specific value:

$this->getConfig('key');

Reading a nested value:

$this->getConfig('some.nested.key');

Reading with default value:

$this->getConfig('some-key', 'default-value');
Parameters
$key : string|null = null

The key to get or null for the whole config.

$default : mixed = null

The return value when the key does not exist.

Return values
mixed

Configuration data at the named key or null if the key does not exist.

getConfigOrFail()

Returns the config for this specific key.

public getConfigOrFail(string $key) : mixed

The config value for this key must exist, it can never be null.

Parameters
$key : string

The key to get.

Tags
throws
InvalidArgumentException
Return values
mixed

Configuration data at the named key

log()

Log an error for an exception with optional request context.

public log(Throwable $exception[, ServerRequestInterface|null $request = null ]) : bool

Use logException instead.

Parameters
$exception : Throwable

The exception to log a message for.

$request : ServerRequestInterface|null = null

The current request if available.

Return values
bool

logError()

Log an error to Cake's Log subsystem

public logError(PhpError $error[, ServerRequestInterface|null $request = null ][, bool $includeTrace = false ]) : void
Parameters
$error : PhpError

The error to log

$request : ServerRequestInterface|null = null

The request if in an HTTP context.

$includeTrace : bool = false

Should the log message include a stacktrace

logException()

Log an exception to Cake's Log subsystem

public logException(Throwable $exception[, ServerRequestInterface|null $request = null ][, bool $includeTrace = false ]) : void
Parameters
$exception : Throwable

The exception to log a message for.

$request : ServerRequestInterface|null = null

The current request if available.

$includeTrace : bool = false

Whether or not a stack trace should be logged.

logMessage()

Log a an error message to the error logger.

public logMessage(string|int $level, string $message[, array<string|int, mixed> $context = [] ]) : bool

Use logError instead.

Parameters
$level : string|int

The logging level

$message : string

The message to be logged.

$context : array<string|int, mixed> = []

Context.

Return values
bool

setConfig()

Sets the config.

public setConfig(array<string, mixed>|string $key[, mixed|null $value = null ][, bool $merge = true ]) : $this

Usage

Setting a specific value:

$this->setConfig('key', $value);

Setting a nested value:

$this->setConfig('some.nested.key', $value);

Updating multiple config settings at the same time:

$this->setConfig(['one' => 'value', 'another' => 'value']);
Parameters
$key : array<string, mixed>|string

The key to set, or a complete array of configs.

$value : mixed|null = null

The value to set.

$merge : bool = true

Whether to recursively merge or overwrite existing config, defaults to true.

Tags
throws
CakeException

When trying to set a key that is invalid.

Return values
$this

_configDelete()

Deletes a single config key.

protected _configDelete(string $key) : void
Parameters
$key : string

Key to delete.

Tags
throws
CakeException

if attempting to clobber existing config

_configRead()

Reads a config key.

protected _configRead(string|null $key) : mixed
Parameters
$key : string|null

Key to read.

_configWrite()

Writes a config key.

protected _configWrite(array<string, mixed>|string $key, mixed $value[, string|bool $merge = false ]) : void
Parameters
$key : array<string, mixed>|string

Key to write to.

$value : mixed

Value to write.

$merge : string|bool = false

True to merge recursively, 'shallow' for simple merge, false to overwrite, defaults to false.

Tags
throws
CakeException

if attempting to clobber existing config

getMessage()

Generate the message for the exception

protected getMessage(Throwable $exception[, bool $isPrevious = false ][, bool $includeTrace = false ]) : string
Parameters
$exception : Throwable

The exception to log a message for.

$isPrevious : bool = false

False for original exception, true for previous

$includeTrace : bool = false

Whether or not to include a stack trace.

Return values
string

Error message


        
On this page

Search results