Final Class Yiisoft\Profiler\Target\FileTarget
| Inheritance | Yiisoft\Profiler\Target\FileTarget » Yiisoft\Profiler\Target\AbstractTarget |
|---|---|
| Implements | Yiisoft\Profiler\Target\TargetInterface |
FileTarget records profiling messages in a file specified via {@see FileTarget::$filePath}.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Profiler\Target\FileTarget | |
| 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() | Yiisoft\Profiler\Target\FileTarget | |
| 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
| public mixed __construct ( string $filePath, float $requestBeginTime, integer $directoryMode = 0775 ) | ||
| $filePath | string |
Path of the file to write to. It may contain the placeholders, which will be replaced by computed values. The supported placeholders are:
The directory containing the file will be automatically created if not existing. If target file is already exist it will be overridden. |
| $requestBeginTime | float |
Time of the beginning of the request. Can be set as |
| $directoryMode | integer |
The permission to be set for newly created directories. This value will be used by PHP chmod() function. No umask will be applied. Defaults to 0775, meaning the directory is read-writable by owner and group, but read-only for other users. |
public function __construct(
private readonly string $filePath,
private readonly float $requestBeginTime,
private readonly int $directoryMode = 0775
) {
}
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:
|
public function collect(array $messages): void
{
if (!$this->enabled) {
return;
}
$messages = $this->filterMessages($messages);
if (count($messages) > 0) {
$this->export($messages);
}
}
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;
}
| 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;
}
| public void export ( array $messages ) | ||
| $messages | array | |
public function export(array $messages): void
{
$memoryPeakUsage = memory_get_peak_usage();
$totalTime = microtime(true) - $this->requestBeginTime;
$text = "Total processing time: $totalTime ms; Peak memory: $memoryPeakUsage B. \n\n";
$text .= implode("\n", array_map([$this, 'formatMessage'], $messages));
$filename = $this->resolveFilename();
if (file_exists($filename)) {
FileHelper::unlink($filename);
} else {
$filePath = dirname($filename);
if (!is_dir($filePath)) {
FileHelper::ensureDirectory($filePath, $this->directoryMode);
}
}
file_put_contents($filename, $text);
}
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;
}
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 |
public function include(array $include): self
{
$new = clone $this;
$new->include = $include;
return $new;
}
Defined in: Yiisoft\Profiler\Target\AbstractTarget::isEnabled()
Returns target is enabled.
| public boolean isEnabled ( ) |
public function isEnabled(): bool
{
return $this->enabled;
}
Signup or Login in order to comment.