# LogTarget

> Per-request JSON snapshot collector consumed by the debug toolbar.

[API reference](/docs/api/index.md) › [Debug](/docs/extensions/debug/reference/index.md) › LogTarget

| class | `yii\debug\LogTarget` |
| --- | --- |
| Extends | [`yii\log\Target`](/docs/api/yii/log/target/index.md) » [`yii\base\Component`](/docs/api/yii/base/component/index.md) » [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Source | [`src/LogTarget.php`](https://github.com/yii2-extensions/debug/blob/main/src/LogTarget.php#L34) |

Per-request JSON snapshot collector consumed by the debug toolbar.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-behaviors"></span>[`$behaviors`](/docs/api/yii/base/component/index.md#property-behaviors) read-only | `array<`[`yii\base\Behavior`](/docs/api/yii/base/behavior/index.md)`<static>>` | List of behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="property-categories"></span>[`$categories`](/docs/api/yii/log/target/index.md#property-categories) | `list<string>` | List of message categories that this target is interested in. Default: `[]`. | [`yii\log\Target`](/docs/api/yii/log/target/index.md) |
| <span id="property-enabled"></span>[`$enabled`](/docs/api/yii/log/target/index.md#property-enabled) | `bool\|callable` | A boolean value or a callable to obtain the value from. | [`yii\log\Target`](/docs/api/yii/log/target/index.md) |
| <span id="property-except"></span>[`$except`](/docs/api/yii/log/target/index.md#property-except) | `list<string>` | List of message categories that this target is NOT interested in. Default: `[]`. | [`yii\log\Target`](/docs/api/yii/log/target/index.md) |
| <span id="property-exportInterval"></span>[`$exportInterval`](/docs/api/yii/log/target/index.md#property-exportInterval) | `int` | How many messages should be accumulated before they are exported. Default: `1000`. | [`yii\log\Target`](/docs/api/yii/log/target/index.md) |
| <span id="property-levels"></span>[`$levels`](/docs/api/yii/log/target/index.md#property-levels) | `array\|int` | Message levels that this target is interested in. | [`yii\log\Target`](/docs/api/yii/log/target/index.md) |
| <span id="property-logVars"></span>[`$logVars`](/docs/api/yii/log/target/index.md#property-logVars) | `list<string>` | List of the PHP predefined variables that should be logged in a message. Default: `['_GET', '_POST', '_FILES', '_COOKIE', '_SESSION', '_SERVER']`. | [`yii\log\Target`](/docs/api/yii/log/target/index.md) |
| <span id="property-maskVars"></span>[`$maskVars`](/docs/api/yii/log/target/index.md#property-maskVars) | `list<string>` | List of the PHP predefined variables that should NOT be logged "as is" and should always be replaced with a mask `***` before logging, when exist. Default: `['_SERVER.HTTP_AUTHORIZATION', '_SERVER.PHP_AUTH_USER', '_SERVER.PHP_AUTH_PW']`. Available since 2.0.16. | [`yii\log\Target`](/docs/api/yii/log/target/index.md) |
| <span id="property-messages"></span>[`$messages`](/docs/api/yii/log/target/index.md#property-messages) | `list<yii\log\LogMessage>` | The messages that are retrieved from the logger so far by this log target. Default: `[]`. | [`yii\log\Target`](/docs/api/yii/log/target/index.md) |
| <span id="property-microtime"></span>[`$microtime`](/docs/api/yii/log/target/index.md#property-microtime) | `bool` | Whether to log time with microseconds. Default: `false`. Available since 2.0.13. | [`yii\log\Target`](/docs/api/yii/log/target/index.md) |
| <span id="property-module"></span>`$module` constructor | [`Module`](/docs/extensions/debug/reference/module/index.md) | Debugger module owning this target. | `LogTarget` |
| <span id="property-prefix"></span>[`$prefix`](/docs/api/yii/log/target/index.md#property-prefix) | `callable(yii\log\LogMessage): string\|null` | A PHP callable that returns a string to be prefixed to every exported message. Default: `null`. | [`yii\log\Target`](/docs/api/yii/log/target/index.md) |
| <span id="property-tag"></span>`$tag` | `string` | Unique tag identifying the current request. Default: `''`. | `LogTarget` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Adopts the owning module and registers itself as the module's log target when none is wired yet, so collectors reading through [`Module::$logTarget`](/docs/extensions/debug/reference/module/index.md#property-logTarget) see the messages this target accumulates. | `LogTarget` |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/component/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__clone"></span>[`__clone()`](/docs/api/yii/base/component/index.md#method-__clone) | This method is called after the object is created by cloning an existing one. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/base/component/index.md#method-__get) | Returns the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/base/component/index.md#method-__isset) | Checks if a property is set, i.e. defined and not null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/component/index.md#method-__set) | Sets the value of a component property. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/component/index.md#method-__unset) | Sets a component property to be null. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-attachBehavior"></span>[`attachBehavior()`](/docs/api/yii/base/component/index.md#method-attachBehavior) | Attaches a behavior to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-attachBehaviors"></span>[`attachBehaviors()`](/docs/api/yii/base/component/index.md#method-attachBehaviors) | Attaches a list of behaviors to the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`beginRequest()`](#method-beginRequest) | Starts a fresh persistent-worker request with an isolated tag and message buffer. | `LogTarget` |
| <span id="method-behaviors"></span>[`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) | Returns a list of behaviors that this component should behave as. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/component/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/component/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| [`collect()`](#method-collect) | Accumulates the flushed log messages and writes the capture once the request ends. | `LogTarget` |
| <span id="method-detachBehavior"></span>[`detachBehavior()`](/docs/api/yii/base/component/index.md#method-detachBehavior) | Detaches a behavior from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-detachBehaviors"></span>[`detachBehaviors()`](/docs/api/yii/base/component/index.md#method-detachBehaviors) | Detaches all behaviors from the component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-ensureBehaviors"></span>[`ensureBehaviors()`](/docs/api/yii/base/component/index.md#method-ensureBehaviors) | Makes sure that the behaviors declared in [`behaviors()`](/docs/api/yii/base/component/index.md#method-behaviors) are attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`export()`](#method-export) | Captures every panel into a typed DTO, writes one JSON snapshot, and updates the JSON manifest. | `LogTarget` |
| <span id="method-filterMessages"></span>[`filterMessages()`](/docs/api/yii/log/target/index.md#method-filterMessages) static | Filters the given messages according to their categories and levels. | [`yii\log\Target`](/docs/api/yii/log/target/index.md) |
| <span id="method-formatMessage"></span>[`formatMessage()`](/docs/api/yii/log/target/index.md#method-formatMessage) | Formats a log message for display as a string. | [`yii\log\Target`](/docs/api/yii/log/target/index.md) |
| <span id="method-getBehavior"></span>[`getBehavior()`](/docs/api/yii/base/component/index.md#method-getBehavior) | Returns the named behavior object. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getBehaviors"></span>[`getBehaviors()`](/docs/api/yii/base/component/index.md#method-getBehaviors) | Returns all behaviors attached to this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-getEnabled"></span>[`getEnabled()`](/docs/api/yii/log/target/index.md#method-getEnabled) | Check whether the log target is enabled. | [`yii\log\Target`](/docs/api/yii/log/target/index.md) |
| <span id="method-getLevels"></span>[`getLevels()`](/docs/api/yii/log/target/index.md#method-getLevels) |  | [`yii\log\Target`](/docs/api/yii/log/target/index.md) |
| <span id="method-getMessagePrefix"></span>[`getMessagePrefix()`](/docs/api/yii/log/target/index.md#method-getMessagePrefix) | Returns a string to be prefixed to the given message. | [`yii\log\Target`](/docs/api/yii/log/target/index.md) |
| <span id="method-hasEventHandlers"></span>[`hasEventHandlers()`](/docs/api/yii/base/component/index.md#method-hasEventHandlers) | Returns a value indicating whether there is any handler attached to the named event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/component/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/component/index.md#method-hasProperty) | Returns a value indicating whether a property is defined for this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-init"></span>[`init()`](/docs/api/yii/base/baseobject/index.md#method-init) | Initializes the object. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| [`loadManifest()`](#method-loadManifest) | Reads the manifest of retained captures. | `LogTarget` |
| [`loadSnapshot()`](#method-loadSnapshot) | Returns the immutable snapshot envelope for a captured request. | `LogTarget` |
| [`loadTagToPanels()`](#method-loadTagToPanels) | Hydrates all registered panels for a tag and returns its typed request summary. | `LogTarget` |
| <span id="method-off"></span>[`off()`](/docs/api/yii/base/component/index.md#method-off) | Detaches an existing event handler from this component. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-on"></span>[`on()`](/docs/api/yii/base/component/index.md#method-on) | Attaches an event handler to an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| <span id="method-setEnabled"></span>[`setEnabled()`](/docs/api/yii/log/target/index.md#method-setEnabled) | Sets a value indicating whether this log target is enabled. | [`yii\log\Target`](/docs/api/yii/log/target/index.md) |
| <span id="method-setLevels"></span>[`setLevels()`](/docs/api/yii/log/target/index.md#method-setLevels) | Sets the message levels that this target is interested in. | [`yii\log\Target`](/docs/api/yii/log/target/index.md) |
| <span id="method-trigger"></span>[`trigger()`](/docs/api/yii/base/component/index.md#method-trigger) | Triggers an event. | [`yii\base\Component`](/docs/api/yii/base/component/index.md) |
| [`collectSummary()`](#method-collectSummary) protected | Captures the canonical manifest summary for the current request. | `LogTarget` |
| <span id="method-formatMessageText"></span>[`formatMessageText()`](/docs/api/yii/log/target/index.md#method-formatMessageText) protected | Converts a log message value to text. | [`yii\log\Target`](/docs/api/yii/log/target/index.md) |
| <span id="method-getContextMessage"></span>[`getContextMessage()`](/docs/api/yii/log/target/index.md#method-getContextMessage) protected | Generates the context information to be logged. | [`yii\log\Target`](/docs/api/yii/log/target/index.md) |
| [`getExcessiveDbCallersCount()`](#method-getExcessiveDbCallersCount) protected | Counts the call sites flagged as issuing too many statements. | `LogTarget` |
| [`getSqlTotalCount()`](#method-getSqlTotalCount) protected | Counts the statements executed during the request. | `LogTarget` |
| <span id="method-getTime"></span>[`getTime()`](/docs/api/yii/log/target/index.md#method-getTime) protected | Returns formatted ('Y-m-d H:i:s') timestamp for message. | [`yii\log\Target`](/docs/api/yii/log/target/index.md) |

## Method details

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

```php
public function __construct(yii\debug\Module $module, array<string, mixed> $config = [])
```

Adopts the owning module and registers itself as the module's log target when none is wired yet, so collectors
reading through [`Module::$logTarget`](/docs/extensions/debug/reference/module/index.md#property-logTarget) see the messages this target accumulates.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$module` | [`Module`](/docs/extensions/debug/reference/module/index.md) | Debugger module owning this target. |
| `$config` | `array<string, mixed>` | Standard [`BaseObject`](/docs/api/yii/base/baseobject/index.md) configuration. |

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

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

Starts a fresh persistent-worker request with an isolated tag and message buffer.

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

```php
public function collect(array<int|string, yii\debug\LogMessage> $messages, bool $final): void
```

Accumulates the flushed log messages and writes the capture once the request ends.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$messages` | `array<int\|string, yii\debug\LogMessage>` | Messages flushed by the logger. |
| `$final` | `bool` | Whether this is the final flush of the request. |

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

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

Captures every panel into a typed DTO, writes one JSON snapshot, and updates the JSON manifest.

A failing panel is isolated as a [`PanelFailure`](https://github.com/php-forge/debug-core/blob/b70459f033a1d7a1c5edf7951029aad2061986dd/src/Storage/PanelFailure.php); root, encoding, and filesystem failures remain explicit.

**Throws**

- [`yii\base\Exception`](/docs/api/yii/base/exception/index.md): when the debug data directory cannot be created.

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

```php
public function loadManifest(): array<string, PHPForge\Debug\Storage\RequestSummary>
```

Reads the manifest of retained captures.

**Returns**

`array<string, PHPForge\Debug\Storage\RequestSummary>`: Manifest entries keyed by tag, newest first.

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

```php
public function loadSnapshot(string $tag): PHPForge\Debug\Storage\DebugSnapshot|null
```

Returns the immutable snapshot envelope for a captured request.

Unlike [`loadTagToPanels()`](/docs/extensions/debug/reference/logtarget/index.md#method-loadTagToPanels), this method does not mutate the registered panel instances. It is intended for
cross-request workflows such as history comparison where two captures must be inspected at the same time.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$tag` | `string` | Captured request tag. |

**Returns**

`PHPForge\Debug\Storage\DebugSnapshot|null`: Snapshot envelope, or `null` when the tag is unavailable.

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

```php
public function loadTagToPanels(string $tag): PHPForge\Debug\Storage\RequestSummary|null
```

Hydrates all registered panels for a tag and returns its typed request summary.

Invalid root JSON or summary data rejects the snapshot. Invalid panel payloads are isolated as visible panel
errors while the remaining panels continue to load.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$tag` | `string` | Capture to load. |

**Returns**

`PHPForge\Debug\Storage\RequestSummary|null`: Summary of the capture, or `null` when it cannot be read.

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

```php
protected function collectSummary(): PHPForge\Debug\Storage\RequestSummary
```

Captures the canonical manifest summary for the current request.

**Returns**

`PHPForge\Debug\Storage\RequestSummary`: Manifest entry describing the current request.

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

```php
protected function getExcessiveDbCallersCount(): int
```

Counts the call sites flagged as issuing too many statements.

**Returns**

`int`: Number of call sites that issued at least the configured threshold of queries; `0` when the Database collector is not registered.

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

```php
protected function getSqlTotalCount(): int
```

Counts the statements executed during the request.

**Returns**

`int`: Number of queries executed during the request; `0` when the Database collector is not registered.