Skip to content

Commit ce33d8f

Browse files
committed
update README.md
1 parent c424192 commit ce33d8f

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,56 @@ Laravel's (`>= 5.0, < 5.1`) exception logger doesn't use event dispatcher (https
117117
php artisan vendor:publish --provider="Understand\UnderstandLaravel5\UnderstandLaravel5ServiceProvider"
118118
```
119119

120+
### Log Filter
121+
To filter out specific log types a custom log filter can be provided.
122+
123+
**Example filter class**
124+
```php
125+
// app/Logging/UnderstandLogFilter.php
126+
<?php
127+
128+
declare(strict_types=1);
129+
130+
namespace App\Logging;
131+
132+
use Illuminate\Support\Str;
133+
134+
class UnderstandLogFilter
135+
{
136+
public function __invoke($level, $message, $context): bool
137+
{
138+
if ($level === 'warning' && Str::contains(strtolower($message), 'deprecated')) {
139+
return true;
140+
}
141+
142+
return false;
143+
}
144+
}
145+
```
146+
and then it can be configured in `understand-laravel.php`
147+
```php
148+
<?php
149+
// ...
150+
// config/understand-laravel.php
151+
'log_filter' => \App\Logging\UnderstandLogFilter::class,
152+
```
153+
154+
The `log_filter` config value must be a callable type:
155+
- https://www.php.net/manual/en/function.is-callable.php
156+
or a callable dependency from the service container:
157+
- https://laravel.com/docs/9.x/container#the-make-method
158+
159+
The suggested way would be to create an invokable class since it's hard to serialise anonymous functions (Laravel config cache):
160+
- https://www.php.net/manual/en/language.oop5.magic.php#object.invoke
161+
162+
The log filter interface must be as follows: `$callable($level, $message, $context)`.
163+
The result of the filter must be a boolean value:
164+
- `TRUE`, the log should be ignored and NOT delivered to Understand.io
165+
- `FALSE`, the log should be delivered to Understand.io
166+
167+
The `ignored_logs` config value has higher precedence than `log_filter`.
168+
169+
120170
### Requirements
121171
##### UTF-8
122172
This package uses the json_encode function, which only supports UTF-8 data, and you should therefore ensure that all of your data is correctly encoded. In the event that your log data contains non UTF-8 strings, then the json_encode function will not be able to serialize the data.

0 commit comments

Comments
 (0)