# LogCollector

> Captures Yiisoft log messages in the canonical Log panel shape.

[API reference](/docs/api/index.md) › [Yii3 Debug](/docs/extensions/yii3-debug/reference/index.md) › [Collector](/docs/extensions/yii3-debug/reference/collector/index.md) › LogCollector

| final class | `Yii3\Debug\Collector\LogCollector` |
| --- | --- |
| Implements | [`CollectorInterface`](https://github.com/php-forge/debug/blob/e4fbb8c3238a4d011ceef5e0094344abd50deaf4/src/CollectorInterface.php) |
| Source | [`src/Collector/LogCollector.php`](https://github.com/yii3/debug/blob/main/src/Collector/LogCollector.php#L25) |

Captures Yiisoft log messages in the canonical Log panel shape.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Creates a log collector that flushes and redacts application messages before capture. | `LogCollector` |
| [`capture()`](#method-capture) | Encodes the captured messages into the Logs panel payload. | `LogCollector` |
| [`id()`](#method-id) | Returns the stable identifier of this collector. | `LogCollector` |
| [`shutdown()`](#method-shutdown) | Stops capturing and clears the messages accumulated for the request. | `LogCollector` |
| [`startup()`](#method-startup) | Starts capturing, discarding anything the target held from a previous request. | `LogCollector` |

## Method details

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

```php
public function __construct(Yii3\Debug\Log\DebugLogTarget $target, Psr\Log\LoggerInterface|null $logger = null, PHPForge\Debug\Capture\CapturePolicy $capturePolicy = new \PHPForge\Debug\Capture\CapturePolicy())
```

Creates a log collector that flushes and redacts application messages before capture.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$target` | [`Yii3\Debug\Log\DebugLogTarget`](/docs/extensions/yii3-debug/reference/log/debuglogtarget/index.md) | Log target accumulating the messages of the request. |
| `$logger` | `Psr\Log\LoggerInterface\|null` | Application logger flushed before reading, or `null` to skip flushing. |
| `$capturePolicy` | [`CapturePolicy`](https://github.com/php-forge/debug-core/blob/b70459f033a1d7a1c5edf7951029aad2061986dd/src/Capture/CapturePolicy.php) | Policy redacting the sensitive keys and string values of the PSR-3 context; the message text is never redacted. |

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

```php
public function capture(): array<string, mixed>|null
```

Encodes the captured messages into the Logs panel payload.

Each row carries the PSR-3 context without the reserved keys, normalized into a bounded, redacted JSON tree.

**Returns**

`array<string, mixed>|null`: Encoded Logs panel payload; `null` when the collector never started.

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

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

Returns the stable identifier of this collector.

**Returns**

`string`: Stable ID pairing this collector with its panel.

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

```php
public function shutdown(): void
```

Stops capturing and clears the messages accumulated for the request.

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

```php
public function startup(): void
```

Starts capturing, discarding anything the target held from a previous request.