# PsrMessage

> Stores a PSR-3 message together with its original level and context.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [log](/docs/api/yii/log/index.md) › PsrMessage

| final readonly class | `yii\log\PsrMessage` |
| --- | --- |
| Implements | [`Stringable`](https://www.php.net/manual/en/class.stringable.php) |
| Since | 22.0 |
| Source | [`framework/log/PsrMessage.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/log/PsrMessage.php#L24) |

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.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) |  | `PsrMessage` |
| [`__toString()`](#method-__toString) | Returns the message with safely convertible context placeholders interpolated. | `PsrMessage` |
| [`getContext()`](#method-getContext) | Returns the PSR-3 context. | `PsrMessage` |
| [`getLevel()`](#method-getLevel) | Returns the original PSR-3 level. | `PsrMessage` |
| [`getMessage()`](#method-getMessage) | Returns the message without placeholder interpolation. | `PsrMessage` |

## Method details

### __construct() <span id="method-__construct"></span>

```php
public function __construct(string|Stringable $message, array<array-key, mixed> $context, string $level)
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$message` | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php) | The PSR-3 message, cast to `string` eagerly so a throwing [`Stringable`](https://www.php.net/manual/en/class.stringable.php) fails at the logging call site instead of during a later target flush. |
| `$context` | `array<array-key, mixed>` | The PSR-3 context. |
| `$level` | `string` | The original PSR-3 level. |

### __toString() <span id="method-__toString"></span>

```php
public function __toString(): string
```

Returns the message with safely convertible context placeholders interpolated.

**Returns**

`string`

### getContext() <span id="method-getContext"></span>

```php
public function getContext(): array<array-key, mixed>
```

Returns the PSR-3 context.

**Returns**

`array<array-key, mixed>`

### getLevel() <span id="method-getLevel"></span>

```php
public function getLevel(): string
```

Returns the original PSR-3 level.

**Returns**

`string`

### getMessage() <span id="method-getMessage"></span>

```php
public function getMessage(): string
```

Returns the message without placeholder interpolation.

**Returns**

`string`