Final Class yii\log\PsrMessage
| Inheritance | yii\ |
|---|---|
| Implements | Stringable |
| Available since version | 22.0 |
| Source Code | https://github.com/yiisoft/yii2/blob/master/framework/log/PsrMessage.php |
Stores a PSR-3 message together with its original level and context.
String conversion performs the optional PSR-3 placeholder interpolation while ignoring context values that cannot be safely converted to strings.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | yii\ |
|
| __toString() | Returns the message with safely convertible context placeholders interpolated. | yii\ |
| getContext() | Returns the PSR-3 context. | yii\ |
| getLevel() | Returns the original PSR-3 level. | yii\ |
| getMessage() | Returns the message without placeholder interpolation. | yii\ |
Method Details
| public mixed __construct ( string|\ | ||
| $message | string|\ |
The PSR-3 message, cast to |
| $context | array |
The PSR-3 context. |
| $level | string |
The original PSR-3 level. |
public function __construct(
Stringable|string $message,
private array $context,
private string $level,
) {
$this->_message = (string) $message;
}
Returns the message with safely convertible context placeholders interpolated.
| public string __toString ( ) |
public function __toString(): string
{
$replace = [];
foreach ($this->context as $key => $value) {
if (is_scalar($value) || $value === null) {
$replace['{' . $key . '}'] = (string) $value;
continue;
}
if (!$value instanceof Stringable) {
continue;
}
try {
$replace['{' . $key . '}'] = (string) $value;
} catch (Throwable) {
// PSR-3 context values must never cause logging to fail.
}
}
return strtr($this->_message, $replace);
}
Returns the PSR-3 context.
| public array |
public function getContext(): array
{
return $this->context;
}
Returns the original PSR-3 level.
| public string getLevel ( ) |
public function getLevel(): string
{
return $this->level;
}
Returns the message without placeholder interpolation.
| public string getMessage ( ) |
public function getMessage(): string
{
return $this->_message;
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.