Total Complexity | 4 |
Total Lines | 34 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
14 | final class ErrorLogger |
||
15 | { |
||
16 | public function __construct( |
||
20 | } |
||
21 | |||
22 | public function __invoke(Throwable $e, RouterMatch $request): string |
||
23 | { |
||
24 | $isError = $e->getCode() >= 500; |
||
25 | $logRef = new LogRef($e); |
||
26 | 9 | $logRef->log($e, $request, $this->appMeta); |
|
27 | $message = sprintf('req:"%s" code:%s e:%s(%s) logref:%s', (string) $request, $e->getCode(), $e::class, $e->getMessage(), (string) $logRef); |
||
28 | 9 | $this->log($isError, $message); |
|
29 | 9 | ||
30 | 9 | return (string) $logRef; |
|
31 | } |
||
32 | 1 | ||
33 | /** |
||
34 | 1 | * Log with method |
|
35 | 1 | * |
|
36 | 1 | * monolog has different log level constants(200,400) than psr/logger, |
|
37 | 1 | * and those constants change from version to version. |
|
38 | 1 | */ |
|
39 | private function log(bool $isError, string $message): void |
||
48 | } |
||
49 | } |
||
50 |