Class ErrorLogger
Log errors and unhandled exceptions to Cake\Log\Log
Property Summary
-
$_config protected
array<string, mixed>Runtime config
-
$_configInitialized protected
boolWhether the config property has already been configured with defaults
-
$_defaultConfig protected
array<string, mixed>Default configuration values.
Method Summary
-
__construct() public
Constructor
-
_configDelete() protected
Deletes a single config key.
-
_configRead() protected
Reads a config key.
-
_configWrite() protected
Writes a config key.
-
alert() public
Action must be taken immediately.
-
configShallow() public
Merge provided config with existing config. Unlike
config()which does a recursive merge for nested keys, this method does a simple merge. -
critical() public
Critical conditions.
-
debug() public
Detailed debug information.
-
emergency() public
System is unusable.
-
error() public
Runtime errors that do not require immediate action but should typically be logged and monitored.
-
getConfig() public
Returns the config.
-
getConfigOrFail() public
Returns the config for this specific key.
-
getMessage() protected
Generate the message for the exception
-
getRequestContext() public
Get the request context for an error/exception trace.
-
info() public
Interesting events.
-
log() public
Logs with an arbitrary level.
-
logError() public
Log an error to Cake's Log subsystem
-
logException() public
Log an error for an exception with optional request context.
-
notice() public
Normal but significant events.
-
setConfig() public
Sets the config.
-
warning() public
Exceptional occurrences that are not errors.
Method Detail
__construct() ¶ public
__construct(array<string, mixed> $config = [])
Constructor
Parameters
-
array<string, mixed>$config optional Config array.
_configDelete() ¶ protected
_configDelete(string $key): void
Deletes a single config key.
Parameters
-
string$key Key to delete.
Returns
voidThrows
Cake\Core\Exception\CakeExceptionif attempting to clobber existing config
_configRead() ¶ protected
_configRead(string|null $key): mixed
Reads a config key.
Parameters
-
string|null$key Key to read.
Returns
mixed_configWrite() ¶ protected
_configWrite(array<string, mixed>|string $key, mixed $value, string|bool $merge = false): void
Writes a config key.
Parameters
-
array<string, mixed>|string$key Key to write to.
-
mixed$value Value to write.
-
string|bool$merge optional True to merge recursively, 'shallow' for simple merge, false to overwrite, defaults to false.
Returns
voidThrows
Cake\Core\Exception\CakeExceptionif attempting to clobber existing config
alert() ¶ public
alert(string|Stringable $message, array $context = []): void
Action must be taken immediately.
Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up.
Parameters
-
string|Stringable$message -
array$context optional
Returns
voidconfigShallow() ¶ public
configShallow(array<string, mixed>|string $key, mixed|null $value = null): $this
Merge provided config with existing config. Unlike config() which does
a recursive merge for nested keys, this method does a simple merge.
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
-
array<string, mixed>|string$key The key to set, or a complete array of configs.
-
mixed|null$value optional The value to set.
Returns
$thiscritical() ¶ public
critical(string|Stringable $message, array $context = []): void
Critical conditions.
Example: Application component unavailable, unexpected exception.
Parameters
-
string|Stringable$message -
array$context optional
Returns
voiddebug() ¶ public
debug(string|Stringable $message, array $context = []): void
Detailed debug information.
Parameters
-
string|Stringable$message -
array$context optional
Returns
voidemergency() ¶ public
emergency(string|Stringable $message, array $context = []): void
System is unusable.
Parameters
-
string|Stringable$message -
array$context optional
Returns
voiderror() ¶ public
error(string|Stringable $message, array $context = []): void
Runtime errors that do not require immediate action but should typically be logged and monitored.
Parameters
-
string|Stringable$message -
array$context optional
Returns
voidgetConfig() ¶ public
getConfig(string|null $key = null, mixed $default = null): mixed
Returns the config.
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
-
string|null$key optional The key to get or null for the whole config.
-
mixed$default optional The return value when the key does not exist.
Returns
mixedgetConfigOrFail() ¶ public
getConfigOrFail(string $key): mixed
Returns the config for this specific key.
The config value for this key must exist, it can never be null.
Parameters
-
string$key The key to get.
Returns
mixedThrows
InvalidArgumentExceptiongetMessage() ¶ protected
getMessage(Throwable $exception, bool $isPrevious = false, bool $includeTrace = false): string
Generate the message for the exception
Parameters
-
Throwable$exception The exception to log a message for.
-
bool$isPrevious optional False for original exception, true for previous
-
bool$includeTrace optional Whether or not to include a stack trace.
Returns
stringgetRequestContext() ¶ public
getRequestContext(Psr\Http\Message\ServerRequestInterface $request): string
Get the request context for an error/exception trace.
Parameters
-
Psr\Http\Message\ServerRequestInterface$request The request to read from.
Returns
stringinfo() ¶ public
info(string|Stringable $message, array $context = []): void
Interesting events.
Example: User logs in, SQL logs.
Parameters
-
string|Stringable$message -
array$context optional
Returns
voidlog() ¶ public
log(mixed $level, Stringable|string $message, array $context = []): void
Logs with an arbitrary level.
Parameters
-
mixed$level -
Stringable|string$message -
array$context optional
Returns
voidlogError() ¶ public
logError(Cake\Error\PhpError $error, Psr\Http\Message\ServerRequestInterface|null $request = null, bool $includeTrace = false): void
Log an error to Cake's Log subsystem
Parameters
-
Cake\Error\PhpError$error -
Psr\Http\Message\ServerRequestInterface|null$request optional -
bool$includeTrace optional
Returns
voidlogException() ¶ public
logException(Throwable $exception, Psr\Http\Message\ServerRequestInterface|null $request = null, bool $includeTrace = false): void
Log an error for an exception with optional request context.
Parameters
-
Throwable$exception -
Psr\Http\Message\ServerRequestInterface|null$request optional -
bool$includeTrace optional
Returns
voidnotice() ¶ public
notice(string|Stringable $message, array $context = []): void
Normal but significant events.
Parameters
-
string|Stringable$message -
array$context optional
Returns
voidsetConfig() ¶ public
setConfig(array<string, mixed>|string $key, mixed|null $value = null, bool $merge = true): $this
Sets the config.
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
-
array<string, mixed>|string$key The key to set, or a complete array of configs.
-
mixed|null$value optional The value to set.
-
bool$merge optional Whether to recursively merge or overwrite existing config, defaults to true.
Returns
$thisThrows
Cake\Core\Exception\CakeExceptionWhen trying to set a key that is invalid.
warning() ¶ public
warning(string|Stringable $message, array $context = []): void
Exceptional occurrences that are not errors.
Example: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong.
Parameters
-
string|Stringable$message -
array$context optional
Returns
void