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