# LogContext

> Normalizes the PSR-3 context of a log message into a bounded, redacted, JSON-safe value tree.

[API reference](/docs/api/index.md) › [Debug Core](/docs/extensions/debug-core/reference/index.md) › [Panel](/docs/extensions/debug-core/reference/panel/index.md) › [Log](/docs/extensions/debug-core/reference/panel/log/index.md) › LogContext

| final class | `PHPForge\Debug\Panel\Log\LogContext` |
| --- | --- |
| Source | [`src/Panel/Log/LogContext.php`](https://github.com/php-forge/debug-core/blob/main/src/Panel/Log/LogContext.php#L38) |

Normalizes the PSR-3 context of a log message into a bounded, redacted, JSON-safe value tree.

Objects are reduced to readable strings and never inspected, so the tree always survives the strict JSON encoding of
the capture.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`normalize()`](#method-normalize) static | Normalizes a log context into a bounded JSON-safe tree. | `LogContext` |

## Method details

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

```php
public static function normalize(array<array-key, mixed> $context, PHPForge\Debug\Capture\CapturePolicy $policy, list<string> $excludeKeys = []): array<array-key, mixed>
```

Normalizes a log context into a bounded JSON-safe tree.

Keys become valid UTF-8 strings cut at [`MAX_KEY_BYTES`](https://github.com/php-forge/debug-core/blob/main/src/Panel/Log/LogContext.php#L55) bytes (PHP still stores numeric keys as
integers); a key that collides with an earlier one after the cut or the binary conversion gets a ` #2`, ` #3`
suffix instead of overwriting it. Values whose original key the policy denies become `[redacted]` at any depth,
and string values pass through [`CapturePolicy::redactText()`](/docs/extensions/debug-core/reference/capture/capturepolicy/index.md#method-redactText). The whole tree retains at most
[`MAX_NODES`](https://github.com/php-forge/debug-core/blob/main/src/Panel/Log/LogContext.php#L67) values.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$context` | `array<array-key, mixed>` | Context passed to the logger call. |
| `$policy` | [`PHPForge\Debug\Capture\CapturePolicy`](/docs/extensions/debug-core/reference/capture/capturepolicy/index.md) | Host policy that decides which keys and text fragments are redacted. |
| `$excludeKeys` | `list<string>` | Top-level keys dropped before normalization, such as logger-injected fields already shown as columns. |

**Returns**

`array<array-key, mixed>`: Bounded tree of `null`, `bool`, `int`, finite `float`, `string`, and arrays.