Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| OlzProcessor | |
0.00% |
0 / 15 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
| __invoke | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
20 | |||
| protectTokens | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Olz\Utils; |
| 4 | |
| 5 | use Monolog\Attribute\AsMonologProcessor; |
| 6 | use Monolog\LogRecord; |
| 7 | use Monolog\Processor\ProcessorInterface; |
| 8 | |
| 9 | #[AsMonologProcessor] |
| 10 | class OlzProcessor implements ProcessorInterface { |
| 11 | use WithUtilsTrait; |
| 12 | |
| 13 | public function __invoke(LogRecord $record): LogRecord { |
| 14 | if ($this->server()) { |
| 15 | $record->extra['url'] = $this->protectTokens($this->server()['REQUEST_URI'] ?? null); |
| 16 | $record->extra['referrer'] = $this->server()['HTTP_REFERER'] ?? null; |
| 17 | $record->extra['user_agent'] = $this->server()['HTTP_USER_AGENT'] ?? null; |
| 18 | } |
| 19 | $record->extra['user'] = $this->session()->get('user'); |
| 20 | $record->extra['auth_user'] = $this->session()->get('auth_user'); |
| 21 | if ($record->channel && $record->channel !== 'app') { |
| 22 | return $record; |
| 23 | } |
| 24 | $trace = debug_backtrace(); |
| 25 | $general_utils = new GeneralUtils(); |
| 26 | $trace_overview = $general_utils->getTraceOverview($trace); |
| 27 | return $record->with(channel: $trace_overview); |
| 28 | } |
| 29 | |
| 30 | protected function protectTokens(?string $unsanitized): ?string { |
| 31 | if (!$unsanitized) { |
| 32 | return $unsanitized; |
| 33 | } |
| 34 | return preg_replace('/(access\_token\=[a-zA-Z0-9\_\-\+\/]{3})[a-zA-Z0-9\_\-\+\/]*([a-zA-Z0-9\_\-\+\/]{3})/', '$1***$2', $unsanitized); |
| 35 | } |
| 36 | } |