Abstract Class Yiisoft\Profiler\Target\AbstractTarget
| Inheritance | Yiisoft\Profiler\Target\AbstractTarget |
|---|---|
| Implements | Yiisoft\Profiler\Target\TargetInterface |
| Subclasses | Yiisoft\Profiler\Target\FileTarget, Yiisoft\Profiler\Target\LogTarget |
Target is the base class for all profiling target classes.
A profile target object will filter the messages stored by {@see \Yiisoft\Profiler\Target\Profiler} according to its {@see \Yiisoft\Profiler\Target\AbstractTarget::include()} and {@see \Yiisoft\Profiler\Target\AbstractTarget::exclude()}.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| collect() | Processes the given log messages. | Yiisoft\Profiler\Target\AbstractTarget |
| enable() | Enable or disable target. | Yiisoft\Profiler\Target\AbstractTarget |
| exclude() | Yiisoft\Profiler\Target\AbstractTarget | |
| export() | Exports profiling messages to a specific destination. | Yiisoft\Profiler\Target\AbstractTarget |
| include() | Yiisoft\Profiler\Target\AbstractTarget | |
| isEnabled() | Returns target is enabled. | Yiisoft\Profiler\Target\AbstractTarget |
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| filterMessages() | Filters the given messages according to their categories. | Yiisoft\Profiler\Target\AbstractTarget |
Method Details
Processes the given log messages.
This method will filter the given messages with {@see \Yiisoft\Profiler\Target\include()} and {@see \Yiisoft\Profiler\Target\exclude()}. And if requested, it will also export the filtering result to specific medium (e.g. email).
| public void collect ( array $messages ) | ||
| $messages | array |
Profiling messages to be processed. Each message has the following keys:
|
public function collect(array $messages): void
{
if (!$this->enabled) {
return;
}
$messages = $this->filterMessages($messages);
if (count($messages) > 0) {
$this->export($messages);
}
}
Enable or disable target.
| public void enable ( boolean $value = true ) | ||
| $value | boolean | |
public function enable(bool $value = true): void
{
$this->enabled = $value;
}
| public $this exclude ( string[] $exclude ) | ||
| $exclude | string[] |
List of message categories that this target is NOT interested in. Defaults to empty, meaning no uninteresting messages. If this property is not empty, then any category listed here will be excluded from {@see \Yiisoft\Profiler\Target\include()}.
You can use an asterisk at the end of a category so that the category can be used to
match those categories sharing the same common prefix. For example, 'Yiisoft\Db**' will match
categories starting with 'Yiisoft\Db\', such as |
public function exclude(array $exclude): self
{
$new = clone $this;
$new->exclude = $exclude;
return $new;
}
Exports profiling messages to a specific destination.
Child classes must implement this method.
| public abstract void export ( Yiisoft\Profiler\Message[] $messages ) | ||
| $messages | Yiisoft\Profiler\Message[] |
Profiling messages to be exported. |
abstract public function export(array $messages): void;
Filters the given messages according to their categories.
| protected Yiisoft\Profiler\Message[] filterMessages ( Yiisoft\Profiler\Message[] $messages ) | ||
| $messages | Yiisoft\Profiler\Message[] |
Messages to be filtered. The message structure follows that in {@see \Yiisoft\Profiler\Target\TargetInterface::collect()}. |
| return | Yiisoft\Profiler\Message[] |
The filtered messages. |
|---|---|---|
protected function filterMessages(array $messages): array
{
foreach ($messages as $i => $message) {
if (!$this->isCategoryMatched($message->level())) {
unset($messages[$i]);
}
}
return $messages;
}
See also \Yiisoft\Strings\WildcardPattern.
| public $this include ( string[] $include ) | ||
| $include | string[] |
List of message categories that this target is interested in. Defaults to empty, meaning all categories. You can use an asterisk at the end of a category so that the category may be used to
match those categories sharing the same common prefix. For example, 'Yiisoft\Db**' will match
categories starting with 'Yiisoft\Db\', such as |
public function include(array $include): self
{
$new = clone $this;
$new->include = $include;
return $new;
}
Signup or Login in order to comment.