0 follower

Final Class Yiisoft\Profiler\Target\LogTarget

InheritanceYiisoft\Profiler\Target\LogTarget » Yiisoft\Profiler\Target\AbstractTarget
ImplementsYiisoft\Profiler\Target\TargetInterface

LogTarget saves profiling messages as a log messages.

Protected Methods

Hide inherited methods

Method Description Defined By
filterMessages() Filters the given messages according to their categories. Yiisoft\Profiler\Target\AbstractTarget

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( \Psr\Log\LoggerInterface $logger, string $logLevel LogLevel::DEBUG )
$logger \Psr\Log\LoggerInterface
$logLevel string

                public function __construct(
    /**
     * @var LoggerInterface Logger to be used for message export.
     */
    private readonly LoggerInterface $logger,
    /**
     * @var string Log level to be used for messages export.
     */
    private readonly string $logLevel = LogLevel::DEBUG
) {
}

            
collect() public method

Defined in: Yiisoft\Profiler\Target\AbstractTarget::collect()

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:

  • token: string, profiling token.
  • level: string, message category.
  • beginTime: float, profiling begin timestamp obtained by microtime(true).
  • endTime: float, profiling end timestamp obtained by microtime(true).
  • duration: float, profiling block duration in milliseconds.
  • beginMemory: int, memory usage at the beginning of profile block in bytes, obtained by memory_get_usage().
  • endMemory: int, memory usage at the end of profile block in bytes, obtained by memory_get_usage().
  • memoryDiff: int, a diff between 'endMemory' and 'beginMemory'.

                public function collect(array $messages): void
{
    if (!$this->enabled) {
        return;
    }
    $messages = $this->filterMessages($messages);
    if (count($messages) > 0) {
        $this->export($messages);
    }
}

            
enable() public method

Defined in: Yiisoft\Profiler\Target\AbstractTarget::enable()

Enable or disable target.

public void enable ( boolean $value true )
$value boolean

                public function enable(bool $value = true): void
{
    $this->enabled = $value;
}

            
exclude() public method
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 Yiisoft\Db\Connection.

                public function exclude(array $exclude): self
{
    $new = clone $this;
    $new->exclude = $exclude;
    return $new;
}

            
export() public method

public void export ( array $messages )
$messages array

                public function export(array $messages): void
{
    foreach ($messages as $message) {
        $this->logger->log($this->logLevel, $message->token(), $message->context());
    }
}

            
filterMessages() protected method

Defined in: Yiisoft\Profiler\Target\AbstractTarget::filterMessages()

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;
}

            
include() public method

Defined in: Yiisoft\Profiler\Target\AbstractTarget::include()

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 Yiisoft\Db\Connection.

                public function include(array $include): self
{
    $new = clone $this;
    $new->include = $include;
    return $new;
}

            
isEnabled() public method

Defined in: Yiisoft\Profiler\Target\AbstractTarget::isEnabled()

Returns target is enabled.

public boolean isEnabled ( )

                public function isEnabled(): bool
{
    return $this->enabled;
}