Final Class Yiisoft\Log\Message\CategoryFilter
| Inheritance | Yiisoft\Log\Message\CategoryFilter |
|---|
Category is a data object that stores and matches the included and excluded categories of log messages.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| exclude() | Sets the log message categories to be excluded. | Yiisoft\Log\Message\CategoryFilter |
| include() | Sets the log message categories to be included. | Yiisoft\Log\Message\CategoryFilter |
| isExcluded() | Checks whether the specified log message category is excluded. | Yiisoft\Log\Message\CategoryFilter |
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| DEFAULT | 'application' | Deprecated Since 2.1, will be removed in 3.0. Use {@see \Yiisoft\Log\Message::DEFAULT_CATEGORY} instead. | Yiisoft\Log\Message\CategoryFilter |
Method Details
Sets the log message categories to be excluded.
| public void exclude ( string[] $categories ) | ||
| $categories | string[] |
The list of log message categories to be excluded. |
| throws | InvalidArgumentException |
When log message category structure is invalid. |
|---|---|---|
public function exclude(array $categories): void
{
$this->checkStructure($categories);
$this->exclude = $categories;
}
Sets the log message categories to be included.
| public void include ( string[] $categories ) | ||
| $categories | string[] |
List of log message categories to be included. |
| throws | InvalidArgumentException |
for invalid log message categories structure. |
|---|---|---|
public function include(array $categories): void
{
$this->checkStructure($categories);
$this->include = $categories;
}
Checks whether the specified log message category is excluded.
| public boolean isExcluded ( string $category ) | ||
| $category | string |
The log message category. |
| return | boolean |
The value indicating whether the specified category is excluded. |
|---|---|---|
public function isExcluded(string $category): bool
{
foreach ($this->exclude as $exclude) {
$prefix = rtrim($exclude, '*');
if ($category === $exclude || ($prefix !== $exclude && str_starts_with($category, $prefix))) {
return true;
}
}
if (empty($this->include)) {
return false;
}
foreach ($this->include as $include) {
if (
$category === $include
|| (
!empty($include)
&& str_ends_with($include, '*')
&& str_starts_with($category, rtrim($include, '*'))
)
) {
return false;
}
}
return true;
}
Signup or Login in order to comment.